2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2020 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, version 3 of the License.
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.
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/>.
25 xdr "github.com/davecgh/go-xdr/xdr2"
28 func TestPktEncWrite(t *testing.T) {
29 nodeOur, err := NewNodeGenerate()
33 nodeTheir, err := NewNodeGenerate()
37 f := func(path string, pathSize uint8, data [1 << 16]byte, size, padSize uint16) bool {
38 dataR := bytes.NewReader(data[:])
40 if len(path) > int(pathSize) {
41 path = path[:int(pathSize)]
43 pkt, err := NewPkt(PktTypeFile, 123, []byte(path))
61 if _, err = xdr.Unmarshal(&ct, &pktEnc); err != nil {
64 if *pktEnc.Sender != *nodeOur.Id {
69 if err := quick.Check(f, nil); err != nil {
74 func TestPktEncRead(t *testing.T) {
75 node1, err := NewNodeGenerate()
79 node2, err := NewNodeGenerate()
89 dataR := bytes.NewReader(data[:])
91 if len(path) > int(pathSize) {
92 path = path[:int(pathSize)]
94 pkt, err := NewPkt(PktTypeFile, 123, []byte(path))
113 nodes := make(map[NodeId]*Node)
114 nodes[*node1.Id] = node1.Their()
115 node, sizeGot, err := PktEncRead(node2, nodes, &ct, &pt)
119 if *node.Id != *node1.Id {
122 if sizeGot != sizeWithTags(PktOverhead+int64(size)) {
125 var pktBuf bytes.Buffer
126 xdr.Marshal(&pktBuf, &pkt)
127 return bytes.Compare(pt.Bytes(), append(pktBuf.Bytes(), data[:int(size)]...)) == 0
129 if err := quick.Check(f, nil); err != nil {