VERSION | 2 +- common.mk | 10 +++++++--- doc/cmds.texi | 26 +++++++++++++++++++++----- doc/download.texi | 4 ++++ doc/news.texi | 12 ++++++++++++ doc/workflow.texi | 2 +- ports/nncp/Makefile | 5 +++-- ports/nncp/files/pkg-message.in | 2 +- src/cypherpunks.ru/nncp/cfg.go | 21 ++++++++++++++------- src/cypherpunks.ru/nncp/cmd/nncp-call/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-file/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-mincfg/main.go | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go => src/cypherpunks.ru/nncp/cmd/nncp-newcfg/main.go | 6 +++--- src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go | 3 +++ src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go | 4 ++-- src/cypherpunks.ru/nncp/ctx.go | 7 ++++--- src/cypherpunks.ru/nncp/sp.go | 5 +++++ src/cypherpunks.ru/nncp/toss.go | 4 ++-- src/cypherpunks.ru/nncp/toss_test.go | 5 +++++ src/cypherpunks.ru/nncp/tx_test.go | 1 + diff --git a/VERSION b/VERSION index cae6c688f13ebc7d1fe765a26e8091edf1c44c934d3bab97d4345973be03b3eb..de2f5c302ef01d4b9fbf0ab9adae4398f059d3a4f6fd85568feadf7180a58e59 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3 +0.4 diff --git a/common.mk b/common.mk index dc4a43b2e37b7f19c7a0df6f691ca4902cd9de5f3192453d242c07ef57303745..6285890ff283a51d88a9b78ca12009f4e08a85d7e16c2067baaee88f94b05915 100644 --- a/common.mk +++ b/common.mk @@ -25,7 +25,8 @@ nncp-daemon \ nncp-file \ nncp-freq \ nncp-log \ - nncp-newnode \ + nncp-mincfg \ + nncp-newcfg \ nncp-pkt \ nncp-stat \ nncp-toss \ @@ -57,8 +58,11 @@ nncp-mail: GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-mail -nncp-newnode: - GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-newnode +nncp-mincfg: + GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-mincfg + +nncp-newcfg: + GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-newcfg nncp-pkt: GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-pkt diff --git a/doc/cmds.texi b/doc/cmds.texi index 9506e3ab410d7e30bf477fe935dddd2b5f1a0c838421563f0c4464159e61fd20..17272e5a282816f8c54ee87922b81dbbac91e6511267ecd694e752d7334d44bf 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -166,15 +166,28 @@ side will execute specified @ref{CfgSendmail, sendmail} command with @option{USER}s appended as a command line argument and feed decompressed mail body to that command's stdin. -@node nncp-newnode -@section nncp-newnode +@node nncp-mincfg +@section nncp-mincfg + +@verbatim +% nncp-mincfg [options] > stripped.yaml +@end verbatim + +Print out stripped configuration version: only path to @ref{Spool, +spool}, path to log file, neighbours public keys are stayed. This is +useful mainly for usage with @ref{nncp-xfer} that has to know only +neighbours, without private keys involving. + +@node nncp-newcfg +@section nncp-newcfg @verbatim -% nncp-newnode [options] > mynewnode.yaml +% nncp-newcfg [options] > new.yaml @end verbatim -Generate new node: private keys, example configuration file and print it -to stdout. You must use this command when you setup the new node. +Generate new node configuration: private keys, example configuration +file and print it to stdout. You must use this command when you setup +the new node. Pay attention that private keys generation consumes an entropy from your operating system. @@ -269,6 +282,9 @@ remove them. @option{-rx} option tells only to move inbound packets addressed to us. @option{-tx} option tells exactly the opposite: move only outbound packets. + +@ref{nncp-mincfg} could be useful for creating stripped minimalistic +configuration file version without any private keys. @file{DIR} directory has the following structure: @file{RECIPIENT/SENDER/PACKET}, where @file{RECIPIENT} is Base32 encoded diff --git a/doc/download.texi b/doc/download.texi index 11d0fbf55370672d1a020969264f66c50529f89b418fe986d62d18aa69e8a1aa..7bba5e53471395e77da65ad93984477000bb8282d1210545771ff56d0aea9b9f 100644 --- a/doc/download.texi +++ b/doc/download.texi @@ -31,4 +31,8 @@ @item @ref{Release 0.2, 0.2} @tab 740 KiB @tab @url{download/nncp-0.2.tar.xz, link} @url{download/nncp-0.2.tar.xz.sig, sign} @tab @code{00BEAC5A 0C4083B0 42E3152B ACA6FF20 12768B82 CE24D716 8E04279C ECE14DB7} +@item @ref{Release 0.3, 0.3} @tab 741 KiB +@tab @url{download/nncp-0.3.tar.xz, link} @url{download/nncp-0.3.tar.xz.sig, sign} +@tab @code{6E76EC5E 6B575C65 BF2D6388 870F2A1C 417D63E4 1628CAA1 BB499D0D 0634473B} + @end multitable diff --git a/doc/news.texi b/doc/news.texi index 1fbe18da5de053a8712b4164a00e8b699c1377f92225e1b532e9ac7988cc7e40..988ba0395e276550aee638ed0a8eac7375c813c95fa5998a5a72e719c5943c12 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -24,3 +24,15 @@ @node Release 0.3 @section Release 0.3 Fixed compatibility with Go 1.6. + +@node Release 0.4 +@section Release 0.4 +@itemize +@item Small fix in @ref{nncp-call}, @ref{nncp-caller}, +@ref{nncp-daemon}: they can segmentation fail sometimes (no data is lost). +@item @command{nncp-newnode} renamed to @ref{nncp-newcfg} -- it is +shorter and more convenient to use. +@item @ref{nncp-mincfg} command appeared: helper allowing to create +minimalistic stripped down configuration files without private keys, +that is useful during @ref{nncp-xfer} usage. +@end itemize diff --git a/doc/workflow.texi b/doc/workflow.texi index 33571ec159192dcc7376dda84729468907d1affc76b1fe0dcb9c2ffb3ce0696b..a84e7a685a7810d30f99797a5579ecf92cb66fe1d2706c5152d249518a589faf 100644 --- a/doc/workflow.texi +++ b/doc/workflow.texi @@ -5,7 +5,7 @@ NNCP consists of several utilities. As a rule you will have the following workflow: @enumerate -@item Run @ref{nncp-newnode} on each node to create an initial +@item Run @ref{nncp-newcfg} on each node to create an initial @ref{Configuration, configuration} file. @item Tune it up and set at least @ref{Spool, spool} and log paths. @item Share your public keys and reachability addressees with your diff --git a/ports/nncp/Makefile b/ports/nncp/Makefile index c8388efff3a203659d48058318e4af9e2224093e20a7d8de8053d1356a358918..12504f74ffe7cd97edff7ab4149076e76f682d0ed7da71b8eb9bcb311d7c34fb 100644 --- a/ports/nncp/Makefile +++ b/ports/nncp/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ PORTNAME= nncp -PORTVERSION= 0.2 +PORTVERSION= 0.4 CATEGORIES= net MASTER_SITES= http://www.nncpgo.org/download/ \ http://sourceforge.net/projects/nncp/files/ @@ -34,7 +34,8 @@ bin/nncp-file \ bin/nncp-freq \ bin/nncp-log \ bin/nncp-mail \ - bin/nncp-newnode \ + bin/nncp-mincfg \ + bin/nncp-newcfg \ bin/nncp-pkt \ bin/nncp-stat \ bin/nncp-toss \ diff --git a/ports/nncp/files/pkg-message.in b/ports/nncp/files/pkg-message.in index 5be96b12fd962150f0204b6c3fa194e2e6d00fbe656b437ea6148cde042fd655..138a6fb55544a7fd44379ffa0c2e990c66fa065d0f078d0c3979ee37aaffa99e 100644 --- a/ports/nncp/files/pkg-message.in +++ b/ports/nncp/files/pkg-message.in @@ -13,5 +13,5 @@ - Look in nncp.info how to integrate mail exchanging with Postfix. - Generate NNCP configuration file using the command: # umask 077 - # nncp-newnode > %%PREFIX%%/etc/nncp.yaml + # nncp-newcfg > %%PREFIX%%/etc/nncp.yaml ====================================================================== diff --git a/src/cypherpunks.ru/nncp/cfg.go b/src/cypherpunks.ru/nncp/cfg.go index 4334e1a7308ee0a62ed6d3998229fa645c9b19edeaf067ab701c845dd73c48fd..a2b6247a618b9ff7486db694ffd53742107a96554f3cc1eec222e04d0e8bae5f 100644 --- a/src/cypherpunks.ru/nncp/cfg.go +++ b/src/cypherpunks.ru/nncp/cfg.go @@ -43,8 +43,8 @@ type NodeYAML struct { Id string ExchPub string SignPub string - NoisePub *string `noisepub,omitempty` - Sendmail []string + NoisePub *string `noisepub,omitempty` + Sendmail []string `sendmail,omitempty` Incoming *string `incoming,omitempty` Freq *string `freq,omitempty` Via []string `via,omitempty` @@ -86,7 +86,7 @@ Freq *FromToYAML `freq,omitempty` } type CfgYAML struct { - Self NodeOurYAML + Self *NodeOurYAML `self,omitempty` Neigh map[string]NodeYAML Spool string @@ -231,7 +231,7 @@ } return &node, nil } -func NewNodeOur(yml NodeOurYAML) (*NodeOur, error) { +func NewNodeOur(yml *NodeOurYAML) (*NodeOur, error) { id, err := NodeIdFromString(yml.Id) if err != nil { return nil, err @@ -324,9 +324,15 @@ err := yaml.Unmarshal(data, &cfgYAML) if err != nil { return nil, err } - self, err := NewNodeOur(cfgYAML.Self) - if err != nil { - return nil, err + if _, exists := cfgYAML.Neigh["self"]; !exists { + return nil, errors.New("self neighbour missing") + } + var self *NodeOur + if cfgYAML.Self != nil { + self, err = NewNodeOur(cfgYAML.Self) + if err != nil { + return nil, err + } } spoolPath := path.Clean(cfgYAML.Spool) if !path.IsAbs(spoolPath) { @@ -364,6 +370,7 @@ } ctx.Alias[name] = neigh.Id vias[*neigh.Id] = neighYAML.Via } + ctx.SelfId = ctx.Alias["self"] for neighId, viasRaw := range vias { for _, viaRaw := range viasRaw { foundNodeId, err := ctx.FindNode(viaRaw) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go index 976509c271db21b380aa2f5d9271ddb7cf8a5338384d389363fff0a05ecf8073..feaf876dbfb1afdfad7343a96a5aed12fa59c5d5aae07c01243ca861fbb95dae 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go @@ -82,6 +82,9 @@ ctx, err := nncp.CfgParse(cfgRaw) 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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go index 85a6e96688a9b12963d0269f1fcd596bb80c895edec575570724c6824b75130f..dac1d0944c44611c264a25be1ad5e926c6e08460107b8cb192470dfcfd8b0831 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go @@ -67,6 +67,9 @@ ctx, err := nncp.CfgParse(cfgRaw) 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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go index 99e8eb46b084de7eaa044748025527ef50330f0b935dec0d720ec2961d468f8e..cdb4f56338d4af5bc08453443a2ce2c048f5d3d3c57467a97e6068a6b96412fb 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go @@ -73,6 +73,9 @@ ctx, err := nncp.CfgParse(cfgRaw) 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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go index a59c6a0ea048d0e2778e2363b313154cbc0f3880edbb946dc34c117f7bc37126..b831dccee40c93cccd4d4c73fe68e2a32020206260278b2fadbc95c74fdc91e4 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go @@ -74,6 +74,9 @@ ctx, err := nncp.CfgParse(cfgRaw) 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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go index bab6a0acce818ebaae8ed220e7ad45239c6888810be4eaee8b9e16843773a9a6..2918169245f4a0ede27941c3151246bb9fc732b8b29466055066f4b1ccf9db82 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go @@ -74,6 +74,9 @@ ctx, err := nncp.CfgParse(cfgRaw) 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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go index c338546b355fcd59536dd83c96cd6e7f6e68e515ae1a1d6476e9c7f09c661f02..3afe652bbc5fb77b59d898f122fb6857f45bfb8b0685f8fe10bd505ac3c79c2b 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go @@ -75,6 +75,9 @@ ctx, err := nncp.CfgParse(cfgRaw) 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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-mincfg/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-mincfg/main.go new file mode 100644 index 0000000000000000000000000000000000000000..5d5154dd58a3893e91ac7d350dcf34a5802a01802bdf733abf31277b15cf4e8f --- /dev/null +++ b/src/cypherpunks.ru/nncp/cmd/nncp-mincfg/main.go @@ -0,0 +1,89 @@ +/* +NNCP -- Node to Node copy, utilities for store-and-forward data exchange +Copyright (C) 2016-2017 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 +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +// Stripped NNCP configuration file. +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "log" + "os" + + "cypherpunks.ru/nncp" + "gopkg.in/yaml.v2" +) + +func usage() { + fmt.Fprintf(os.Stderr, nncp.UsageHeader()) + fmt.Fprintln(os.Stderr, "nncp-mincfg -- print stripped configuration\n") + fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) + flag.PrintDefaults() +} + +func main() { + var ( + cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") + version = flag.Bool("version", false, "Print version information") + warranty = flag.Bool("warranty", false, "Print warranty information") + ) + flag.Usage = usage + flag.Parse() + if *warranty { + fmt.Println(nncp.Warranty) + return + } + if *version { + fmt.Println(nncp.VersionGet()) + return + } + + cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath)) + if err != nil { + log.Fatalln("Can not read config:", err) + } + ctx, err := nncp.CfgParse(cfgRaw) + if err != nil { + log.Fatalln("Can not parse config:", err) + } + + cfg := nncp.CfgYAML{ + Spool: ctx.Spool, + Log: ctx.LogPath, + Neigh: make(map[string]nncp.NodeYAML), + } + for _, node := range ctx.Neigh { + var noisePub *string + if node.NoisePub != nil { + np := nncp.ToBase32(node.NoisePub[:]) + noisePub = &np + } + cfg.Neigh[node.Name] = nncp.NodeYAML{ + Id: node.Id.String(), + ExchPub: nncp.ToBase32(node.ExchPub[:]), + SignPub: nncp.ToBase32(node.SignPub[:]), + NoisePub: noisePub, + } + } + raw, err := yaml.Marshal(&cfg) + if err != nil { + panic(err) + } + fmt.Print(string(raw)) +} diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-newcfg/main.go rename from src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go rename to src/cypherpunks.ru/nncp/cmd/nncp-newcfg/main.go index 408201f0cf42678835d69a38e68315743a9631b3a0fc832bd921f2f75da79099..5c9fdd64e86f28c157a042cdb46599f7beb20312974d471184874048a0178ea3 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-newcfg/main.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -// Generate new NNCP node keys +// Generate new NNCP node keys and configuration file package main import ( @@ -30,7 +30,7 @@ ) func usage() { fmt.Fprintf(os.Stderr, nncp.UsageHeader()) - fmt.Fprintln(os.Stderr, "nncp-newnode -- generate new node keys\nOptions:") + fmt.Fprintln(os.Stderr, "nncp-newcfg -- generate new configuration and keys\nOptions:") flag.PrintDefaults() } @@ -55,7 +55,7 @@ panic(err) } noisePub := nncp.ToBase32(nodeOur.NoisePub[:]) cfg := nncp.CfgYAML{ - Self: nncp.NodeOurYAML{ + Self: &nncp.NodeOurYAML{ Id: nodeOur.Id.String(), ExchPub: nncp.ToBase32(nodeOur.ExchPub[:]), ExchPrv: nncp.ToBase32(nodeOur.ExchPrv[:]), diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go index 7908c849cd94080995a81bc9d983f98aa2bcb8df1b18a192027959f5159ba213..b93a29450b0e4f3340709b154e93a6d32322f2aa81e1f4208c976882f63f7e7e 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go @@ -122,6 +122,9 @@ ctx, err := nncp.CfgParse(cfgRaw) if err != nil { log.Fatalln("Can not parse config:", err) } + if ctx.Self == nil { + log.Fatalln("Config lacks private keys") + } bufW := bufio.NewWriter(os.Stdout) if _, _, err = nncp.PktEncRead( ctx.Self, diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go index 057fbaa7da2be4660bf48c1e99eab1e05fe343e0731c98653c23e0f735275e1b..b434cffe1c4d3d8d634edd23815353e3c918d924bde4a645c363be8b604092bb 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go @@ -72,6 +72,9 @@ ctx, err := nncp.CfgParse(cfgRaw) 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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go index 091f5c9f52db7c07baf04131b2e46cae1bf720eb414aa8eb30d93ed5b8ca69ac..e59f0f06c8653bdbb74f62165153100c07c4a27d5779f7e6ee8c08cd10a80638 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go @@ -96,7 +96,7 @@ log.Fatalln("Invalid -node specified:", err) } } - selfPath := filepath.Join(flag.Arg(0), ctx.Self.Id.String()) + selfPath := filepath.Join(flag.Arg(0), ctx.SelfId.String()) isBad := false var dir *os.File var fis []os.FileInfo @@ -258,7 +258,7 @@ isBad = true continue } } - dstPath := filepath.Join(nodePath, ctx.Self.Id.String()) + dstPath := filepath.Join(nodePath, ctx.SelfId.String()) sds["dir"] = dstPath _, err = os.Stat(dstPath) if err != nil { diff --git a/src/cypherpunks.ru/nncp/ctx.go b/src/cypherpunks.ru/nncp/ctx.go index ec4bef4fd85e90c313536aab86f450048420a81fb91705d85c14e9b54cb83895..2cead9c2ebddb52f1cc1abfa424ca6d18ed720f155fe98bbd95b48b301e4dc8e 100644 --- a/src/cypherpunks.ru/nncp/ctx.go +++ b/src/cypherpunks.ru/nncp/ctx.go @@ -25,9 +25,10 @@ "path/filepath" ) type Ctx struct { - Self *NodeOur - Neigh map[NodeId]*Node - Alias map[string]*NodeId + Self *NodeOur + SelfId *NodeId + Neigh map[NodeId]*Node + Alias map[string]*NodeId Spool string LogPath string diff --git a/src/cypherpunks.ru/nncp/sp.go b/src/cypherpunks.ru/nncp/sp.go index 5b0213376dffe90bfa03a9c5286879a7f4d224ffc8520283037edc371112afa5..6fc777884dc41a3f4474fc5c574e7b274ec04073e451b8d7c436fc56be5c9161 100644 --- a/src/cypherpunks.ru/nncp/sp.go +++ b/src/cypherpunks.ru/nncp/sp.go @@ -826,13 +826,16 @@ fd.Close() return nil, err } ourSize := uint64(file.Offset) + uint64(len(file.Payload)) + state.RLock() sdsp["fullsize"] = strconv.FormatInt(int64(state.infosTheir[*file.Hash].Size), 10) sdsp["size"] = strconv.FormatInt(int64(ourSize), 10) state.ctx.LogP("sp-file", sdsp, "") if state.infosTheir[*file.Hash].Size != ourSize { + state.RUnlock() fd.Close() continue } + state.RUnlock() go func() { if err := fd.Sync(); err != nil { state.ctx.LogE("sp-file", SdsAdd(sdsp, SDS{"err": err}), "sync") @@ -918,10 +921,12 @@ } if infosGot { var pkts int var size uint64 + state.RLock() for _, info := range state.infosTheir { pkts++ size += info.Size } + state.RUnlock() state.ctx.LogI("sp-infos", SDS{ "xx": string(TRx), "node": state.Node.Id, diff --git a/src/cypherpunks.ru/nncp/toss.go b/src/cypherpunks.ru/nncp/toss.go index 44c160b06f587ec9aa0b851066961ccd423aa76d6b90eeddcb7a25edcb3daa5f..3e2f49070ef3c08261b691940398a33accbfdf53da7ece5b91c147b68f8c18ad 100644 --- a/src/cypherpunks.ru/nncp/toss.go +++ b/src/cypherpunks.ru/nncp/toss.go @@ -220,7 +220,7 @@ if err = os.Remove(job.Fd.Name()); err != nil { ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "remove") isBad = true } - sendmail := ctx.Neigh[*ctx.Self.Id].Sendmail + sendmail := ctx.Neigh[*ctx.SelfId].Sendmail if ctx.NotifyFile != nil { cmd := exec.Command( sendmail[0], @@ -267,7 +267,7 @@ ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "remove") isBad = true } if ctx.NotifyFreq != nil { - sendmail := ctx.Neigh[*ctx.Self.Id].Sendmail + sendmail := ctx.Neigh[*ctx.SelfId].Sendmail cmd := exec.Command( sendmail[0], append(sendmail[1:len(sendmail)], ctx.NotifyFreq.To)..., diff --git a/src/cypherpunks.ru/nncp/toss_test.go b/src/cypherpunks.ru/nncp/toss_test.go index a1f2e8035c0be278f3b050d89fb00fcc50ae892f8859763333d66abb3d381396..a96279d17d1e8d52547eece41daa23d71a0fa73fde9622127aae361460a44131 100644 --- a/src/cypherpunks.ru/nncp/toss_test.go +++ b/src/cypherpunks.ru/nncp/toss_test.go @@ -68,6 +68,7 @@ } ctx := Ctx{ Spool: spool, Self: nodeOur, + SelfId: nodeOur.Id, Neigh: make(map[NodeId]*Node), Alias: make(map[string]*NodeId), LogPath: filepath.Join(spool, "log.log"), @@ -162,6 +163,7 @@ } ctx := Ctx{ Spool: spool, Self: nodeOur, + SelfId: nodeOur.Id, Neigh: make(map[NodeId]*Node), Alias: make(map[string]*NodeId), LogPath: filepath.Join(spool, "log.log"), @@ -230,6 +232,7 @@ } ctx := Ctx{ Spool: spool, Self: nodeOur, + SelfId: nodeOur.Id, Neigh: make(map[NodeId]*Node), Alias: make(map[string]*NodeId), LogPath: filepath.Join(spool, "log.log"), @@ -298,6 +301,7 @@ } ctx := Ctx{ Spool: spool, Self: nodeOur, + SelfId: nodeOur.Id, Neigh: make(map[NodeId]*Node), Alias: make(map[string]*NodeId), LogPath: filepath.Join(spool, "log.log"), @@ -396,6 +400,7 @@ } ctx := Ctx{ Spool: spool, Self: nodeOur, + SelfId: nodeOur.Id, Neigh: make(map[NodeId]*Node), Alias: make(map[string]*NodeId), LogPath: filepath.Join(spool, "log.log"), diff --git a/src/cypherpunks.ru/nncp/tx_test.go b/src/cypherpunks.ru/nncp/tx_test.go index 31a21b7581106ff74cd19f47c23d55408fa4ff2423d9e28ea87611735f3e239d..2cd2e22c81742efa64f52eda45a0cbdb0577eb4d94cb7fb3161b468807ec2f7c 100644 --- a/src/cypherpunks.ru/nncp/tx_test.go +++ b/src/cypherpunks.ru/nncp/tx_test.go @@ -58,6 +58,7 @@ Spool: spool, LogPath: path.Join(spool, "log.log"), Debug: true, Self: nodeOur, + SelfId: nodeOur.Id, Neigh: make(map[NodeId]*Node, hops), Alias: make(map[string]*NodeId), }