From: Sergey Matveev Date: Fri, 22 Nov 2019 19:40:55 +0000 (+0300) Subject: freq.maxsize configuration file option X-Git-Tag: v5.1.0^2~2 X-Git-Url: http://www.git.cypherpunks.ru/?p=nncp.git;a=commitdiff_plain;h=aa9595835a7c23d83906da6570be5a68e1070905 freq.maxsize configuration file option --- diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 675e041..3290355 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -18,6 +18,10 @@ конфигурационного файла заменены на структуру @option{freq: @{path: ..., minsize: ..., chunked: ...@}}. +@item +Добавлена @option{freq.maxsize} опция конфигурационного файл, +запрещающая ответ на файловый запрос больше заданного размера. + @end itemize @node Релиз 5.0.0 diff --git a/doc/news.texi b/doc/news.texi index 0516ecf..ec52ba2 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -19,6 +19,10 @@ Free disk space is checked during outbound packets creation. file options replaced with the structure: @option{freq: @{path: ..., minsize: ..., chunked: ...@}}. +@item +Added @option{freq.maxsize} configuration file option, forbidding of +freq sending larger than specified size. + @end itemize @node Release 5.0.0 diff --git a/src/cfg.go b/src/cfg.go index ab8ec7f..46e6bba 100644 --- a/src/cfg.go +++ b/src/cfg.go @@ -68,6 +68,7 @@ type NodeFreqJSON struct { Path *string `json:"path,omitempty"` Chunked *uint64 `json:"chunked,omitempty"` MinSize *uint64 `json:"minsize,omitempty"` + MaxSize *uint64 `json:"maxsize,omitempty"` } type CallJSON struct { @@ -157,6 +158,7 @@ func NewNode(name string, yml NodeJSON) (*Node, error) { var freqPath *string freqChunked := int64(MaxFileSize) var freqMinSize int64 + freqMaxSize := int64(MaxFileSize) if yml.Freq != nil { f := yml.Freq if f.Path != nil { @@ -175,6 +177,9 @@ func NewNode(name string, yml NodeJSON) (*Node, error) { if f.MinSize != nil { freqMinSize = int64(*f.MinSize) * 1024 } + if f.MaxSize != nil { + freqMaxSize = int64(*f.MaxSize) * 1024 + } } defRxRate := 0 @@ -278,6 +283,7 @@ func NewNode(name string, yml NodeJSON) (*Node, error) { FreqPath: freqPath, FreqChunked: freqChunked, FreqMinSize: freqMinSize, + FreqMaxSize: freqMaxSize, Calls: calls, Addrs: yml.Addrs, RxRate: defRxRate, diff --git a/src/cmd/nncp-file/main.go b/src/cmd/nncp-file/main.go index 8e1b7f8..d7c0607 100644 --- a/src/cmd/nncp-file/main.go +++ b/src/cmd/nncp-file/main.go @@ -116,6 +116,7 @@ func main() { splitted[1], chunkSize, minSize, + nncp.MaxFileSize, ); err != nil { log.Fatalln(err) } diff --git a/src/node.go b/src/node.go index dd2442b..65f5e9c 100644 --- a/src/node.go +++ b/src/node.go @@ -45,6 +45,7 @@ type Node struct { FreqPath *string FreqChunked int64 FreqMinSize int64 + FreqMaxSize int64 Via []*NodeId Addrs map[string]string RxRate int @@ -105,6 +106,7 @@ func (nodeOur *NodeOur) Their() *Node { ExchPub: nodeOur.ExchPub, SignPub: nodeOur.SignPub, FreqChunked: MaxFileSize, + FreqMaxSize: MaxFileSize, } } diff --git a/src/toss.go b/src/toss.go index eaf7401..19e97e5 100644 --- a/src/toss.go +++ b/src/toss.go @@ -294,6 +294,7 @@ func (ctx *Ctx) Toss( dst, sender.FreqChunked, sender.FreqMinSize, + sender.FreqMaxSize, ) if err != nil { ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "tx file") diff --git a/src/toss_test.go b/src/toss_test.go index d11c589..3a6f29f 100644 --- a/src/toss_test.go +++ b/src/toss_test.go @@ -201,6 +201,7 @@ func TestTossFile(t *testing.T) { fileName, MaxFileSize, 1<<15, + MaxFileSize, ); err != nil { t.Error(err) return false @@ -276,6 +277,7 @@ func TestTossFileSameName(t *testing.T) { "samefile", MaxFileSize, 1<<15, + MaxFileSize, ); err != nil { t.Error(err) return false diff --git a/src/tx.go b/src/tx.go index 7d49776..20853b0 100644 --- a/src/tx.go +++ b/src/tx.go @@ -286,7 +286,7 @@ func (ctx *Ctx) TxFile( nice uint8, srcPath, dstPath string, chunkSize int64, - minSize int64, + minSize, maxSize int64, ) error { dstPathSpecified := false if dstPath == "" { @@ -308,6 +308,9 @@ func (ctx *Ctx) TxFile( if err != nil { return err } + if fileSize > maxSize { + return errors.New("Too big than allowed") + } if archived && !dstPathSpecified { dstPath += TarExt }