]> Cypherpunks.ru repositories - nncp.git/commitdiff
freq.maxsize configuration file option
authorSergey Matveev <stargrave@stargrave.org>
Fri, 22 Nov 2019 19:40:55 +0000 (22:40 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 24 Nov 2019 15:08:55 +0000 (18:08 +0300)
doc/news.ru.texi
doc/news.texi
src/cfg.go
src/cmd/nncp-file/main.go
src/node.go
src/toss.go
src/toss_test.go
src/tx.go

index 675e041d53846562f36f58ae257b9a65c8dab128..32903555854e73ec752643f3fd5d4bf24dc4fc9d 100644 (file)
 конфигурационного файла заменены на структуру
 @option{freq: @{path: ..., minsize: ..., chunked: ...@}}.
 
+@item
+Добавлена @option{freq.maxsize} опция конфигурационного файл,
+запрещающая ответ на файловый запрос больше заданного размера.
+
 @end itemize
 
 @node Релиз 5.0.0
index 0516ecfadd224d19b831f4ed3538485013b4f75a..ec52ba2e7cc4ebbc2038a94e9d91a2170ffc5a8a 100644 (file)
@@ -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
index ab8ec7f6d73c0925fe71b0a8c0cd633666275d80..46e6bba6eab537a542f98619a9f19fc86964ed54 100644 (file)
@@ -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,
index 8e1b7f88706deb56c3c72fbe7cedc39ef74a05fe..d7c06074843642f4bc7052c2b0b10e0924264240 100644 (file)
@@ -116,6 +116,7 @@ func main() {
                splitted[1],
                chunkSize,
                minSize,
+               nncp.MaxFileSize,
        ); err != nil {
                log.Fatalln(err)
        }
index dd2442b06d52516627d325056b01747ede14de41..65f5e9cde30cc7e8c4931f9c54384c89b9c8e9b2 100644 (file)
@@ -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,
        }
 }
 
index eaf74019fcc0acc0a9519d31ccf53f942da6f1fc..19e97e531a7625403cd053186565784a89e12d24 100644 (file)
@@ -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")
index d11c58925d484ca904aead55bfe37745c6dbf58f..3a6f29fa36334c0f8924e3c53568e73a64058b69 100644 (file)
@@ -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
index 7d497769031695cfd058317b3511ca851028592d..20853b0b27a3cd4a02eab6027a2081675bf6a11f 100644 (file)
--- 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
        }