func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- niceRaw = flag.Int("nice", 255, "Minimal required niceness")
- doRx = flag.Bool("rx", false, "Receive packets")
- doTx = flag.Bool("tx", false, "Transfer packets")
- doDelete = flag.Bool("delete", false, "Delete transferred packets")
- doCheck = flag.Bool("check", false, "Check integrity while receiving")
- dryRun = flag.Bool("dryrun", false, "Do not writings")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ niceRaw = flag.Int("nice", 255, "Minimal required niceness")
+ doRx = flag.Bool("rx", false, "Receive packets")
+ doTx = flag.Bool("tx", false, "Transfer packets")
+ doDelete = flag.Bool("delete", false, "Delete transferred packets")
+ doCheck = flag.Bool("check", false, "Check integrity while receiving")
+ dryRun = flag.Bool("dryrun", false, "Do not writings")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
log.Fatalln("At least one of -rx and -tx must be specified")
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
+ log.Fatalln("Error during initialization:", err)
}
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
- }
- ctx.Quiet = *quiet
- ctx.Debug = *debug
nodeIds := make(map[nncp.NodeId]struct{}, flag.NArg())
for i := 0; i < flag.NArg(); i++ {
ctx.LogD("nncp-bundle", sds, "Bad packet structure")
continue
}
- if pktEnc.Magic != nncp.MagicNNCPEv2 {
+ if pktEnc.Magic != nncp.MagicNNCPEv3 {
ctx.LogD("nncp-bundle", sds, "Bad packet magic number")
continue
}
ctx.LogD("nncp-bundle", sds, "Packet already exists")
continue
}
- if _, err = os.Stat(dstPath + nncp.SeenPostfix); err == nil || !os.IsNotExist(err) {
+ if _, err = os.Stat(dstPath + nncp.SeenSuffix); err == nil || !os.IsNotExist(err) {
ctx.LogD("nncp-bundle", sds, "Packet already exists")
continue
}