nncp-file \
nncp-freq \
nncp-log \
+ nncp-mincfg \
nncp-newnode \
nncp-pkt \
nncp-stat \
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
@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
@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.
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`
}
type CfgYAML struct {
- Self NodeOurYAML
+ Self *NodeOurYAML `self,omitempty`
Neigh map[string]NodeYAML
Spool string
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
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) {
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)
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
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
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
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
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
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
--- /dev/null
+/*
+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))
+}
}
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[:]),
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,
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
}
}
- 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
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 {
)
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
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],
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)...,
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"),
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"),
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"),
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"),
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"),
LogPath: path.Join(spool, "log.log"),
Debug: true,
Self: nodeOur,
+ SelfId: nodeOur.Id,
Neigh: make(map[NodeId]*Node, hops),
Alias: make(map[string]*NodeId),
}