]> Cypherpunks.ru repositories - nncp.git/blob - src/area.go
Raise copyright years
[nncp.git] / src / area.go
1 /*
2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2022 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, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package nncp
19
20 import (
21         "errors"
22 )
23
24 const AreaDir = "area"
25
26 var (
27         PktAreaOverhead int64
28 )
29
30 type AreaId [32]byte
31
32 func (id AreaId) String() string {
33         return Base32Codec.EncodeToString(id[:])
34 }
35
36 type Area struct {
37         Name string
38         Id   *AreaId
39         Pub  *[32]byte
40         Prv  *[32]byte
41
42         Subs []*NodeId
43
44         Exec     map[string][]string
45         Incoming *string
46
47         AllowUnknown bool
48 }
49
50 func AreaIdFromString(raw string) (*AreaId, error) {
51         idRaw, err := Base32Codec.DecodeString(raw)
52         if err != nil {
53                 return nil, err
54         }
55         if len(idRaw) != 32 {
56                 return nil, errors.New("Invalid area id size")
57         }
58         areaId := new(AreaId)
59         copy(areaId[:], idRaw)
60         return areaId, nil
61 }
62
63 func (ctx *Ctx) AreaName(id *AreaId) string {
64         area := ctx.AreaId2Area[*id]
65         if area == nil {
66                 return id.String()
67         }
68         return area.Name
69 }