From: Sergey Matveev Date: Wed, 14 Feb 2018 21:09:34 +0000 (+0300) Subject: Small chunked files are sent as an ordinary ones X-Git-Tag: 3.0^2~12 X-Git-Url: http://www.git.cypherpunks.ru/?a=commitdiff_plain;h=2afa3121b4a46bbceeebdf6d04971ddac0d9fcb0;p=nncp.git Small chunked files are sent as an ordinary ones --- diff --git a/doc/news.ru.texi b/doc/news.ru.texi index ec168fa..fd37894 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -8,6 +8,9 @@ Возможность переопределить @option{via} опцию конфигурации для целевого узла через @option{-via} опцию командной строки для следующих команд: @command{nncp-file}, @command{nncp-freq}, @command{nncp-mail}. +@item +Chunked файлы, меньшего размера чем указанный chunk, отправляются просто +в виде одного файла. @end itemize @node Релиз 2.0 diff --git a/doc/news.texi b/doc/news.texi index d2dbd61..475583e 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -10,6 +10,9 @@ See also this page @ref{Новости, on russian}. Ability to override @option{via} configuration option for destination node via @option{-via} command line option for following commands: @command{nncp-file}, @command{nncp-freq}, @command{nncp-mail}. +@item +Chunked files, having size less than specified chunk size, will be sent +as an ordinary single file. @end itemize @node Release 2.0 diff --git a/src/cypherpunks.ru/nncp/tx.go b/src/cypherpunks.ru/nncp/tx.go index aeb1748..0569cce 100644 --- a/src/cypherpunks.ru/nncp/tx.go +++ b/src/cypherpunks.ru/nncp/tx.go @@ -211,6 +211,35 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m return err } + if fileSize <= chunkSize { + pkt, err := NewPkt(PktTypeFile, dstPath) + if err != nil { + return err + } + _, err = ctx.Tx(node, pkt, nice, fileSize, minSize, reader) + if err == nil { + ctx.LogI("tx", SDS{ + "type": "file", + "node": node.Id, + "nice": strconv.Itoa(int(nice)), + "src": srcPath, + "dst": dstPath, + "size": strconv.FormatInt(fileSize, 10), + }, "sent") + } else { + ctx.LogE("tx", SDS{ + "type": "file", + "node": node.Id, + "nice": strconv.Itoa(int(nice)), + "src": srcPath, + "dst": dstPath, + "size": strconv.FormatInt(fileSize, 10), + "err": err, + }, "sent") + } + return err + } + leftSize := fileSize metaPkt := ChunkedMeta{ Magic: MagicNNCPMv1,