]> Cypherpunks.ru repositories - nncp.git/commitdiff
-minsize option
authorSergey Matveev <stargrave@stargrave.org>
Fri, 13 Jan 2017 21:14:45 +0000 (00:14 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 13 Jan 2017 21:14:45 +0000 (00:14 +0300)
doc/cmds.texi
src/cypherpunks.ru/nncp/cmd/nncp-file/main.go
src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go
src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go
src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go
src/cypherpunks.ru/nncp/pkt.go
src/cypherpunks.ru/nncp/pkt_test.go
src/cypherpunks.ru/nncp/toss.go
src/cypherpunks.ru/nncp/toss_test.go
src/cypherpunks.ru/nncp/tx.go
src/cypherpunks.ru/nncp/tx_test.go

index e3c1fd2b1d78039fdb3ef7095ec006dde5229470..51944ac655a4ffaf737366f478410f638af0883a 100644 (file)
@@ -9,6 +9,10 @@ Nearly all commands have the following common options:
     environment variable.
 @item -debug
     Print debug messages. Normally this option should not be used.
+@item -minsize
+    Minimal required resulting packet size. For example if you send 2
+    KiB file and set @option{-minsize 4096}, then resulting packet will
+    be 4 KiB (containing file itself and some junk).
 @item -nice
     Set desired outgoing packet niceness level. 1-255 values are
     allowed. Higher value means lower priority. In some commands that
index c17d5f339ce8d9d0845dd36847a7cdff44ca3987..f6772863720c7a096f5ca8c02c852a402775f207 100644 (file)
@@ -41,6 +41,7 @@ func main() {
        var (
                cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
                niceRaw  = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
+               minSize  = flag.Uint64("minsize", 0, "Minimal required resulting packet size")
                quiet    = flag.Bool("quiet", false, "Print only errors")
                debug    = flag.Bool("debug", false, "Print debug messages")
                version  = flag.Bool("version", false, "Print version information")
@@ -86,7 +87,7 @@ func main() {
                log.Fatalln("Invalid NODE specified:", err)
        }
 
-       if err = ctx.TxFile(node, nice, flag.Arg(0), splitted[1]); err != nil {
+       if err = ctx.TxFile(node, nice, flag.Arg(0), splitted[1], int64(*minSize)); err != nil {
                log.Fatalln(err)
        }
 }
index ebfa82d3463ef0cafe5b725fcaf02c0f55dd71ab..ada8edbba2854725af5f8b226ed7d96b52f62743 100644 (file)
@@ -41,6 +41,7 @@ func main() {
        var (
                cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
                niceRaw  = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
+               minSize  = flag.Uint64("minsize", 0, "Minimal required resulting packet size")
                quiet    = flag.Bool("quiet", false, "Print only errors")
                debug    = flag.Bool("debug", false, "Print debug messages")
                version  = flag.Bool("version", false, "Print version information")
@@ -86,7 +87,7 @@ func main() {
                log.Fatalln("Invalid NODE specified:", err)
        }
 
-       if err = ctx.TxFreq(node, nice, splitted[1], flag.Arg(1)); err != nil {
+       if err = ctx.TxFreq(node, nice, splitted[1], flag.Arg(1), int64(*minSize)); err != nil {
                log.Fatalln(err)
        }
 }
index ab0d0ad1563db273ed39e9f4e04be2b4106a212b..223aea520e5d848b65d3b305ca6f4cf74cf4bd25 100644 (file)
@@ -36,13 +36,13 @@ func usage() {
        fmt.Fprintln(os.Stderr, "nncp-mail -- send email\n")
        fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE USER ...\nOptions:\n", os.Args[0])
        flag.PrintDefaults()
-       fmt.Fprintln(os.Stderr, "Email body is read from stdin.")
 }
 
 func main() {
        var (
                cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
                niceRaw  = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
+               minSize  = flag.Uint64("minsize", 0, "Minimal required resulting packet size")
                quiet    = flag.Bool("quiet", false, "Print only errors")
                debug    = flag.Bool("debug", false, "Print debug messages")
                version  = flag.Bool("version", false, "Print version information")
@@ -88,7 +88,7 @@ func main() {
                log.Fatalln("Can not read mail body from stdin:", err)
        }
 
-       if err = ctx.TxMail(node, nice, strings.Join(flag.Args()[1:], " "), body); err != nil {
+       if err = ctx.TxMail(node, nice, strings.Join(flag.Args()[1:], " "), body, int64(*minSize)); err != nil {
                log.Fatalln(err)
        }
 }
index 222750df7337bb4d7844f839cf8559b7801280ee..535c7d25ae7c670ea621f4d23b12ac074e3dddc5 100644 (file)
@@ -31,7 +31,6 @@ import (
 
        "cypherpunks.ru/nncp"
        "github.com/davecgh/go-xdr/xdr2"
-       "github.com/dustin/go-humanize"
        "golang.org/x/crypto/blake2b"
 )
 
@@ -62,7 +61,7 @@ func main() {
        }
 
        var err error
-       beginning := make([]byte, nncp.PktOverhead - 8 - 2*blake2b.Size256)
+       beginning := make([]byte, nncp.PktOverhead-8-2*blake2b.Size256)
        if _, err = io.ReadFull(os.Stdin, beginning); err != nil {
                log.Fatalln("Not enough data to read")
        }
@@ -113,7 +112,7 @@ func main() {
                                log.Fatalln("Can not parse config:", err)
                        }
                        bufW := bufio.NewWriter(os.Stdout)
-                       if _, err = nncp.PktEncRead(
+                       if _, _, err = nncp.PktEncRead(
                                ctx.Self,
                                ctx.Neigh,
                                io.MultiReader(
index 2802085330212d39693e7ea5e97523db1887aed8..ce85ec2e853581358bd0ea1fc3671c72f61009f6 100644 (file)
@@ -138,7 +138,16 @@ func blake256() hash.Hash {
        return h
 }
 
-func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size int64, data io.Reader, out io.Writer) error {
+type DevZero struct{}
+
+func (d DevZero) Read(b []byte) (n int, err error) {
+       for n = 0; n < len(b); n++ {
+               b[n] = 0
+       }
+       return
+}
+
+func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size, padSize int64, data io.Reader, out io.Writer) error {
        pubEph, prvEph, err := box.GenerateKey(rand.Reader)
        if err != nil {
                return err
@@ -174,15 +183,6 @@ func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size int64, da
        curve25519.ScalarMult(sharedKey, prvEph, their.ExchPub)
        kdf := hkdf.New(blake256, sharedKey[:], nil, MagicNNCPEv1[:])
 
-       // Derive keys
-       keyEnc4Size := make([]byte, 32)
-       if _, err = io.ReadFull(kdf, keyEnc4Size); err != nil {
-               return err
-       }
-       keyAuth4Size := make([]byte, 64)
-       if _, err = io.ReadFull(kdf, keyAuth4Size); err != nil {
-               return err
-       }
        keyEnc := make([]byte, 32)
        if _, err = io.ReadFull(kdf, keyEnc); err != nil {
                return err
@@ -192,16 +192,6 @@ func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size int64, da
                return err
        }
 
-       // Initialize ciphers and MACs
-       ciph4Size, err := twofish.NewCipher(keyEnc4Size)
-       if err != nil {
-               return err
-       }
-       ctr4Size := cipher.NewCTR(ciph4Size, make([]byte, twofish.BlockSize))
-       mac4Size, err := blake2b.New256(keyAuth4Size)
-       if err != nil {
-               return err
-       }
        ciph, err := twofish.NewCipher(keyEnc)
        if err != nil {
                return err
@@ -212,22 +202,56 @@ func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size int64, da
                return err
        }
 
-       mw := io.MultiWriter(out, mac4Size)
-       ae := &cipher.StreamWriter{S: ctr4Size, W: mw}
+       mw := io.MultiWriter(out, mac)
+       ae := &cipher.StreamWriter{S: ctr, W: mw}
        usize := uint64(size)
        if _, err = xdr.Marshal(ae, &usize); err != nil {
                return err
        }
-       out.Write(mac4Size.Sum(nil))
+       ae.Close()
+       out.Write(mac.Sum(nil))
+
+       if _, err = io.ReadFull(kdf, keyEnc); err != nil {
+               return err
+       }
+       if _, err = io.ReadFull(kdf, keyAuth); err != nil {
+               return err
+       }
+
+       ciph, err = twofish.NewCipher(keyEnc)
+       if err != nil {
+               return err
+       }
+       ctr = cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
+       mac, err = blake2b.New256(keyAuth)
+       if err != nil {
+               return err
+       }
 
        mw = io.MultiWriter(out, mac)
        ae = &cipher.StreamWriter{S: ctr, W: mw}
        ae.Write(pktBuf.Bytes())
-       if _, err = io.CopyN(ae, data, int64(size)); err != nil {
+       if _, err = io.CopyN(ae, data, size); err != nil {
                return err
        }
        ae.Close()
        out.Write(mac.Sum(nil))
+
+       if padSize > 0 {
+               if _, err = io.ReadFull(kdf, keyEnc); err != nil {
+                       return err
+               }
+               ciph, err = twofish.NewCipher(keyEnc)
+               if err != nil {
+                       return err
+               }
+               ctr = cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
+               ae = &cipher.StreamWriter{S: ctr, W: out}
+               if _, err = io.CopyN(ae, DevZero{}, padSize); err != nil {
+                       return err
+               }
+               ae.Close()
+       }
        return nil
 }
 
@@ -246,92 +270,91 @@ func TbsVerify(our *NodeOur, their *Node, pktEnc *PktEnc) (bool, error) {
        return ed25519.Verify(their.SignPub, tbsBuf.Bytes(), pktEnc.Sign[:]), nil
 }
 
-func PktEncRead(our *NodeOur, nodes map[NodeId]*Node, data io.Reader, out io.Writer) (*Node, error) {
+func PktEncRead(our *NodeOur, nodes map[NodeId]*Node, data io.Reader, out io.Writer) (*Node, int64, error) {
        var pktEnc PktEnc
        _, err := xdr.Unmarshal(data, &pktEnc)
        if err != nil {
-               return nil, err
+               return nil, 0, err
        }
        if pktEnc.Magic != MagicNNCPEv1 {
-               return nil, BadMagic
+               return nil, 0, BadMagic
        }
        their, known := nodes[*pktEnc.Sender]
        if !known {
-               return nil, errors.New("Unknown sender")
+               return nil, 0, errors.New("Unknown sender")
        }
        verified, err := TbsVerify(our, their, &pktEnc)
        if err != nil {
-               return nil, err
+               return nil, 0, err
        }
        if !verified {
-               return their, errors.New("Invalid signature")
+               return their, 0, errors.New("Invalid signature")
        }
        sharedKey := new([32]byte)
        curve25519.ScalarMult(sharedKey, our.ExchPrv, pktEnc.ExchPub)
        kdf := hkdf.New(blake256, sharedKey[:], nil, MagicNNCPEv1[:])
 
-       // Derive keys
-       keyEnc4Size := make([]byte, 32)
-       if _, err = io.ReadFull(kdf, keyEnc4Size); err != nil {
-               return their, err
-       }
-       keyAuth4Size := make([]byte, 64)
-       if _, err = io.ReadFull(kdf, keyAuth4Size); err != nil {
-               return their, err
-       }
        keyEnc := make([]byte, 32)
        if _, err = io.ReadFull(kdf, keyEnc); err != nil {
-               return their, err
+               return their, 0, err
        }
        keyAuth := make([]byte, 64)
        if _, err = io.ReadFull(kdf, keyAuth); err != nil {
-               return their, err
+               return their, 0, err
        }
 
-       // Initialize ciphers and MACs
-       ciph4Size, err := twofish.NewCipher(keyEnc4Size)
-       if err != nil {
-               return their, err
-       }
-       ctr4Size := cipher.NewCTR(ciph4Size, make([]byte, twofish.BlockSize))
-       mac4Size, err := blake2b.New256(keyAuth4Size)
-       if err != nil {
-               return their, err
-       }
        ciph, err := twofish.NewCipher(keyEnc)
        if err != nil {
-               return their, err
+               return their, 0, err
        }
        ctr := cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
        mac, err := blake2b.New256(keyAuth)
        if err != nil {
-               return their, err
+               return their, 0, err
        }
 
-       tr := io.TeeReader(data, mac4Size)
-       ae := &cipher.StreamReader{S: ctr4Size, R: tr}
+       tr := io.TeeReader(data, mac)
+       ae := &cipher.StreamReader{S: ctr, R: tr}
        var usize uint64
        if _, err = xdr.Unmarshal(ae, &usize); err != nil {
-               return their, err
+               return their, 0, err
        }
        tag := make([]byte, blake2b.Size256)
        if _, err = io.ReadFull(data, tag); err != nil {
-               return their, err
+               return their, 0, err
+       }
+       if subtle.ConstantTimeCompare(mac.Sum(nil), tag) != 1 {
+               return their, 0, errors.New("Unauthenticated size")
+       }
+       size := int64(usize)
+
+       if _, err = io.ReadFull(kdf, keyEnc); err != nil {
+               return their, size, err
        }
-       if subtle.ConstantTimeCompare(mac4Size.Sum(nil), tag) != 1 {
-               return their, errors.New("Unauthenticated payload")
+       if _, err = io.ReadFull(kdf, keyAuth); err != nil {
+               return their, size, err
+       }
+
+       ciph, err = twofish.NewCipher(keyEnc)
+       if err != nil {
+               return their, size, err
+       }
+       ctr = cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
+       mac, err = blake2b.New256(keyAuth)
+       if err != nil {
+               return their, size, err
        }
 
        tr = io.TeeReader(data, mac)
        ae = &cipher.StreamReader{S: ctr, R: tr}
-       if _, err = io.CopyN(out, ae, PktOverhead+int64(usize)-8-blake2b.Size256-blake2b.Size256); err != nil {
-               return their, err
+       if _, err = io.CopyN(out, ae, PktOverhead+size-8-blake2b.Size256-blake2b.Size256); err != nil {
+               return their, size, err
        }
        if _, err = io.ReadFull(data, tag); err != nil {
-               return their, err
+               return their, size, err
        }
        if subtle.ConstantTimeCompare(mac.Sum(nil), tag) != 1 {
-               return their, errors.New("Unauthenticated payload")
+               return their, size, errors.New("Unauthenticated payload")
        }
-       return their, nil
+       return their, size, nil
 }
index ec58785d298018edf2c3681a72a1e9c9ca08d039..15bff169132f01aa11eeb572f7aaa21c23ae7908 100644 (file)
@@ -35,7 +35,7 @@ func TestPktEncWrite(t *testing.T) {
        if err != nil {
                panic(err)
        }
-       f := func(path string, pathSize uint8, data [1 << 16]byte, size uint16) bool {
+       f := func(path string, pathSize uint8, data [1 << 16]byte, size, padSize uint16) bool {
                dataR := bytes.NewReader(data[:])
                var ct bytes.Buffer
                if len(path) > int(pathSize) {
@@ -45,7 +45,16 @@ func TestPktEncWrite(t *testing.T) {
                if err != nil {
                        panic(err)
                }
-               err = PktEncWrite(nodeOur, nodeTheir.Their(), pkt, 123, int64(size), dataR, &ct)
+               err = PktEncWrite(
+                       nodeOur,
+                       nodeTheir.Their(),
+                       pkt,
+                       123,
+                       int64(size),
+                       int64(padSize),
+                       dataR,
+                       &ct,
+               )
                if err != nil {
                        return false
                }
@@ -72,7 +81,7 @@ func TestPktEncRead(t *testing.T) {
        if err != nil {
                panic(err)
        }
-       f := func(path string, pathSize uint8, data [1 << 16]byte, size uint16, junk []byte) bool {
+       f := func(path string, pathSize uint8, data [1 << 16]byte, size, padSize uint16, junk []byte) bool {
                dataR := bytes.NewReader(data[:])
                var ct bytes.Buffer
                if len(path) > int(pathSize) {
@@ -82,7 +91,16 @@ func TestPktEncRead(t *testing.T) {
                if err != nil {
                        panic(err)
                }
-               err = PktEncWrite(node1, node2.Their(), pkt, 123, int64(size), dataR, &ct)
+               err = PktEncWrite(
+                       node1,
+                       node2.Their(),
+                       pkt,
+                       123,
+                       int64(size),
+                       int64(padSize),
+                       dataR,
+                       &ct,
+               )
                if err != nil {
                        return false
                }
@@ -90,13 +108,16 @@ func TestPktEncRead(t *testing.T) {
                var pt bytes.Buffer
                nodes := make(map[NodeId]*Node)
                nodes[*node1.Id] = node1.Their()
-               node, err := PktEncRead(node2, nodes, &ct, &pt)
+               node, sizeGot, err := PktEncRead(node2, nodes, &ct, &pt)
                if err != nil {
                        return false
                }
                if *node.Id != *node1.Id {
                        return false
                }
+               if sizeGot != int64(size) {
+                       return false
+               }
                var pktBuf bytes.Buffer
                xdr.Marshal(&pktBuf, &pkt)
                return bytes.Compare(pt.Bytes(), append(pktBuf.Bytes(), data[:int(size)]...)) == 0
index 66e5812d1151f99f4ec81e560ee7bdfb74d348d5..31bda110ced87a6070bc0615fa0ed1cd0e737d90 100644 (file)
@@ -96,7 +96,7 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun bool) bool {
                errs := make(chan error, 1)
                go func(job Job) {
                        pipeWB := bufio.NewWriter(pipeW)
-                       _, err := PktEncRead(
+                       _, _, err := PktEncRead(
                                ctx.Self,
                                ctx.Neigh,
                                bufio.NewReader(job.Fd),
@@ -249,7 +249,7 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun bool) bool {
                                goto Closing
                        }
                        if !dryRun {
-                               if err = ctx.TxFile(sender, job.PktEnc.Nice, filepath.Join(*freq, src), dst); err != nil {
+                               if err = ctx.TxFile(sender, job.PktEnc.Nice, filepath.Join(*freq, src), dst, 0); err != nil {
                                        ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "tx file")
                                        isBad = true
                                        goto Closing
index ee8ae80e6488c9c8a9a9e2b347c3a04f13fe3e04..f0038d8ac38493cd32de83ffea2f59fc4612792e 100644 (file)
@@ -92,6 +92,7 @@ func TestTossEmail(t *testing.T) {
                                DefaultNiceMail,
                                "recipient",
                                []byte{123},
+                               1<<15,
                        ); err != nil {
                                panic(err)
                        }
@@ -180,6 +181,7 @@ func TestTossFile(t *testing.T) {
                                DefaultNiceFile,
                                src,
                                fileName,
+                               1<<15,
                        ); err != nil {
                                panic(err)
                        }
@@ -249,6 +251,7 @@ func TestTossFileSameName(t *testing.T) {
                                DefaultNiceFile,
                                srcPath,
                                "samefile",
+                               1<<15,
                        ); err != nil {
                                panic(err)
                        }
@@ -314,6 +317,7 @@ func TestTossFreq(t *testing.T) {
                                DefaultNiceFreq,
                                fileName,
                                fileName,
+                               1<<15,
                        ); err != nil {
                                panic(err)
                        }
@@ -346,7 +350,7 @@ func TestTossFreq(t *testing.T) {
                }
                for job := range ctx.Jobs(ctx.Self.Id, TTx) {
                        var buf bytes.Buffer
-                       _, err := PktEncRead(ctx.Self, ctx.Neigh, job.Fd, &buf)
+                       _, _, err := PktEncRead(ctx.Self, ctx.Neigh, job.Fd, &buf)
                        if err != nil {
                                panic(err)
                        }
@@ -417,6 +421,7 @@ func TestTossTrns(t *testing.T) {
                                &pktTrans,
                                123,
                                int64(len(data)),
+                               0,
                                bytes.NewReader(data),
                                &dst,
                        ); err != nil {
index 03e2df241673b8956bec20f8e4cd2712fd88e5cf..b016863c47dd1c040a634ba8aaf8dba904c824f4 100644 (file)
@@ -32,7 +32,7 @@ import (
        "golang.org/x/crypto/blake2b"
 )
 
-func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size int64, src io.Reader) (*Node, error) {
+func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size, minSize int64, src io.Reader) (*Node, error) {
        tmp, err := ctx.NewTmpFileWHash()
        if err != nil {
                return nil, err
@@ -44,6 +44,10 @@ func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size int64, src io.Reader)
                lastNode = ctx.Neigh[*node.Via[i-1]]
                hops = append(hops, lastNode)
        }
+       padSize := minSize - size - int64(len(hops)) * (PktOverhead + PktEncOverhead)
+       if padSize < 0 {
+               padSize = 0
+       }
        errs := make(chan error)
        curSize := size
        pipeR, pipeW := io.Pipe()
@@ -53,9 +57,10 @@ func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size int64, src io.Reader)
                        "nice": strconv.Itoa(int(nice)),
                        "size": strconv.FormatInt(size, 10),
                }, "wrote")
-               errs <- PktEncWrite(ctx.Self, hops[0], pkt, nice, size, src, dst)
+               errs <- PktEncWrite(ctx.Self, hops[0], pkt, nice, size, padSize, src, dst)
                dst.Close()
        }(curSize, src, pipeW)
+       curSize += padSize
 
        var pipeRPrev io.Reader
        for i := 1; i < len(hops); i++ {
@@ -75,7 +80,7 @@ func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size int64, src io.Reader)
                                "nice": strconv.Itoa(int(nice)),
                                "size": strconv.FormatInt(size, 10),
                        }, "trns wrote")
-                       errs <- PktEncWrite(ctx.Self, node, pkt, nice, size, src, dst)
+                       errs <- PktEncWrite(ctx.Self, node, pkt, nice, size, 0, src, dst)
                        dst.Close()
                }(hops[i], &pktTrans, curSize, pipeRPrev, pipeW)
        }
@@ -96,7 +101,7 @@ func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size int64, src io.Reader)
        return lastNode, err
 }
 
-func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string) error {
+func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string, minSize int64) error {
        if dstPath == "" {
                dstPath = filepath.Base(srcPath)
        }
@@ -117,7 +122,7 @@ func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string) error {
        if err != nil {
                return err
        }
-       _, err = ctx.Tx(node, pkt, nice, srcStat.Size(), bufio.NewReader(src))
+       _, err = ctx.Tx(node, pkt, nice, srcStat.Size(), minSize, bufio.NewReader(src))
        if err == nil {
                ctx.LogI("tx", SDS{
                        "type": "file",
@@ -141,7 +146,7 @@ func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string) error {
        return err
 }
 
-func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string) error {
+func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string, minSize int64) error {
        dstPath = filepath.Clean(dstPath)
        if filepath.IsAbs(dstPath) {
                return errors.New("Relative destination path required")
@@ -156,7 +161,7 @@ func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string) error {
        }
        src := strings.NewReader(dstPath)
        size := int64(src.Len())
-       _, err = ctx.Tx(node, pkt, nice, size, src)
+       _, err = ctx.Tx(node, pkt, nice, size, minSize, src)
        if err == nil {
                ctx.LogI("tx", SDS{
                        "type": "freq",
@@ -178,7 +183,7 @@ func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string) error {
        return err
 }
 
-func (ctx *Ctx) TxMail(node *Node, nice uint8, recipient string, body []byte) error {
+func (ctx *Ctx) TxMail(node *Node, nice uint8, recipient string, body []byte, minSize int64) error {
        pkt, err := NewPkt(PktTypeMail, recipient)
        if err != nil {
                return err
@@ -190,7 +195,7 @@ func (ctx *Ctx) TxMail(node *Node, nice uint8, recipient string, body []byte) er
        }
        compressor.Close()
        size := int64(compressed.Len())
-       _, err = ctx.Tx(node, pkt, nice, size, &compressed)
+       _, err = ctx.Tx(node, pkt, nice, size, minSize, &compressed)
        if err == nil {
                ctx.LogI("tx", SDS{
                        "type": "mail",
index fd2117bc6238d3789c09edbee5a090e29497c009..c46f057789a7b21e6ba7c2c85259011613a63ac3 100644 (file)
@@ -33,7 +33,7 @@ import (
 )
 
 func TestTx(t *testing.T) {
-       f := func(hops uint8, pathSrc, data string, nice uint8) bool {
+       f := func(hops uint8, pathSrc, data string, nice uint8, padSize int16) bool {
                if len(pathSrc) > int(MaxPathSize) {
                        pathSrc = pathSrc[:MaxPathSize]
                }
@@ -77,7 +77,14 @@ func TestTx(t *testing.T) {
                }
                pkt, err := NewPkt(PktTypeMail, pathSrc)
                src := strings.NewReader(data)
-               dstNode, err := ctx.Tx(nodeTgt, pkt, 123, int64(src.Len()), src)
+               dstNode, err := ctx.Tx(
+                       nodeTgt,
+                       pkt,
+                       123,
+                       int64(src.Len()),
+                       int64(padSize),
+                       src,
+               )
                if err != nil {
                        return false
                }
@@ -99,7 +106,7 @@ func TestTx(t *testing.T) {
                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)
                        if err != nil {
                                return false
                        }