X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fnncp%2Ftoss_test.go;h=48149c49f2d807fec138143d5be6f325206aba30;hb=dd92823db3d72fb21a4c712a7fb052dce16443dd;hp=a5687a72c0a18b5663b432fd06ac019f56c760ac;hpb=535d386941ae38abbaa8e1a6df69a5e739058011;p=nncp.git diff --git a/src/cypherpunks.ru/nncp/toss_test.go b/src/cypherpunks.ru/nncp/toss_test.go index a5687a7..48149c4 100644 --- a/src/cypherpunks.ru/nncp/toss_test.go +++ b/src/cypherpunks.ru/nncp/toss_test.go @@ -1,11 +1,10 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2017 Sergey Matveev +Copyright (C) 2016-2019 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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. +the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -51,8 +50,9 @@ func dirFiles(path string) []string { return names } -func TestTossEmail(t *testing.T) { - f := func(recipients [16]uint8) bool { +func TestTossExec(t *testing.T) { + f := func(replyNice uint8, handleRaw uint32, recipients [16]uint8) bool { + handle := strconv.Itoa(int(handleRaw)) for i, recipient := range recipients { recipients[i] = recipient % 8 } @@ -90,11 +90,13 @@ func TestTossEmail(t *testing.T) { ctx.Neigh[*our.Id] = our.Their() } for _, recipient := range recipients { - if err := ctx.TxMail( + if err := ctx.TxExec( ctx.Neigh[*privates[recipient].Id], - DefaultNiceMail, - "recipient", - []byte{123}, + DefaultNiceExec, + replyNice, + handle, + []string{"arg0", "arg1"}, + []byte("BODY\n"), 1<<15, ); err != nil { t.Error(err) @@ -108,20 +110,25 @@ func TestTossEmail(t *testing.T) { if len(dirFiles(rxPath)) == 0 { continue } - ctx.Toss(ctx.Self.Id, DefaultNiceMail-1, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceExec-1, false, false, false, false, false, false) if len(dirFiles(rxPath)) == 0 { return false } - ctx.Neigh[*nodeOur.Id].Sendmail = []string{"/bin/sh", "-c", "false"} - ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, 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) if len(dirFiles(rxPath)) == 0 { return false } - ctx.Neigh[*nodeOur.Id].Sendmail = []string{ + ctx.Neigh[*nodeOur.Id].Exec[handle] = []string{ "/bin/sh", "-c", - fmt.Sprintf("cat >> %s", filepath.Join(spool, "mbox")), + fmt.Sprintf( + "echo $NNCP_NICE $0 $1 >> %s ; cat >> %s", + filepath.Join(spool, "mbox"), + filepath.Join(spool, "mbox"), + ), } - ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceExec, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false } @@ -132,7 +139,11 @@ func TestTossEmail(t *testing.T) { } expected := make([]byte, 0, 16) for i := 0; i < 16; i++ { - expected = append(expected, 123) + expected = append( + expected, + []byte(fmt.Sprintf("%d arg0 arg1\n", replyNice))..., + ) + expected = append(expected, []byte("BODY\n")...) } return bytes.Compare(mbox, expected) == 0 } @@ -195,12 +206,12 @@ 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) + ctx.Toss(ctx.Self.Id, DefaultNiceFile, 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) + ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false } @@ -270,7 +281,7 @@ 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) + ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) expected := make(map[string]struct{}) expected["samefile"] = struct{}{} for i := 0; i < files-1; i++ { @@ -293,7 +304,7 @@ func TestTossFileSameName(t *testing.T) { } func TestTossFreq(t *testing.T) { - f := func(fileSizes []uint8) bool { + f := func(fileSizes []uint8, replyNice uint8) bool { if len(fileSizes) == 0 { return true } @@ -328,6 +339,7 @@ func TestTossFreq(t *testing.T) { if err := ctx.TxFreq( ctx.Neigh[*nodeOur.Id], DefaultNiceFreq, + replyNice, fileName, fileName, 1<<15, @@ -340,12 +352,12 @@ 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) + ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 { return false } ctx.Neigh[*nodeOur.Id].Freq = &spool - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 { return false } @@ -358,7 +370,7 @@ func TestTossFreq(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) if len(dirFiles(txPath)) == 0 || len(dirFiles(rxPath)) != 0 { return false } @@ -374,6 +386,9 @@ func TestTossFreq(t *testing.T) { t.Error(err) return false } + if pkt.Nice != replyNice { + return false + } dst := string(pkt.Path[:int(pkt.PathLen)]) if bytes.Compare(buf.Bytes(), files[dst]) != 0 { return false @@ -426,7 +441,7 @@ func TestTossTrns(t *testing.T) { os.MkdirAll(txPath, os.FileMode(0700)) for _, data := range datum { pktTrans := Pkt{ - Magic: MagicNNCPPv1, + Magic: MagicNNCPPv2, Type: PktTypeTrns, PathLen: blake2b.Size256, Path: new([MaxPathSize]byte), @@ -455,7 +470,7 @@ func TestTossTrns(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, 123, false, false) + ctx.Toss(ctx.Self.Id, 123, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false } @@ -467,7 +482,6 @@ func TestTossTrns(t *testing.T) { for k, data := range datum { if bytes.Compare(dataRead, data) == 0 { delete(datum, k) - break } } }