]> Cypherpunks.ru repositories - nncp.git/commitdiff
nncp-mincfg command
authorSergey Matveev <stargrave@stargrave.org>
Thu, 19 Jan 2017 20:23:08 +0000 (23:23 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 19 Jan 2017 20:33:43 +0000 (23:33 +0300)
18 files changed:
common.mk
doc/cmds.texi
src/cypherpunks.ru/nncp/cfg.go
src/cypherpunks.ru/nncp/cmd/nncp-call/main.go
src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go
src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go
src/cypherpunks.ru/nncp/cmd/nncp-file/main.go
src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go
src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go
src/cypherpunks.ru/nncp/cmd/nncp-mincfg/main.go [new file with mode: 0644]
src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go
src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go
src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go
src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go
src/cypherpunks.ru/nncp/ctx.go
src/cypherpunks.ru/nncp/toss.go
src/cypherpunks.ru/nncp/toss_test.go
src/cypherpunks.ru/nncp/tx_test.go

index c05ae8963307eb6e07c5097a8f4124915c7f2d94..0f7345e4f6b965fbbe68cda35b1739317ca1fc8d 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -25,6 +25,7 @@ ALL = \
        nncp-file \
        nncp-freq \
        nncp-log \
+       nncp-mincfg \
        nncp-newnode \
        nncp-pkt \
        nncp-stat \
@@ -57,6 +58,9 @@ nncp-log:
 nncp-mail:
        GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-mail
 
+nncp-mincfg:
+       GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-mincfg
+
 nncp-newnode:
        GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-newnode
 
index 4c1873f85d2fcd548a3b2b1d355f150e80959779..2751006bd6c65684301f50698d3d8d3b43709bf1 100644 (file)
@@ -166,6 +166,18 @@ 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-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-newnode
 @section nncp-newnode
 
@@ -270,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
 destination node, @file{SENDER} is Base32 encoded sender node.
index c05a6a7c90424999c139f474d8a789f8456d4d04..f89c106f3c3178dadaa3a736b8277f16ad205b7c 100644 (file)
@@ -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 @@ type NotifyYAML struct {
 }
 
 type CfgYAML struct {
-       Self  NodeOurYAML
+       Self  *NodeOurYAML `self,omitempty`
        Neigh map[string]NodeYAML
 
        Spool  string
@@ -231,7 +231,7 @@ func NewNode(name string, yml NodeYAML) (*Node, error) {
        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 @@ func CfgParse(data []byte) (*Ctx, error) {
        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 @@ func CfgParse(data []byte) (*Ctx, error) {
                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)
index 03005a1ac66bc8fe2adba112ba7e7113032756bf..9694639dc6356cbdacb018f7240afcbc6910d749 100644 (file)
@@ -82,6 +82,9 @@ 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
 
index bcfd6c3b001e87777bedfc6c813521bf01850435..3cbbe8f19d05ca8b9797139a2450e6f98773d82d 100644 (file)
@@ -67,6 +67,9 @@ 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
 
index c1355c8a1a0be90e0aaa9436b3cbca8e78b7bbb0..b3678cde1ad0e28425dc4a1a9866363932ab5130 100644 (file)
@@ -73,6 +73,9 @@ 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
 
index f6772863720c7a096f5ca8c02c852a402775f207..3291c3a7ed61398a7a8af085b7d8803081019d0d 100644 (file)
@@ -74,6 +74,9 @@ 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
 
index ada8edbba2854725af5f8b226ed7d96b52f62743..2641da01046b89846fa4c154230d7a12ae7f0592 100644 (file)
@@ -74,6 +74,9 @@ 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
 
index 223aea520e5d848b65d3b305ca6f4cf74cf4bd25..c09fbe228e2aa415bed4bb0009a24718ecc6888b 100644 (file)
@@ -75,6 +75,9 @@ 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
 
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 (file)
index 0000000..5b5fdf5
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+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
+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 <http://www.gnu.org/licenses/>.
+*/
+
+// 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))
+}
index b32a32d2264276bf0da10114ac4a62144d3e2e9b..080160bb4581b866f3eac0b9225383636b02119a 100644 (file)
@@ -55,7 +55,7 @@ func main() {
        }
        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[:]),
index 82bcffbd5d0fe444e0908fc5e15106a9fa46ae1f..93759b69ee7037fca2984d42580fbd7bc2c1e13f 100644 (file)
@@ -122,6 +122,9 @@ func main() {
                        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,
index 11066956a3fcbbc6b9495158fa4d6a2cb41ac059..71a15ee87561742e0aeb1d985661bbdb10bec2fc 100644 (file)
@@ -72,6 +72,9 @@ 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
 
index 9c2b5e211efd96eaaa8acd1fbed765e3bcb41403..b11fc5d9e328f7d920ab9f5f119c3a714c8606cc 100644 (file)
@@ -96,7 +96,7 @@ func main() {
                }
        }
 
-       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 @@ Tx:
                                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 {
index c3dc144d3d6284678b9fc2f8fc29c7c55fcbeaeb..21b3d6fd8e8efe76e146b02e1d47af38d0df675a 100644 (file)
@@ -25,9 +25,10 @@ import (
 )
 
 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
index 11e85914bebcb0c179b4d75e77df25dc9a49610d..9d17053e665ac760ed33e23ba86634ebefc7aa4a 100644 (file)
@@ -220,7 +220,7 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun bool) bool {
                                        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 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun bool) bool {
                                        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)...,
index f0038d8ac38493cd32de83ffea2f59fc4612792e..c40c9d8628779ffe5b5855f0922b05575d930c3c 100644 (file)
@@ -68,6 +68,7 @@ func TestTossEmail(t *testing.T) {
                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 @@ func TestTossFile(t *testing.T) {
                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 @@ func TestTossFileSameName(t *testing.T) {
                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 @@ func TestTossFreq(t *testing.T) {
                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 @@ func TestTossTrns(t *testing.T) {
                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"),
index c46f057789a7b21e6ba7c2c85259011613a63ac3..ad721bc09e90a80577837fb99a845538c77f71e0 100644 (file)
@@ -58,6 +58,7 @@ func TestTx(t *testing.T) {
                        LogPath: path.Join(spool, "log.log"),
                        Debug:   true,
                        Self:    nodeOur,
+                       SelfId:  nodeOur.Id,
                        Neigh:   make(map[NodeId]*Node, hops),
                        Alias:   make(map[string]*NodeId),
                }