From 5478625bf8ef989fd87d430ea3415607e0ff6984 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 14 Feb 2018 22:32:56 +0300 Subject: [PATCH] Ability to override Via configuration option --- VERSION | 2 +- doc/cfg.texi | 1 + doc/cmds.texi | 3 ++ doc/news.ru.texi | 9 +++++ doc/news.texi | 9 +++++ src/cypherpunks.ru/nncp/cmd/nncp-file/main.go | 33 +++++++++++++------ src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go | 31 ++++++++++++----- src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go | 31 ++++++++++++----- 8 files changed, 90 insertions(+), 29 deletions(-) diff --git a/VERSION b/VERSION index cd5ac03..879b416 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0 +2.1 diff --git a/doc/cfg.texi b/doc/cfg.texi index 0420d39..f898493 100644 --- a/doc/cfg.texi +++ b/doc/cfg.texi @@ -111,6 +111,7 @@ freqing. This is the desired chunk size in KiBs. If set, then apply @ref{OptMinSize, -minsize} option during file transmission. +@anchor{CfgVia} @item via An array of node identifiers that will be used as a relay to that node. For example @verb{|[foo,bar]|} means that packet can reach current node diff --git a/doc/cmds.texi b/doc/cmds.texi index 9868443..2b1d37f 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -20,6 +20,9 @@ Nearly all commands have the following common options: 1-255 values are allowed. @item -node Process only single specified node. +@item -via + Override @ref{CfgVia, via} configuration option for destination node. + Specified nodes must be separated with comma: @verb{|NODE1,NODE2|}. @item -spool Override path to spool directory. May be specified by @env{NNCPSPOOL} environment variable. diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 3325a19..ec168fa 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -1,6 +1,15 @@ @node Новости @section Новости +@node Релиз 2.1 +@subsection Релиз 2.1 +@itemize +@item +Возможность переопределить @option{via} опцию конфигурации для целевого +узла через @option{-via} опцию командной строки для следующих команд: +@command{nncp-file}, @command{nncp-freq}, @command{nncp-mail}. +@end itemize + @node Релиз 2.0 @subsection Релиз 2.0 @itemize diff --git a/doc/news.texi b/doc/news.texi index 23112e2..d2dbd61 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -3,6 +3,15 @@ See also this page @ref{Новости, on russian}. +@node Release 2.1 +@section Release 2.1 +@itemize +@item +Ability to override @option{via} configuration option for destination +node via @option{-via} command line option for following commands: +@command{nncp-file}, @command{nncp-freq}, @command{nncp-mail}. +@end itemize + @node Release 2.0 @section Release 2.0 @itemize diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go index 0e34060..b51dc6b 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go @@ -41,16 +41,17 @@ 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.DefaultNiceFile, "Outbound packet niceness") - minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB") - chunkSize = flag.Uint64("chunked", 0, "Split file on specified size chunks, in KiB") - 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") + 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, in KiB") + chunkSize = flag.Uint64("chunked", 0, "Split file on specified size chunks, 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") + 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() @@ -89,6 +90,18 @@ func main() { log.Fatalln("Invalid NODE specified:", err) } + if *viaOverride != "" { + vias := make([]*nncp.NodeId, 0, strings.Count(*viaOverride, ",")+1) + for _, via := range strings.Split(*viaOverride, ",") { + foundNodeId, err := ctx.FindNode(via) + if err != nil { + log.Fatalln("Invalid Via node specified:", err) + } + vias = append(vias, foundNodeId.Id) + } + node.Via = vias + } + if *chunkSize == 0 { err = ctx.TxFile( node, diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go index 610853a..18d93b6 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go @@ -39,15 +39,16 @@ func usage() { func main() { var ( - cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") - niceRaw = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness") - minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB") - 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") + cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") + niceRaw = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness") + minSize = flag.Uint64("minsize", 0, "Minimal required 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") + 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() @@ -86,6 +87,18 @@ func main() { log.Fatalln("Invalid NODE specified:", err) } + if *viaOverride != "" { + vias := make([]*nncp.NodeId, 0, strings.Count(*viaOverride, ",")+1) + for _, via := range strings.Split(*viaOverride, ",") { + foundNodeId, err := ctx.FindNode(via) + if err != nil { + log.Fatalln("Invalid Via node specified:", err) + } + vias = append(vias, foundNodeId.Id) + } + node.Via = vias + } + var dst string if flag.NArg() == 2 { dst = flag.Arg(1) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go index 235ba97..4e3cc88 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go @@ -40,15 +40,16 @@ func usage() { func main() { var ( - cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") - niceRaw = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness") - minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB") - 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") + cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") + niceRaw = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness") + minSize = flag.Uint64("minsize", 0, "Minimal required 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") + 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() @@ -82,6 +83,18 @@ func main() { log.Fatalln("Invalid NODE specified:", err) } + if *viaOverride != "" { + vias := make([]*nncp.NodeId, 0, strings.Count(*viaOverride, ",")+1) + for _, via := range strings.Split(*viaOverride, ",") { + foundNodeId, err := ctx.FindNode(via) + if err != nil { + log.Fatalln("Invalid Via node specified:", err) + } + vias = append(vias, foundNodeId.Id) + } + node.Via = vias + } + body, err := ioutil.ReadAll(bufio.NewReader(os.Stdin)) if err != nil { log.Fatalln("Can not read mail body from stdin:", err) -- 2.44.0