]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cmd/nncp-file/main.go
Better to call option as -chunked
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-file / main.go
index c94ecd53cc837d0e5aa8418f41383f7fbabcdf6c..0b61aba057356d3cfbe1de1bfd7d3b9dedf989d1 100644 (file)
@@ -1,5 +1,5 @@
 /*
-NNCP -- Node-to-Node CoPy
+NNCP -- Node to Node copy, utilities for store-and-forward data exchange
 Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
@@ -33,17 +33,23 @@ import (
 func usage() {
        fmt.Fprintf(os.Stderr, nncp.UsageHeader())
        fmt.Fprintln(os.Stderr, "nncp-file -- send file\n")
-       fmt.Fprintf(os.Stderr, "Usage: %s [options] SRC NODE:DST\nOptions:", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options] SRC NODE:[DST]\nOptions:\n", os.Args[0])
        flag.PrintDefaults()
+       fmt.Fprint(os.Stderr, `
+If SRC equals to -, then read data from stdin to temporary file.
+`)
 }
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw  = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
-               debug    = flag.Bool("debug", false, "Enable debugging information")
-               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", nncp.DefaultNiceFile, "Outbound packet niceness")
+               minSize   = flag.Uint64("minsize", 0, "Minimal required resulting packet size")
+               chunkSize = flag.Uint64("chunked", 0, "Split file on specified size chunks, in KiB")
+               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()
@@ -64,7 +70,7 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(*cfgPath)
+       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
        if err != nil {
                log.Fatalln("Can not read config:", err)
        }
@@ -72,6 +78,10 @@ func main() {
        if err != nil {
                log.Fatalln("Can not parse config:", err)
        }
+       if ctx.Self == nil {
+               log.Fatalln("Config lacks private keys")
+       }
+       ctx.Quiet = *quiet
        ctx.Debug = *debug
 
        splitted := strings.SplitN(flag.Arg(1), ":", 2)
@@ -84,7 +94,19 @@ func main() {
                log.Fatalln("Invalid NODE specified:", err)
        }
 
-       if err = ctx.TxFile(node, nice, flag.Arg(0), splitted[1]); err != nil {
+       if *chunkSize == 0 {
+               err = ctx.TxFile(node, nice, flag.Arg(0), splitted[1], int64(*minSize))
+       } else {
+               err = ctx.TxFileChunked(
+                       node,
+                       nice,
+                       flag.Arg(0),
+                       splitted[1],
+                       int64(*minSize),
+                       int64(*chunkSize)*1024,
+               )
+       }
+       if err != nil {
                log.Fatalln(err)
        }
 }