X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Ftoss_test.go;h=000653d7be96cf60c8b0fd4a09961836bea880d8;hb=2e59e1d8da61bc5dee797d351e50e8ed114aa4c7;hp=a66f43ba52ae2ea1a761ff663dad3e5aed3001e6;hpb=09afcade2662992be6a24f465668c5ea499ac8bb;p=nncp.git diff --git a/src/toss_test.go b/src/toss_test.go index a66f43b..000653d 100644 --- a/src/toss_test.go +++ b/src/toss_test.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev 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 @@ -97,9 +97,9 @@ func TestTossExec(t *testing.T) { handle, []string{"arg0", "arg1"}, strings.NewReader("BODY\n"), - 1<<15, - false, + 1<<15, MaxFileSize, false, + nil, ); err != nil { t.Error(err) return false @@ -112,13 +112,15 @@ func TestTossExec(t *testing.T) { if len(dirFiles(rxPath)) == 0 { continue } - ctx.Toss(ctx.Self.Id, DefaultNiceExec-1, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec-1, + false, false, false, false, false, false, false, false) if len(dirFiles(rxPath)) == 0 { return false } ctx.Neigh[*nodeOur.Id].Exec = make(map[string][]string) ctx.Neigh[*nodeOur.Id].Exec[handle] = []string{"/bin/sh", "-c", "false"} - ctx.Toss(ctx.Self.Id, DefaultNiceExec, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec, + false, false, false, false, false, false, false, false) if len(dirFiles(rxPath)) == 0 { return false } @@ -130,7 +132,8 @@ func TestTossExec(t *testing.T) { filepath.Join(spool, "mbox"), ), } - ctx.Toss(ctx.Self.Id, DefaultNiceExec, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceExec, + false, false, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false } @@ -161,6 +164,10 @@ func TestTossFile(t *testing.T) { } files := make(map[string][]byte) for i, fileSize := range fileSizes { + if fileSize == 0 { + // to prevent chunked send + fileSize++ + } data := make([]byte, fileSize) if _, err := io.ReadFull(rand.Reader, data); err != nil { panic(err) @@ -204,6 +211,7 @@ func TestTossFile(t *testing.T) { MaxFileSize, 1<<15, MaxFileSize, + nil, ); err != nil { t.Error(err) return false @@ -211,12 +219,16 @@ func TestTossFile(t *testing.T) { } rxPath := filepath.Join(spool, ctx.Self.Id.String(), string(TRx)) os.Rename(filepath.Join(spool, ctx.Self.Id.String(), string(TTx)), rxPath) - ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile, + false, false, false, false, false, false, false, false) if len(dirFiles(rxPath)) == 0 { return false } ctx.Neigh[*nodeOur.Id].Incoming = &incomingPath - ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) + if ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile, + false, false, false, false, false, false, false, false) { + return false + } if len(dirFiles(rxPath)) != 0 { return false } @@ -281,6 +293,7 @@ func TestTossFileSameName(t *testing.T) { MaxFileSize, 1<<15, MaxFileSize, + nil, ); err != nil { t.Error(err) return false @@ -289,7 +302,8 @@ func TestTossFileSameName(t *testing.T) { rxPath := filepath.Join(spool, ctx.Self.Id.String(), string(TRx)) os.Rename(filepath.Join(spool, ctx.Self.Id.String(), string(TTx)), rxPath) ctx.Neigh[*nodeOur.Id].Incoming = &incomingPath - ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFile, + false, false, false, false, false, false, false, false) expected := make(map[string]struct{}) expected["samefile"] = struct{}{} for i := 0; i < files-1; i++ { @@ -338,6 +352,10 @@ func TestTossFreq(t *testing.T) { ctx.Neigh[*nodeOur.Id] = nodeOur.Their() files := make(map[string][]byte) for i, fileSize := range fileSizes { + if fileSize == 0 { + // to prevent chunked send + fileSize++ + } fileData := make([]byte, fileSize) if _, err := io.ReadFull(rand.Reader, fileData); err != nil { panic(err) @@ -360,12 +378,14 @@ func TestTossFreq(t *testing.T) { txPath := filepath.Join(spool, ctx.Self.Id.String(), string(TTx)) os.Rename(txPath, rxPath) os.MkdirAll(txPath, os.FileMode(0700)) - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFreq, + false, false, false, false, false, false, false, false) if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 { return false } ctx.Neigh[*nodeOur.Id].FreqPath = &spool - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFreq, + false, false, false, false, false, false, false, false) if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 { return false } @@ -378,7 +398,8 @@ func TestTossFreq(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, DefaultNiceFreq, + false, false, false, false, false, false, false, false) if len(dirFiles(txPath)) == 0 || len(dirFiles(rxPath)) != 0 { return false } @@ -389,7 +410,7 @@ func TestTossFreq(t *testing.T) { t.Error(err) return false } - _, _, err = PktEncRead(ctx.Self, ctx.Neigh, fd, &buf) + _, _, _, err = PktEncRead(ctx.Self, ctx.Neigh, fd, &buf, true, nil) if err != nil { t.Error(err) return false @@ -460,13 +481,12 @@ func TestTossTrns(t *testing.T) { } copy(pktTrans.Path[:], nodeOur.Id[:]) var dst bytes.Buffer - if _, err := PktEncWrite( + if _, _, err := PktEncWrite( ctx.Self, ctx.Neigh[*nodeOur.Id], &pktTrans, 123, - int64(len(data)), - 0, + 0, MaxFileSize, 1, bytes.NewReader(data), &dst, ); err != nil { @@ -483,7 +503,8 @@ func TestTossTrns(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, 123, false, false, false, false, false, false) + ctx.Toss(ctx.Self.Id, TRx, 123, + false, false, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false }