2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
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.
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.
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/>.
26 "github.com/davecgh/go-xdr/xdr2"
29 func TestPktEncWrite(t *testing.T) {
30 nodeOur, err := NewNodeGenerate()
34 nodeTheir, err := NewNodeGenerate()
38 f := func(path string, pathSize uint8, data [1 << 16]byte, size, padSize uint16) bool {
39 dataR := bytes.NewReader(data[:])
41 if len(path) > int(pathSize) {
42 path = path[:int(pathSize)]
44 pkt, err := NewPkt(PktTypeFile, 123, []byte(path))
62 if _, err = xdr.Unmarshal(&ct, &pktEnc); err != nil {
65 if *pktEnc.Sender != *nodeOur.Id {
70 if err := quick.Check(f, nil); err != nil {
75 func TestPktEncRead(t *testing.T) {
76 node1, err := NewNodeGenerate()
80 node2, err := NewNodeGenerate()
84 f := func(path string, pathSize uint8, data [1 << 16]byte, size, padSize uint16, junk []byte) bool {
85 dataR := bytes.NewReader(data[:])
87 if len(path) > int(pathSize) {
88 path = path[:int(pathSize)]
90 pkt, err := NewPkt(PktTypeFile, 123, []byte(path))
109 nodes := make(map[NodeId]*Node)
110 nodes[*node1.Id] = node1.Their()
111 node, sizeGot, err := PktEncRead(node2, nodes, &ct, &pt)
115 if *node.Id != *node1.Id {
118 if sizeGot != int64(size) {
121 var pktBuf bytes.Buffer
122 xdr.Marshal(&pktBuf, &pkt)
123 return bytes.Compare(pt.Bytes(), append(pktBuf.Bytes(), data[:int(size)]...)) == 0
125 if err := quick.Check(f, nil); err != nil {