]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/tx_test.go
Raise copyright years
[nncp.git] / src / tx_test.go
index 46e5b1e98b12bab0a5dc2049cac62b516a928b74..507bc8b94e7b5ba848b39e19aeb1ebcb7fb5dd37 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -19,25 +19,35 @@ package nncp
 
 import (
        "bytes"
+       "crypto/rand"
        "io"
        "io/ioutil"
        "os"
        "path"
-       "strings"
        "testing"
        "testing/quick"
 
        xdr "github.com/davecgh/go-xdr/xdr2"
-       "golang.org/x/crypto/blake2b"
 )
 
 func TestTx(t *testing.T) {
-       f := func(hops uint8, pathSrc, data string, nice, replyNice uint8, padSize int16) bool {
+       f := func(
+               hops uint8,
+               pathSrc string,
+               dataSize uint32,
+               nice, replyNice uint8,
+               minSize uint32,
+       ) bool {
+               dataSize %= 1 << 20
+               data := make([]byte, dataSize)
+               if _, err := io.ReadFull(rand.Reader, data); err != nil {
+                       panic(err)
+               }
+               minSize %= 1 << 20
                if len(pathSrc) > int(MaxPathSize) {
                        pathSrc = pathSrc[:MaxPathSize]
                }
                hops = hops % 4
-               hops = 1
                spool, err := ioutil.TempDir("", "testtx")
                if err != nil {
                        panic(err)
@@ -76,15 +86,17 @@ func TestTx(t *testing.T) {
                        nodeTgt.Via = append(nodeTgt.Via, node.Id)
                }
                pkt, err := NewPkt(PktTypeExec, replyNice, []byte(pathSrc))
-               src := strings.NewReader(data)
-               dstNode, err := ctx.Tx(
+               src := bytes.NewReader(data)
+               dstNode, _, err := ctx.Tx(
                        nodeTgt,
                        pkt,
                        123,
                        int64(src.Len()),
-                       int64(padSize),
+                       int64(minSize),
+                       MaxFileSize,
                        src,
                        "pktName",
+                       nil,
                )
                if err != nil {
                        return false
@@ -98,16 +110,22 @@ func TestTx(t *testing.T) {
                        return false
                }
                txJob := sentJobs[0]
-               defer txJob.Fd.Close()
+               fd, err := os.Open(txJob.Path)
+               if err != nil {
+                       panic(err)
+               }
+               defer fd.Close()
                var bufR bytes.Buffer
-               if _, err = io.Copy(&bufR, txJob.Fd); err != nil {
+               if _, err = io.Copy(&bufR, fd); err != nil {
                        panic(err)
                }
                var bufW bytes.Buffer
                vias := append(nodeTgt.Via, nodeTgt.Id)
                for i, hopId := range vias {
                        hopOur := privates[*hopId]
-                       foundNode, _, err := PktEncRead(hopOur, ctx.Neigh, &bufR, &bufW)
+                       _, foundNode, _, err := PktEncRead(
+                               hopOur, ctx.Neigh, &bufR, &bufW, true, nil,
+                       )
                        if err != nil {
                                return false
                        }
@@ -137,7 +155,7 @@ func TestTx(t *testing.T) {
                                if pkt.Type != PktTypeTrns {
                                        return false
                                }
-                               if bytes.Compare(pkt.Path[:blake2b.Size256], vias[i+1][:]) != 0 {
+                               if bytes.Compare(pkt.Path[:MTHSize], vias[i+1][:]) != 0 {
                                        return false
                                }
                        }