]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cmd/nncp-bundle/main.go
Merge branch 'develop'
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-bundle / main.go
index e228f2ffa14a0076ce62a4d2c522be8586b536e4..3b754bc1b56a8d8d1311fe18217fbcdc38503cf7 100644 (file)
@@ -1,6 +1,6 @@
 /*
 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
@@ -44,7 +44,7 @@ const (
 
 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])
@@ -54,17 +54,19 @@ func usage() {
 
 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()
@@ -87,16 +89,10 @@ func main() {
                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++ {
@@ -216,7 +212,7 @@ func main() {
                                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
                        }
@@ -283,7 +279,7 @@ func main() {
                                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
                        }