]> Cypherpunks.ru repositories - nncp.git/blob - src/cypherpunks.ru/nncp/ctx.go
Initial
[nncp.git] / src / cypherpunks.ru / nncp / ctx.go
1 /*
2 NNCP -- Node-to-Node CoPy
3 Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
4
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.
9
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.
14
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/>.
17 */
18
19 package nncp
20
21 import (
22         "errors"
23 )
24
25 type Ctx struct {
26         Self  *NodeOur
27         Neigh map[NodeId]*Node
28         Alias map[string]*NodeId
29
30         Spool    string
31         Sendmail []string
32
33         LogPath    string
34         Debug      bool
35         NotifyFile *FromToYAML
36         NotifyFreq *FromToYAML
37 }
38
39 func (ctx *Ctx) FindNode(id string) (*Node, error) {
40         nodeId, known := ctx.Alias[id]
41         if known {
42                 return ctx.Neigh[*nodeId], nil
43         }
44         nodeId, err := NodeIdFromString(id)
45         if err != nil {
46                 return nil, err
47         }
48         node, known := ctx.Neigh[*nodeId]
49         if !known {
50                 return nil, errors.New("Unknown node")
51         }
52         return node, nil
53 }