X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-exec%2Fmain.go;h=aa2ab74895cce66d152883df6c6234521f4aff5f;hb=c2b17fd0fc439e420710f53602604e8823c2fb1d;hp=0a02252f105ba42f16ebb40f78ebc048e0c2379f;hpb=0139e8deda4112d2c3dcd52e0ad72162e54caa03;p=nncp.git diff --git a/src/cmd/nncp-exec/main.go b/src/cmd/nncp-exec/main.go index 0a02252..aa2ab74 100644 --- a/src/cmd/nncp-exec/main.go +++ b/src/cmd/nncp-exec/main.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2019 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev 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 @@ -22,34 +22,41 @@ import ( "bufio" "flag" "fmt" - "io/ioutil" "log" "os" + "strings" - "go.cypherpunks.ru/nncp/v5" + "go.cypherpunks.ru/nncp/v8" ) func usage() { fmt.Fprintf(os.Stderr, nncp.UsageHeader()) fmt.Fprintf(os.Stderr, "nncp-exec -- send execution command\n\n") - fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE HANDLE [ARG0 ARG1 ...]\nOptions:\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE HANDLE [ARG0 ARG1 ...]\n", os.Args[0]) + fmt.Fprintf(os.Stderr, " %s [options] %s:AREA HANDLE [ARG0 ARG1 ...]\nOptions:\n", + os.Args[0], nncp.AreaDir) flag.PrintDefaults() } func main() { var ( + noCompress = flag.Bool("nocompress", false, "Do not compress input data") cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(nncp.DefaultNiceExec), "Outbound packet niceness") replyNiceRaw = flag.String("replynice", nncp.NicenessFmt(nncp.DefaultNiceFile), "Possible reply packet niceness") minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB") + argMaxSize = flag.Uint64("maxsize", 0, "Maximal allowable resulting packet size, in KiB") viaOverride = flag.String("via", "", "Override Via path to destination node") spoolPath = flag.String("spool", "", "Override path to spool") logPath = flag.String("log", "", "Override path to logfile") quiet = flag.Bool("quiet", false, "Print only errors") + showPrgrs = flag.Bool("progress", false, "Force progress showing") + omitPrgrs = flag.Bool("noprogress", false, "Omit progress showing") debug = flag.Bool("debug", false, "Print debug messages") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") ) + log.SetFlags(log.Lshortfile) flag.Usage = usage flag.Parse() if *warranty { @@ -73,7 +80,15 @@ func main() { log.Fatalln(err) } - ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug) + ctx, err := nncp.CtxFromCmdline( + *cfgPath, + *spoolPath, + *logPath, + *quiet, + *showPrgrs, + *omitPrgrs, + *debug, + ) if err != nil { log.Fatalln("Error during initialization:", err) } @@ -81,26 +96,40 @@ func main() { log.Fatalln("Config lacks private keys") } - node, err := ctx.FindNode(flag.Arg(0)) - if err != nil { - log.Fatalln("Invalid NODE specified:", err) + var areaId *nncp.AreaId + var node *nncp.Node + if strings.HasPrefix(flag.Arg(0), nncp.AreaDir+":") { + areaId = ctx.AreaName2Id[flag.Arg(0)[len(nncp.AreaDir)+1:]] + if areaId == nil { + log.Fatalln("Unknown area specified") + } + node = ctx.Neigh[*ctx.SelfId] + } else { + node, err = ctx.FindNode(flag.Arg(0)) + if err != nil { + log.Fatalln("Invalid NODE specified:", err) + } } - nncp.ViaOverride(*viaOverride, ctx, node) - - body, err := ioutil.ReadAll(bufio.NewReader(os.Stdin)) - if err != nil { - log.Fatalln("Can not read body from stdin:", err) + maxSize := int64(nncp.MaxFileSize) + if *argMaxSize > 0 { + maxSize = int64(*argMaxSize) * 1024 } + nncp.ViaOverride(*viaOverride, ctx, node) + ctx.Umask() + if err = ctx.TxExec( node, nice, replyNice, flag.Args()[1], flag.Args()[2:], - body, + bufio.NewReaderSize(os.Stdin, nncp.MTHBlockSize), int64(*minSize)*1024, + maxSize, + *noCompress, + areaId, ); err != nil { log.Fatalln(err) }