]> Cypherpunks.ru repositories - nncp.git/commitdiff
Replace TxFile with TxFileChunked
authorSergey Matveev <stargrave@stargrave.org>
Fri, 22 Nov 2019 19:40:50 +0000 (22:40 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 24 Nov 2019 15:08:55 +0000 (18:08 +0300)
If chunk size is really huge, then no chunked data transmission will
occur, behaving exactly as TxFile.

src/cfg.go
src/cmd/nncp-file/main.go
src/node.go
src/toss.go
src/toss_test.go
src/tx.go

index ca8099e5fc5d08280e16e164d14b9c31e90de689..ab8ec7f6d73c0925fe71b0a8c0cd633666275d80 100644 (file)
@@ -155,7 +155,7 @@ func NewNode(name string, yml NodeJSON) (*Node, error) {
        }
 
        var freqPath *string
-       var freqChunked int64
+       freqChunked := int64(MaxFileSize)
        var freqMinSize int64
        if yml.Freq != nil {
                f := yml.Freq
index 8274d0e993002992a8e76851f106f955b56ba793..8e1b7f88706deb56c3c72fbe7cedc39ef74a05fe 100644 (file)
@@ -109,25 +109,14 @@ func main() {
                chunkSize = *argChunkSize * 1024
        }
 
-       if chunkSize == 0 {
-               err = ctx.TxFile(
-                       node,
-                       nice,
-                       flag.Arg(0),
-                       splitted[1],
-                       minSize,
-               )
-       } else {
-               err = ctx.TxFileChunked(
-                       node,
-                       nice,
-                       flag.Arg(0),
-                       splitted[1],
-                       minSize,
-                       chunkSize,
-               )
-       }
-       if err != nil {
+       if err = ctx.TxFile(
+               node,
+               nice,
+               flag.Arg(0),
+               splitted[1],
+               chunkSize,
+               minSize,
+       ); err != nil {
                log.Fatalln(err)
        }
 }
index 165cd86999fde4cf31d4f7ec47548357acff6377..dd2442b06d52516627d325056b01747ede14de41 100644 (file)
@@ -100,10 +100,11 @@ func NewNodeGenerate() (*NodeOur, error) {
 
 func (nodeOur *NodeOur) Their() *Node {
        return &Node{
-               Name:    "self",
-               Id:      nodeOur.Id,
-               ExchPub: nodeOur.ExchPub,
-               SignPub: nodeOur.SignPub,
+               Name:        "self",
+               Id:          nodeOur.Id,
+               ExchPub:     nodeOur.ExchPub,
+               SignPub:     nodeOur.SignPub,
+               FreqChunked: MaxFileSize,
        }
 }
 
index 5652c68d15de8b46e33d9487a125164ea89d7e46..eaf74019fcc0acc0a9519d31ccf53f942da6f1fc 100644 (file)
@@ -287,24 +287,14 @@ func (ctx *Ctx) Toss(
                                goto Closing
                        }
                        if !dryRun {
-                               if sender.FreqChunked == 0 {
-                                       err = ctx.TxFile(
-                                               sender,
-                                               pkt.Nice,
-                                               filepath.Join(*freqPath, src),
-                                               dst,
-                                               sender.FreqMinSize,
-                                       )
-                               } else {
-                                       err = ctx.TxFileChunked(
-                                               sender,
-                                               pkt.Nice,
-                                               filepath.Join(*freqPath, src),
-                                               dst,
-                                               sender.FreqMinSize,
-                                               sender.FreqChunked,
-                                       )
-                               }
+                               err = ctx.TxFile(
+                                       sender,
+                                       pkt.Nice,
+                                       filepath.Join(*freqPath, src),
+                                       dst,
+                                       sender.FreqChunked,
+                                       sender.FreqMinSize,
+                               )
                                if err != nil {
                                        ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "tx file")
                                        isBad = true
index 4bb5980ac2cd6a0e0bb235085ee4e50b92d189d3..d11c58925d484ca904aead55bfe37745c6dbf58f 100644 (file)
@@ -199,6 +199,7 @@ func TestTossFile(t *testing.T) {
                                DefaultNiceFile,
                                src,
                                fileName,
+                               MaxFileSize,
                                1<<15,
                        ); err != nil {
                                t.Error(err)
@@ -273,6 +274,7 @@ func TestTossFileSameName(t *testing.T) {
                                DefaultNiceFile,
                                srcPath,
                                "samefile",
+                               MaxFileSize,
                                1<<15,
                        ); err != nil {
                                t.Error(err)
index 4b7cb347cc992a3f4f4e58152671d61581bbe275..5c5c446171122b62620a1b246b7477e2fa16d5ff 100644 (file)
--- a/src/tx.go
+++ b/src/tx.go
@@ -39,6 +39,8 @@ import (
 )
 
 const (
+       MaxFileSize = 1 << 62
+
        TarBlockSize = 512
        TarExt       = ".tar"
 )
@@ -279,58 +281,12 @@ func prepareTxFile(srcPath string) (reader io.Reader, closer io.Closer, fileSize
        return
 }
 
-func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string, minSize int64) error {
-       dstPathSpecified := false
-       if dstPath == "" {
-               if srcPath == "-" {
-                       return errors.New("Must provide destination filename")
-               }
-               dstPath = filepath.Base(srcPath)
-       } else {
-               dstPathSpecified = true
-       }
-       dstPath = filepath.Clean(dstPath)
-       if filepath.IsAbs(dstPath) {
-               return errors.New("Relative destination path required")
-       }
-       reader, closer, fileSize, archived, err := prepareTxFile(srcPath)
-       if closer != nil {
-               defer closer.Close()
-       }
-       if err != nil {
-               return err
-       }
-       if archived && !dstPathSpecified {
-               dstPath += TarExt
-       }
-       pkt, err := NewPkt(PktTypeFile, nice, []byte(dstPath))
-       if err != nil {
-               return err
-       }
-       _, err = ctx.Tx(node, pkt, nice, fileSize, minSize, reader)
-       sds := SDS{
-               "type": "file",
-               "node": node.Id,
-               "nice": strconv.Itoa(int(nice)),
-               "src":  srcPath,
-               "dst":  dstPath,
-               "size": strconv.FormatInt(fileSize, 10),
-       }
-       if err == nil {
-               ctx.LogI("tx", sds, "sent")
-       } else {
-               sds["err"] = err
-               ctx.LogE("tx", sds, "sent")
-       }
-       return err
-}
-
-func (ctx *Ctx) TxFileChunked(
+func (ctx *Ctx) TxFile(
        node *Node,
        nice uint8,
        srcPath, dstPath string,
-       minSize int64,
        chunkSize int64,
+       minSize int64,
 ) error {
        dstPathSpecified := false
        if dstPath == "" {