README.RU | 2 +- VERSION | 2 +- doc/about.ru.texi | 2 +- doc/about.texi | 2 +- doc/cmds.texi | 16 ++++++++++++---- doc/download.texi | 4 ++++ doc/install.texi | 2 +- doc/news.ru.texi | 9 ++++++++- doc/news.texi | 11 +++++++++-- makedist.sh | 1 + src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go | 72 +++++++++++++++++++++++++++++++++++++++-------------- src/cypherpunks.ru/nncp/sp.go | 12 +++++++++--- diff --git a/README.RU b/README.RU index dafde9c98875bd17d88a4de6269d0f93ad0fbe390f24339824c8f5bbc070e7f6..0d982049740383e982e4dab436616bb31ee0e6fe78694dff2cf936f5d3845c51 100644 --- a/README.RU +++ b/README.RU @@ -1,5 +1,5 @@ NNCP (Node to Node copy) это набор утилит упрощающий безопасный обмен -файлами и почтой в режиме сохранить-и-переслать. +файлами, почтой и командами в режиме сохранить-и-переслать. Эти утилиты предназначены помочь с построением одноранговых устойчивых к разрывам сетей небольшого размера (дюжины узлов), в режиме друг-к-другу diff --git a/VERSION b/VERSION index 11e557ac2f7fa212b331b212b052bff9cae420ab4df0579c844624dd2e86bce1..201baede28f0e6e68178dea6552eff49010d545c454f0a8100f412f4e5507892 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.3 +3.4 diff --git a/doc/about.ru.texi b/doc/about.ru.texi index 958c3892f689e4bd6908ece4e858f0eedac769b760b3b8cfdb313647b81c3260..ef87089883323f791c508c45ad00f4675333372449ce45406e8d6b6b38d55b35 100644 --- a/doc/about.ru.texi +++ b/doc/about.ru.texi @@ -2,7 +2,7 @@ @node Об утилитах @section Подробнее об утилитах NNCP @strong{NNCP} (Node to Node copy) это набор утилит упрощающий безопасный -обмен файлами и почтой в режиме сохранить-и-переслать. +обмен файлами, почтой и командами в режиме сохранить-и-переслать. Эти утилиты предназначены помочь с построением однораговых @url{https://ru.wikipedia.org/wiki/DTN, устойчивых к разрывам} сетей diff --git a/doc/about.texi b/doc/about.texi index 7df53ca29babe74238e0932f8d8ae81576a8dfa68e1d1f4d49004126dc495b0c..c410b9ff95eaefe06507a250230e1bbccf934c396c38d956331c2a36ecb29157 100644 --- a/doc/about.texi +++ b/doc/about.texi @@ -1,5 +1,5 @@ @strong{NNCP} (Node to Node copy) is a collection of utilities -simplifying secure store-and-forward files and mail exchanging. +simplifying secure store-and-forward files, mail and command exchanging. See also this page @ref{Об утилитах, on russian}. diff --git a/doc/cmds.texi b/doc/cmds.texi index ca71ce7a4be310f760b0a561f3cdfb5448407b00b424719a1c51ed748f4bacee..faab2ef4574c7145a4f3855f229d20089a5ebb3c818f2f43bc784a2caf2b240e 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -230,7 +230,7 @@ @node nncp-daemon @section nncp-daemon @verbatim -% nncp-daemon [options] [-maxconn INT] [-bind ADDR] +% nncp-daemon [options] [-maxconn INT] [-bind ADDR] [-inetd] @end verbatim Start listening TCP daemon, wait for incoming connections and run @@ -241,6 +241,13 @@ @option{-maxconn} option specifies how many simultaneous clients daemon can handle. @option{-bind} option specifies @option{addr:port} it must bind to and listen. + +It could be run as @command{inetd} service, by specifying +@option{-inetd} option. Example inetd-entry: + +@verbatim +uucp stream tcp6 nowait nncpuser /usr/local/bin/nncp-daemon nncp-daemon -inetd +@end verbatim @node nncp-exec @section nncp-exec @@ -503,9 +510,10 @@ @option{INT} seconds in an infinite loop. That can be useful when running this command as a daemon. @option{-seen} option creates empty @file{XXX.seen} file after -successful tossing of @file{XXX} packet. @ref{nncp-xfer} and -@ref{nncp-bundle} commands skip inbound packets that has been already -seen, processed and tossed. This is helpful to defeat duplicates. +successful tossing of @file{XXX} packet. @ref{nncp-xfer}, +@ref{nncp-bundle}, @ref{nncp-daemon} and @ref{nncp-call} commands skip +inbound packets that has been already seen, processed and tossed. This +is helpful to prevent duplicates. @option{-nofile}, @option{-nofreq}, @option{-nomail}, @option{-notrns} options allow to disable any kind of packet types processing. diff --git a/doc/download.texi b/doc/download.texi index 043376fdf764393a58afd84b76199442591d06cc7909fef327e3517e6d7a5723..a52d1b4d2d8e1210fa8781f976f3aabd8fed9a5a35d7e462e15d3283f176fca9 100644 --- a/doc/download.texi +++ b/doc/download.texi @@ -23,6 +23,10 @@ @multitable {XXXXX} {XXXX KiB} {link sign} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} @headitem Version @tab Size @tab Tarball @tab SHA256 checksum +@item @ref{Release 3.3, 3.3} @tab 1152 KiB +@tab @url{download/nncp-3.3.tar.xz, link} @url{download/nncp-3.3.tar.xz.sig, sign} +@tab @code{1F8FA9B4 6125D8A9 0608298B A1ED87E1 12DB2D8B 81C766DE F4DFE191 C7B1BFC2} + @item @ref{Release 3.2, 3.2} @tab 1147 KiB @tab @url{download/nncp-3.2.tar.xz, link} @url{download/nncp-3.2.tar.xz.sig, sign} @tab @code{BE76802F 1E273D1D E91F0648 A7CB23C5 989F5390 A36F2D0C FD873046 51B9141E} diff --git a/doc/install.texi b/doc/install.texi index 33eba0bbd29f1dafa6cadb5fa71331435f38a1e2af3b373e289380ba68ca768f..d54155b6084794317dd5cbdbd64f976a870ae9f18fd5090a01c1d85132b95c7b 100644 --- a/doc/install.texi +++ b/doc/install.texi @@ -5,7 +5,7 @@ Possibly NNCP package already exists for your distribution: @itemize @item @url{https://www.freshports.org/net/nncp/, FreeBSD ports} -@item @url{https://github.com/voidlinux/void-packages/blob/master/srcpkgs/nncp/template, Void Linux} +@item @url{https://github.com/void-linux/void-packages/blob/master/srcpkgs/nncp/template, Void Linux} @end itemize NNCP should run on any POSIX-compatible operating system. diff --git a/doc/news.ru.texi b/doc/news.ru.texi index e4ca43f7bb5e77ced6d399eb398229e3482790a9ffe8ddb3a965945a6f2b1d8b..6f820e37fbe6962f5a999c61d538bde400e06f6ad1e5418e7eda35df48c70259 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -1,6 +1,13 @@ @node Новости @section Новости +@node Релиз 3.4 +@subsection Релиз 3.4 +@itemize +@item +@command{nncp-daemon} может быть запущен как @command{inetd}-служба. +@end itemize + @node Релиз 3.3 @subsection Релиз 3.3 @itemize @@ -144,7 +151,7 @@ @node Релиз 0.11 @subsection Релиз 0.11 @itemize @item -Вывод команды @command{nncp-stat} отсортирован по имены ноды. +Вывод команды @command{nncp-stat} отсортирован по имени ноды. @end itemize @node Релиз 0.10 diff --git a/doc/news.texi b/doc/news.texi index 51aef49d38389d52acf96712a57b434a52829868aac4edd993312f0c20e16b9f..925a396dc99cb37c16fca90ff142397f5397e84d1ce00f122c123b07bd1a21f0 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -3,6 +3,13 @@ @unnumbered News See also this page @ref{Новости, on russian}. +@node Release 3.4 +@section Release 3.4 +@itemize +@item +@command{nncp-daemon} can be run as @command{inetd}-service. +@end itemize + @node Release 3.3 @section Release 3.3 @itemize @@ -19,7 +26,7 @@ Simple packet rate limiter added to online-related tools (@command{nncp-daemon}, @command{nncp-call}, @command{nncp-caller}). @item Ability to specify niceness with symbolic notation: -@verb{|NORMAL|}, @verb{|BULK+10|}, @verb{|PRIORITY-5|}, итд. +@verb{|NORMAL|}, @verb{|BULK+10|}, @verb{|PRIORITY-5|}, etc. @item Changed default niceness levels: for @command{nncp-exec} from 64 to 96, @@ -85,7 +92,7 @@ processing: @option{-nofile}, @option{-nofreq}, @option{-noexec}, @option{-notrns}. @item @command{nncp-file} command uses -@option{FreqMinSize}/@option{FreqChunked} conifiguration file options +@option{FreqMinSize}/@option{FreqChunked} configuration file options for @option{-minsize}/@option{-chunked} by default. You can turn this off by specifying zero value. @end itemize diff --git a/makedist.sh b/makedist.sh index 2f422df0ac54eccb535fe37354e10a06aa9adf9871d2b80c8211fe02cd2abeb1..2989fd3d1b283cc5a441596bda4e5ddbc630c743fda58f1b174a6e89bcd997db 100755 --- a/makedist.sh +++ b/makedist.sh @@ -35,6 +35,7 @@ golang.org/x/crypto/chacha20poly1305 golang.org/x/crypto/curve25519 golang.org/x/crypto/ed25519 golang.org/x/crypto/internal/chacha20 +golang.org/x/crypto/internal/subtle golang.org/x/crypto/nacl golang.org/x/crypto/poly1305 golang.org/x/crypto/salsa20 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go index 830c56b33ba41f4e7c98d6ee9ff895c34bc9b5bb35ad2fe711100d46bea694a9..710fa233dec13b57ceda7b85e711d46bb7109556f46fc83ab7478fcc10219453 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go @@ -26,6 +26,7 @@ "log" "net" "os" "strconv" + "time" "cypherpunks.ru/nncp" "golang.org/x/net/netutil" @@ -38,11 +39,55 @@ fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } +type InetdConn struct { + r *os.File + w *os.File +} + +func (ic *InetdConn) Read(p []byte) (n int, err error) { + return ic.r.Read(p) +} + +func (ic *InetdConn) Write(p []byte) (n int, err error) { + return ic.w.Write(p) +} + +func (ic *InetdConn) SetReadDeadline(t time.Time) error { + return ic.r.SetReadDeadline(t) +} + +func (ic *InetdConn) SetWriteDeadline(t time.Time) error { + return ic.w.SetWriteDeadline(t) +} + +func performSP(ctx *nncp.Ctx, conn nncp.ConnDeadlined, nice uint8) { + state, err := ctx.StartR(conn, nice, "") + if err == nil { + ctx.LogI("call-start", nncp.SDS{"node": state.Node.Id}, "connected") + state.Wait() + ctx.LogI("call-finish", nncp.SDS{ + "node": state.Node.Id, + "duration": strconv.FormatInt(int64(state.Duration.Seconds()), 10), + "rxbytes": strconv.FormatInt(state.RxBytes, 10), + "txbytes": strconv.FormatInt(state.TxBytes, 10), + "rxspeed": strconv.FormatInt(state.RxSpeed, 10), + "txspeed": strconv.FormatInt(state.TxSpeed, 10), + }, "") + } else { + nodeId := "unknown" + if state != nil && state.Node != nil { + nodeId = state.Node.Id.String() + } + ctx.LogE("call-start", nncp.SDS{"node": nodeId, "err": err}, "") + } +} + func main() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness") bind = flag.String("bind", "[::]:5400", "Address to bind to") + inetd = flag.Bool("inetd", false, "Is it started as inetd service") maxConn = flag.Int("maxconn", 128, "Maximal number of simultaneous connections") spoolPath = flag.String("spool", "", "Override path to spool") logPath = flag.String("log", "", "Override path to logfile") @@ -74,6 +119,13 @@ if ctx.Self == nil { log.Fatalln("Config lacks private keys") } + if *inetd { + os.Stderr.Close() + conn := &InetdConn{os.Stdin, os.Stdout} + performSP(ctx, conn, nice) + return + } + ln, err := net.Listen("tcp", *bind) if err != nil { log.Fatalln("Can not listen:", err) @@ -86,25 +138,7 @@ log.Fatalln("Can not accept connection:", err) } ctx.LogD("daemon", nncp.SDS{"addr": conn.RemoteAddr()}, "accepted") go func(conn net.Conn) { - state, err := ctx.StartR(conn, nice, "") - if err == nil { - ctx.LogI("call-start", nncp.SDS{"node": state.Node.Id}, "connected") - state.Wait() - ctx.LogI("call-finish", nncp.SDS{ - "node": state.Node.Id, - "duration": strconv.FormatInt(int64(state.Duration.Seconds()), 10), - "rxbytes": strconv.FormatInt(state.RxBytes, 10), - "txbytes": strconv.FormatInt(state.TxBytes, 10), - "rxspeed": strconv.FormatInt(state.RxSpeed, 10), - "txspeed": strconv.FormatInt(state.TxSpeed, 10), - }, "") - } else { - nodeId := "unknown" - if state != nil && state.Node != nil { - nodeId = state.Node.Id.String() - } - ctx.LogE("call-start", nncp.SDS{"node": nodeId, "err": err}, "") - } + performSP(ctx, conn, nice) conn.Close() }(conn) } diff --git a/src/cypherpunks.ru/nncp/sp.go b/src/cypherpunks.ru/nncp/sp.go index 1dccbd4079eb2dd751d3a1a0f8b0c394e2d5164d947d6e9f8cb5cdc0189b7b78..d92302b2875b2641f3ee5dd5ef6bb10712a485e9c9704015657d23fd54b8ff16 100644 --- a/src/cypherpunks.ru/nncp/sp.go +++ b/src/cypherpunks.ru/nncp/sp.go @@ -104,6 +104,12 @@ freq *SPFreq nice uint8 } +type ConnDeadlined interface { + io.ReadWriter + SetReadDeadline(t time.Time) error + SetWriteDeadline(t time.Time) error +} + func init() { var buf bytes.Buffer spHead := SPHead{Type: SPTypeHalt} @@ -275,7 +281,7 @@ return payloadsSplit(payloads) } func (ctx *Ctx) StartI( - conn net.Conn, + conn ConnDeadlined, nodeId *NodeId, nice uint8, xxOnly TRxTx, @@ -384,7 +390,7 @@ } return &state, err } -func (ctx *Ctx) StartR(conn net.Conn, nice uint8, xxOnly TRxTx) (*SPState, error) { +func (ctx *Ctx) StartR(conn ConnDeadlined, nice uint8, xxOnly TRxTx) (*SPState, error) { started := time.Now() conf := noise.Config{ CipherSuite: NoiseCipherSuite, @@ -499,7 +505,7 @@ return &state, err } func (state *SPState) StartWorkers( - conn net.Conn, + conn ConnDeadlined, infosPayloads [][]byte, payload []byte) error { sds := SDS{"node": state.Node.Id, "nice": strconv.Itoa(int(state.nice))}