File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ type Capability struct {
64
64
func (c * Capability ) DecodeBinary (br * io.BinReader ) {
65
65
c .Type = Type (br .ReadB ())
66
66
switch c .Type {
67
+ case ArchivalNode :
68
+ c .Data = & Archival {}
67
69
case FullNode :
68
70
c .Data = & Node {}
69
71
case TCPServer , WSServer :
@@ -115,6 +117,22 @@ func (s *Server) EncodeBinary(bw *io.BinWriter) {
115
117
bw .WriteU16LE (s .Port )
116
118
}
117
119
120
+ // Archival represents an archival node that stores all blocks.
121
+ type Archival struct {}
122
+
123
+ // DecodeBinary implements io.Serializable.
124
+ func (a * Archival ) DecodeBinary (br * io.BinReader ) {
125
+ var zero = br .ReadB () // Zero-length byte array as per Unknown.
126
+ if zero != 0 {
127
+ br .Err = errors .New ("archival capability with non-zero data" )
128
+ }
129
+ }
130
+
131
+ // EncodeBinary implements io.Serializable.
132
+ func (a * Archival ) EncodeBinary (bw * io.BinWriter ) {
133
+ bw .WriteB (0 )
134
+ }
135
+
118
136
// Unknown represents an unknown capability with some data. Other nodes can
119
137
// decode it even if they can't interpret it. This is not expected to be used
120
138
// for sending data directly (proper new types should be used), but it allows
Original file line number Diff line number Diff line change 4
4
"testing"
5
5
6
6
"github.com/nspcc-dev/neo-go/internal/testserdes"
7
+ "github.com/stretchr/testify/require"
7
8
)
8
9
9
10
func TestUnknownEncodeDecode (t * testing.T ) {
@@ -13,3 +14,14 @@ func TestUnknownEncodeDecode(t *testing.T) {
13
14
)
14
15
testserdes .EncodeDecodeBinary (t , & u , & ud )
15
16
}
17
+
18
+ func TestArchivalEncodeDecode (t * testing.T ) {
19
+ var (
20
+ a = Archival {}
21
+ ad Archival
22
+ )
23
+ testserdes .EncodeDecodeBinary (t , & a , & ad )
24
+
25
+ var bad = []byte {0x02 , 0x55 , 0xaa } // Two-byte var-encoded string.
26
+ require .Error (t , testserdes .DecodeBinary (bad , & ad ))
27
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ const (
10
10
WSServer Type = 0x02
11
11
// FullNode represents a node that has complete current state.
12
12
FullNode Type = 0x10
13
+ // ArchivalNode represents a node that stores full block history.
14
+ // These nodes can be used for P2P synchronization from genesis
15
+ // (FullNode can cut the tail and may not respond to requests for
16
+ // old (wrt MaxTraceableBlocks) blocks).
17
+ ArchivalNode Type = 0x11
13
18
14
19
// 0xf0-0xff are reserved for private experiments.
15
20
)
Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ func TestVersionEncodeDecode(t *testing.T) {
29
29
Port : wsPort ,
30
30
},
31
31
},
32
+ {
33
+ Type : capability .ArchivalNode ,
34
+ Data : & capability.Archival {},
35
+ },
32
36
{
33
37
Type : 0xff ,
34
38
Data : & capability.Unknown {},
You can’t perform that action at this time.
0 commit comments