]> Cypherpunks.ru repositories - nncp.git/blob - src/magic.go
Note about buildability with 1.22
[nncp.git] / src / magic.go
1 // NNCP -- Node to Node copy, utilities for store-and-forward data exchange
2 // Copyright (C) 2016-2024 Sergey Matveev <stargrave@stargrave.org>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 package nncp
17
18 import (
19         "errors"
20         "fmt"
21 )
22
23 type Magic struct {
24         B    [8]byte
25         Name string
26         Till string
27 }
28
29 var (
30         MagicNNCPAv1 = Magic{
31                 B:    [8]byte{'N', 'N', 'C', 'P', 'A', 0, 0, 1},
32                 Name: "NNCPAv1 (area packet v1)", Till: "now",
33         }
34         MagicNNCPBv1 = Magic{
35                 B:    [8]byte{'N', 'N', 'C', 'P', 'B', 0, 0, 1},
36                 Name: "NNCPBv1 (EBlob v1)", Till: "1.0",
37         }
38         MagicNNCPBv2 = Magic{
39                 B:    [8]byte{'N', 'N', 'C', 'P', 'B', 0, 0, 2},
40                 Name: "NNCPBv2 (EBlob v2)", Till: "3.4",
41         }
42         MagicNNCPBv3 = Magic{
43                 B:    [8]byte{'N', 'N', 'C', 'P', 'B', 0, 0, 3},
44                 Name: "NNCPBv3 (EBlob v3)", Till: "now",
45         }
46         MagicNNCPDv1 = Magic{
47                 B:    [8]byte{'N', 'N', 'C', 'P', 'D', 0, 0, 1},
48                 Name: "NNCPDv1 (multicast discovery v1)", Till: "now",
49         }
50         MagicNNCPEv1 = Magic{
51                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 1},
52                 Name: "NNCPEv1 (encrypted packet v1)", Till: "0.12",
53         }
54         MagicNNCPEv2 = Magic{
55                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 2},
56                 Name: "NNCPEv2 (encrypted packet v2)", Till: "1.0",
57         }
58         MagicNNCPEv3 = Magic{
59                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 3},
60                 Name: "NNCPEv3 (encrypted packet v3)", Till: "3.4",
61         }
62         MagicNNCPEv4 = Magic{
63                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 4},
64                 Name: "NNCPEv4 (encrypted packet v4)", Till: "6.6.0",
65         }
66         MagicNNCPEv5 = Magic{
67                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 5},
68                 Name: "NNCPEv5 (encrypted packet v5)", Till: "7.7.0",
69         }
70         MagicNNCPEv6 = Magic{
71                 B:    [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 6},
72                 Name: "NNCPEv6 (encrypted packet v6)", Till: "now",
73         }
74         MagicNNCPSv1 = Magic{
75                 B:    [8]byte{'N', 'N', 'C', 'P', 'S', 0, 0, 1},
76                 Name: "NNCPSv1 (sync protocol v1)", Till: "now",
77         }
78         MagicNNCPMv1 = Magic{
79                 B:    [8]byte{'N', 'N', 'C', 'P', 'M', 0, 0, 1},
80                 Name: "NNCPMv1 (chunked .meta v1)", Till: "6.6.0",
81         }
82         MagicNNCPMv2 = Magic{
83                 B:    [8]byte{'N', 'N', 'C', 'P', 'M', 0, 0, 2},
84                 Name: "NNCPMv2 (chunked .meta v2)", Till: "now",
85         }
86         MagicNNCPPv1 = Magic{
87                 B:    [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 1},
88                 Name: "NNCPPv1 (plain packet v1)", Till: "2.0",
89         }
90         MagicNNCPPv2 = Magic{
91                 B:    [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 2},
92                 Name: "NNCPPv2 (plain packet v2)", Till: "4.1",
93         }
94         MagicNNCPPv3 = Magic{
95                 B:    [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 3},
96                 Name: "NNCPPv3 (plain packet v3)", Till: "now",
97         }
98
99         BadMagic error = errors.New("Unknown magic number")
100 )
101
102 func (m *Magic) TooOld() error {
103         return fmt.Errorf("%s format is unsupported (used till %s)", m.Name, m.Till)
104 }