]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/toss_test.go
Replace Twofish/HKDF with ChaCha20/BLAKE2X for speed and simplicity
[nncp.git] / src / cypherpunks.ru / nncp / toss_test.go
index f0038d8ac38493cd32de83ffea2f59fc4612792e..a5687a72c0a18b5663b432fd06ac019f56c760ac 100644 (file)
@@ -63,11 +63,13 @@ func TestTossEmail(t *testing.T) {
                defer os.RemoveAll(spool)
                nodeOur, err := NewNodeGenerate()
                if err != nil {
-                       panic(err)
+                       t.Error(err)
+                       return false
                }
                ctx := Ctx{
                        Spool:   spool,
                        Self:    nodeOur,
+                       SelfId:  nodeOur.Id,
                        Neigh:   make(map[NodeId]*Node),
                        Alias:   make(map[string]*NodeId),
                        LogPath: filepath.Join(spool, "log.log"),
@@ -81,7 +83,8 @@ func TestTossEmail(t *testing.T) {
                        }
                        our, err := NewNodeGenerate()
                        if err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                        privates[recipient] = our
                        ctx.Neigh[*our.Id] = our.Their()
@@ -94,7 +97,8 @@ func TestTossEmail(t *testing.T) {
                                []byte{123},
                                1<<15,
                        ); err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                }
                for _, recipient := range recipients {
@@ -104,12 +108,12 @@ func TestTossEmail(t *testing.T) {
                        if len(dirFiles(rxPath)) == 0 {
                                continue
                        }
-                       ctx.Toss(ctx.Self.Id, DefaultNiceMail-1, false)
+                       ctx.Toss(ctx.Self.Id, DefaultNiceMail-1, 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)
+                       ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false)
                        if len(dirFiles(rxPath)) == 0 {
                                return false
                        }
@@ -117,7 +121,7 @@ func TestTossEmail(t *testing.T) {
                                "/bin/sh", "-c",
                                fmt.Sprintf("cat >> %s", filepath.Join(spool, "mbox")),
                        }
-                       ctx.Toss(ctx.Self.Id, DefaultNiceMail, false)
+                       ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false)
                        if len(dirFiles(rxPath)) != 0 {
                                return false
                        }
@@ -157,11 +161,13 @@ func TestTossFile(t *testing.T) {
                defer os.RemoveAll(spool)
                nodeOur, err := NewNodeGenerate()
                if err != nil {
-                       panic(err)
+                       t.Error(err)
+                       return false
                }
                ctx := Ctx{
                        Spool:   spool,
                        Self:    nodeOur,
+                       SelfId:  nodeOur.Id,
                        Neigh:   make(map[NodeId]*Node),
                        Alias:   make(map[string]*NodeId),
                        LogPath: filepath.Join(spool, "log.log"),
@@ -183,17 +189,18 @@ func TestTossFile(t *testing.T) {
                                fileName,
                                1<<15,
                        ); err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                }
                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)
+               ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false)
                if len(dirFiles(rxPath)) == 0 {
                        return false
                }
                ctx.Neigh[*nodeOur.Id].Incoming = &incomingPath
-               ctx.Toss(ctx.Self.Id, DefaultNiceFile, false)
+               ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false)
                if len(dirFiles(rxPath)) != 0 {
                        return false
                }
@@ -225,11 +232,13 @@ func TestTossFileSameName(t *testing.T) {
                defer os.RemoveAll(spool)
                nodeOur, err := NewNodeGenerate()
                if err != nil {
-                       panic(err)
+                       t.Error(err)
+                       return false
                }
                ctx := Ctx{
                        Spool:   spool,
                        Self:    nodeOur,
+                       SelfId:  nodeOur.Id,
                        Neigh:   make(map[NodeId]*Node),
                        Alias:   make(map[string]*NodeId),
                        LogPath: filepath.Join(spool, "log.log"),
@@ -242,7 +251,8 @@ func TestTossFileSameName(t *testing.T) {
                        []byte("doesnotmatter"),
                        os.FileMode(0600),
                ); err != nil {
-                       panic(err)
+                       t.Error(err)
+                       return false
                }
                incomingPath := filepath.Join(spool, "incoming")
                for i := 0; i < files; i++ {
@@ -253,13 +263,14 @@ func TestTossFileSameName(t *testing.T) {
                                "samefile",
                                1<<15,
                        ); err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                }
                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)
+               ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false)
                expected := make(map[string]struct{})
                expected["samefile"] = struct{}{}
                for i := 0; i < files-1; i++ {
@@ -293,11 +304,13 @@ func TestTossFreq(t *testing.T) {
                defer os.RemoveAll(spool)
                nodeOur, err := NewNodeGenerate()
                if err != nil {
-                       panic(err)
+                       t.Error(err)
+                       return false
                }
                ctx := Ctx{
                        Spool:   spool,
                        Self:    nodeOur,
+                       SelfId:  nodeOur.Id,
                        Neigh:   make(map[NodeId]*Node),
                        Alias:   make(map[string]*NodeId),
                        LogPath: filepath.Join(spool, "log.log"),
@@ -319,19 +332,20 @@ func TestTossFreq(t *testing.T) {
                                fileName,
                                1<<15,
                        ); err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                }
                rxPath := filepath.Join(spool, ctx.Self.Id.String(), string(TRx))
                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)
+               ctx.Toss(ctx.Self.Id, DefaultNiceFreq, 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)
+               ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false)
                if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 {
                        return false
                }
@@ -344,7 +358,7 @@ func TestTossFreq(t *testing.T) {
                                panic(err)
                        }
                }
-               ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false)
+               ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false)
                if len(dirFiles(txPath)) == 0 || len(dirFiles(rxPath)) != 0 {
                        return false
                }
@@ -352,11 +366,13 @@ func TestTossFreq(t *testing.T) {
                        var buf bytes.Buffer
                        _, _, err := PktEncRead(ctx.Self, ctx.Neigh, job.Fd, &buf)
                        if err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                        var pkt Pkt
                        if _, err = xdr.Unmarshal(&buf, &pkt); err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                        dst := string(pkt.Path[:int(pkt.PathLen)])
                        if bytes.Compare(buf.Bytes(), files[dst]) != 0 {
@@ -391,11 +407,13 @@ func TestTossTrns(t *testing.T) {
                defer os.RemoveAll(spool)
                nodeOur, err := NewNodeGenerate()
                if err != nil {
-                       panic(err)
+                       t.Error(err)
+                       return false
                }
                ctx := Ctx{
                        Spool:   spool,
                        Self:    nodeOur,
+                       SelfId:  nodeOur.Id,
                        Neigh:   make(map[NodeId]*Node),
                        Alias:   make(map[string]*NodeId),
                        LogPath: filepath.Join(spool, "log.log"),
@@ -425,7 +443,8 @@ func TestTossTrns(t *testing.T) {
                                bytes.NewReader(data),
                                &dst,
                        ); err != nil {
-                               panic(err)
+                               t.Error(err)
+                               return false
                        }
                        checksum := blake2b.Sum256(dst.Bytes())
                        if err := ioutil.WriteFile(
@@ -436,7 +455,7 @@ func TestTossTrns(t *testing.T) {
                                panic(err)
                        }
                }
-               ctx.Toss(ctx.Self.Id, 123, false)
+               ctx.Toss(ctx.Self.Id, 123, false, false)
                if len(dirFiles(rxPath)) != 0 {
                        return false
                }