]> Cypherpunks.ru repositories - nncp.git/blob - src/magic.go
78145127eaaed95da5eca1a2ea7bb8cd8910881f
[nncp.git] / src / magic.go
1 /*
2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2021 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         "fmt"
23 )
24
25 type Magic struct {
26         B    [8]byte
27         Name string
28         Till string
29 }
30
31 var (
32         MagicNNCPBv1 = Magic{
33                 B:    [8]byte{'N', 'N', 'C', 'P', 'B', 0, 0, 1},
34                 Name: "NNCPBv1 (EBlob v1)", Till: "1.0",
35         }
36         MagicNNCPBv2 = Magic{
37                 B:    [8]byte{'N', 'N', 'C', 'P', 'B', 0, 0, 2},
38                 Name: "NNCPBv2 (EBlob v2)", Till: "3.4",
39         }
40         MagicNNCPBv3 = Magic{
41                 B:    [8]byte{'N', 'N', 'C', 'P', 'B', 0, 0, 3},
42                 Name: "NNCPBv3 (EBlob v3)", Till: "now",
43         }
44         MagicNNCPDv1 = Magic{
45                 B:    [8]byte{'N', 'N', 'C', 'P', 'D', 0, 0, 1},
46                 Name: "NNCPDv1 (multicast discovery v1)", Till: "now",
47         }
48         MagicNNCPEv1 = Magic{
49                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 1},
50                 Name: "NNCPEv1 (encrypted packet v1)", Till: "0.12",
51         }
52         MagicNNCPEv2 = Magic{
53                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 2},
54                 Name: "NNCPEv2 (encrypted packet v2)", Till: "1.0",
55         }
56         MagicNNCPEv3 = Magic{
57                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 3},
58                 Name: "NNCPEv3 (encrypted packet v3)", Till: "3.4",
59         }
60         MagicNNCPEv4 = Magic{
61                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 4},
62                 Name: "NNCPEv4 (encrypted packet v4)", Till: "6.6.0",
63         }
64         MagicNNCPEv5 = Magic{
65                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 5},
66                 Name: "NNCPEv5 (encrypted packet v5)", Till: "now",
67         }
68         MagicNNCPSv1 = Magic{
69                 B:    [8]byte{'N', 'N', 'C', 'P', 'S', 0, 0, 1},
70                 Name: "NNCPSv1 (sync protocol v1)", Till: "now",
71         }
72         MagicNNCPMv1 = Magic{
73                 B:    [8]byte{'N', 'N', 'C', 'P', 'M', 0, 0, 1},
74                 Name: "NNCPMv1 (chunked .meta v1)", Till: "6.6.0",
75         }
76         MagicNNCPMv2 = Magic{
77                 B:    [8]byte{'N', 'N', 'C', 'P', 'M', 0, 0, 2},
78                 Name: "NNCPMv2 (chunked .meta v2)", Till: "now",
79         }
80         MagicNNCPPv1 = Magic{
81                 B:    [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 1},
82                 Name: "NNCPPv1 (plain packet v1)", Till: "2.0",
83         }
84         MagicNNCPPv2 = Magic{
85                 B:    [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 2},
86                 Name: "NNCPPv2 (plain packet v2)", Till: "4.1",
87         }
88         MagicNNCPPv3 = Magic{
89                 B:    [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 3},
90                 Name: "NNCPPv3 (plain packet v3)", Till: "now",
91         }
92
93         BadMagic error = errors.New("Unknown magic number")
94 )
95
96 func (m *Magic) TooOld() error {
97         return fmt.Errorf("%s format is unsupported (used till %s)", m.Name, m.Till)
98 }