/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
func usage() {
fmt.Fprintf(os.Stderr, nncp.UsageHeader())
- fmt.Fprintln(os.Stderr, "nncp-bundle -- Create/digest stream of NNCP encrypted packets\n")
+ fmt.Fprintf(os.Stderr, "nncp-bundle -- Create/digest stream of NNCP encrypted packets\n\n")
fmt.Fprintf(os.Stderr, "Usage: %s [options] -tx [-delete] NODE [NODE ...] > ...\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s [options] -rx -delete [-dryrun] [NODE ...] < ...\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s [options] -rx [-check] [-dryrun] [NODE ...] < ...\n", os.Args[0])
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
}