]> Cypherpunks.ru repositories - nncp.git/commitdiff
Group freq-related configuration options in single structure
authorSergey Matveev <stargrave@stargrave.org>
Fri, 22 Nov 2019 19:40:47 +0000 (22:40 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 24 Nov 2019 15:08:55 +0000 (18:08 +0300)
doc/cfg.texi
doc/cmds.texi
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

index 0aca8f9d5694b5a953289f895ef6fc8dd2192262..c16c2b1c025c2d4f56d7bf2065873d96101fc762 100644 (file)
@@ -67,9 +67,11 @@ Example @url{https://hjson.org/, Hjson} configuration file:
         warcer: ["/path/to/warcer.sh"]
         wgeter: ["/path/to/wgeter.sh"]
       }
-      freq: "/home/bob/pub"
-      freqchunked: 1024
-      freqminsize: 2048
+      freq: {
+        path: "/home/bob/pub"
+        chunked: 1024
+        minsize: 2048
+      }
       via: ["alice"]
       rxrate: 10
       txrate: 20
@@ -141,15 +143,15 @@ Full path to directory where all file uploads will be saved. May be
 omitted to forbid file uploading on that node.
 
 @anchor{CfgFreq}
-@item freq
+@item freq.path
 Full path to directory from where file requests will queue files for
 transmission. May be omitted to forbid freqing from that node.
 
-@item freqchunked
+@item freq.chunked
 If set, then enable @ref{Chunked, chunked} file transmission during
 freqing. This is the desired chunk size in KiBs.
 
-@item freqminsize
+@item freq.minsize
 If set, then apply @ref{OptMinSize, -minsize} option during file
 transmission.
 
index 7097e821648078f449bb8390606e7afb6006830c..f6adca7855add278cccd9a9d1b09f01f693da1b0 100644 (file)
@@ -343,7 +343,7 @@ $ nncp-freq [options] NODE:SRC [DST]
 @end verbatim
 
 Send file request to @option{NODE}, asking it to send its @file{SRC}
-file from @ref{CfgFreq, freq} directory to our node under @file{DST}
+file from @ref{CfgFreq, freq.path} directory to our node under @file{DST}
 filename in our @ref{CfgIncoming, incoming} one. If @file{DST} is not
 specified, then last element of @file{SRC} will be used.
 
index a7508f448cf92738f8d6b88e0cdc0f36578620d5..675e041d53846562f36f58ae257b9a65c8dab128 100644 (file)
 Во время создания исходящих сообщений проверяется наличие свободного
 места на файловой системе.
 
+@item
+@option{freq}, @option{freqminsize}, @option{freqchunked} опции
+конфигурационного файла заменены на структуру
+@option{freq: @{path: ..., minsize: ..., chunked: ...@}}.
+
 @end itemize
 
 @node Релиз 5.0.0
index 2617f96130294d0677c0f218b6d90ac74d50b2bf..0516ecfadd224d19b831f4ed3538485013b4f75a 100644 (file)
@@ -14,6 +14,11 @@ archive on the fly.
 @item
 Free disk space is checked during outbound packets creation.
 
+@item
+@option{freq}, @option{freqminsize}, @option{freqchunked} configuration
+file options replaced with the structure:
+@option{freq: @{path: ..., minsize: ..., chunked: ...@}}.
+
 @end itemize
 
 @node Release 5.0.0
index a4450e0ae9ff7877d4961322b8abc0bd90d41942..ca8099e5fc5d08280e16e164d14b9c31e90de689 100644 (file)
@@ -46,17 +46,15 @@ var (
 )
 
 type NodeJSON struct {
-       Id          string              `json:"id"`
-       ExchPub     string              `json:"exchpub"`
-       SignPub     string              `json:"signpub"`
-       NoisePub    *string             `json:"noisepub,omitempty"`
-       Exec        map[string][]string `json:"exec,omitempty"`
-       Incoming    *string             `json:"incoming,omitempty"`
-       Freq        *string             `json:"freq,omitempty"`
-       FreqChunked *uint64             `json:"freqchunked,omitempty"`
-       FreqMinSize *uint64             `json:"freqminsize,omitempty"`
-       Via         []string            `json:"via,omitempty"`
-       Calls       []CallJSON          `json:"calls,omitempty"`
+       Id       string              `json:"id"`
+       ExchPub  string              `json:"exchpub"`
+       SignPub  string              `json:"signpub"`
+       NoisePub *string             `json:"noisepub,omitempty"`
+       Exec     map[string][]string `json:"exec,omitempty"`
+       Incoming *string             `json:"incoming,omitempty"`
+       Freq     *NodeFreqJSON       `json:"freq,omitempty"`
+       Via      []string            `json:"via,omitempty"`
+       Calls    []CallJSON          `json:"calls,omitempty"`
 
        Addrs map[string]string `json:"addrs,omitempty"`
 
@@ -66,6 +64,12 @@ type NodeJSON struct {
        MaxOnlineTime  *uint `json:"maxonlinetime,omitempty"`
 }
 
+type NodeFreqJSON struct {
+       Path    *string `json:"path,omitempty"`
+       Chunked *uint64 `json:"chunked,omitempty"`
+       MinSize *uint64 `json:"minsize,omitempty"`
+}
+
 type CallJSON struct {
        Cron           string
        Nice           *string `json:"nice,omitempty"`
@@ -150,24 +154,27 @@ func NewNode(name string, yml NodeJSON) (*Node, error) {
                incoming = &inc
        }
 
-       var freq *string
+       var freqPath *string
+       var freqChunked int64
+       var freqMinSize int64
        if yml.Freq != nil {
-               fr := path.Clean(*yml.Freq)
-               if !path.IsAbs(fr) {
-                       return nil, errors.New("Freq path must be absolute")
+               f := yml.Freq
+               if f.Path != nil {
+                       fPath := path.Clean(*f.Path)
+                       if !path.IsAbs(fPath) {
+                               return nil, errors.New("freq.path path must be absolute")
+                       }
+                       freqPath = &fPath
                }
-               freq = &fr
-       }
-       var freqChunked int64
-       if yml.FreqChunked != nil {
-               if *yml.FreqChunked == 0 {
-                       return nil, errors.New("freqchunked value must be greater than zero")
+               if f.Chunked != nil {
+                       if *f.Chunked == 0 {
+                               return nil, errors.New("freq.chunked value must be greater than zero")
+                       }
+                       freqChunked = int64(*f.Chunked) * 1024
+               }
+               if f.MinSize != nil {
+                       freqMinSize = int64(*f.MinSize) * 1024
                }
-               freqChunked = int64(*yml.FreqChunked) * 1024
-       }
-       var freqMinSize int64
-       if yml.FreqMinSize != nil {
-               freqMinSize = int64(*yml.FreqMinSize) * 1024
        }
 
        defRxRate := 0
@@ -268,7 +275,7 @@ func NewNode(name string, yml NodeJSON) (*Node, error) {
                SignPub:        ed25519.PublicKey(signPub),
                Exec:           yml.Exec,
                Incoming:       incoming,
-               Freq:           freq,
+               FreqPath:       freqPath,
                FreqChunked:    freqChunked,
                FreqMinSize:    freqMinSize,
                Calls:          calls,
index f3572ca04fc95f2b6a38aca6171324a92b9cfd71..8274d0e993002992a8e76851f106f955b56ba793 100644 (file)
@@ -36,7 +36,7 @@ func usage() {
        fmt.Fprint(os.Stderr, `
 If SRC equals to -, then read data from stdin to temporary file.
 
--minsize/-chunked take NODE's FreqMinSize/FreqChunked configuration
+-minsize/-chunked take NODE's freq.minsize/freq.chunked configuration
 options by default. You can forcefully turn them off by specifying 0 value.
 `)
 }
index ac78301f802464dae9c763de4de93495c259f748..165cd86999fde4cf31d4f7ec47548357acff6377 100644 (file)
@@ -42,7 +42,7 @@ type Node struct {
        NoisePub       *[32]byte
        Exec           map[string][]string
        Incoming       *string
-       Freq           *string
+       FreqPath       *string
        FreqChunked    int64
        FreqMinSize    int64
        Via            []*NodeId
index 43b72f5c1cffad94620dd8d0abbaaa0cad42510b..5652c68d15de8b46e33d9487a125164ea89d7e46 100644 (file)
@@ -280,8 +280,8 @@ func (ctx *Ctx) Toss(
                        dst := string(dstRaw)
                        sds["dst"] = dst
                        sender := ctx.Neigh[*job.PktEnc.Sender]
-                       freq := sender.Freq
-                       if freq == nil {
+                       freqPath := sender.FreqPath
+                       if freqPath == nil {
                                ctx.LogE("rx", sds, "freqing is not allowed")
                                isBad = true
                                goto Closing
@@ -291,7 +291,7 @@ func (ctx *Ctx) Toss(
                                        err = ctx.TxFile(
                                                sender,
                                                pkt.Nice,
-                                               filepath.Join(*freq, src),
+                                               filepath.Join(*freqPath, src),
                                                dst,
                                                sender.FreqMinSize,
                                        )
@@ -299,7 +299,7 @@ func (ctx *Ctx) Toss(
                                        err = ctx.TxFileChunked(
                                                sender,
                                                pkt.Nice,
-                                               filepath.Join(*freq, src),
+                                               filepath.Join(*freqPath, src),
                                                dst,
                                                sender.FreqMinSize,
                                                sender.FreqChunked,
index 825ec09977611cccf1d49aade53e576bcdd4d6f4..4bb5980ac2cd6a0e0bb235085ee4e50b92d189d3 100644 (file)
@@ -357,7 +357,7 @@ func TestTossFreq(t *testing.T) {
                if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 {
                        return false
                }
-               ctx.Neigh[*nodeOur.Id].Freq = &spool
+               ctx.Neigh[*nodeOur.Id].FreqPath = &spool
                ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false)
                if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 {
                        return false