2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 Neigh map[NodeId]*Node
32 Alias map[string]*NodeId
38 NotifyFile *FromToYAML
39 NotifyFreq *FromToYAML
42 func (ctx *Ctx) FindNode(id string) (*Node, error) {
43 nodeId, known := ctx.Alias[id]
45 return ctx.Neigh[*nodeId], nil
47 nodeId, err := NodeIdFromString(id)
51 node, known := ctx.Neigh[*nodeId]
53 return nil, errors.New("Unknown node")
58 func (ctx *Ctx) ensureRxDir(nodeId *NodeId) error {
59 dirPath := filepath.Join(ctx.Spool, nodeId.String(), string(TRx))
60 if err := os.MkdirAll(dirPath, os.FileMode(0700)); err != nil {
61 ctx.LogE("dir-ensure", SDS{"dir": dirPath, "err": err}, "")
64 fd, err := os.Open(dirPath)
66 ctx.LogE("dir-ensure", SDS{"dir": dirPath, "err": err}, "")
73 func CtxFromCmdline(cfgPath, spoolPath, logPath string, quiet, debug bool) (*Ctx, error) {
74 env := os.Getenv(CfgPathEnv)
78 cfgRaw, err := ioutil.ReadFile(cfgPath)
82 ctx, err := CfgParse(cfgRaw)
87 env = os.Getenv(CfgSpoolEnv)
95 env = os.Getenv(CfgLogEnv)
100 ctx.LogPath = logPath