From 09afeef5b0f3a3a7305249dd3e8d8ea76fd69b04 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 22 Nov 2019 22:40:47 +0300 Subject: [PATCH] Group freq-related configuration options in single structure --- doc/cfg.texi | 14 +++++---- doc/cmds.texi | 2 +- doc/news.ru.texi | 5 ++++ doc/news.texi | 5 ++++ src/cfg.go | 61 ++++++++++++++++++++++----------------- src/cmd/nncp-file/main.go | 2 +- src/node.go | 2 +- src/toss.go | 8 ++--- src/toss_test.go | 2 +- 9 files changed, 60 insertions(+), 41 deletions(-) diff --git a/doc/cfg.texi b/doc/cfg.texi index 0aca8f9..c16c2b1 100644 --- a/doc/cfg.texi +++ b/doc/cfg.texi @@ -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. diff --git a/doc/cmds.texi b/doc/cmds.texi index 7097e82..f6adca7 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -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. diff --git a/doc/news.ru.texi b/doc/news.ru.texi index a7508f4..675e041 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -13,6 +13,11 @@ Во время создания исходящих сообщений проверяется наличие свободного места на файловой системе. +@item +@option{freq}, @option{freqminsize}, @option{freqchunked} опции +конфигурационного файла заменены на структуру +@option{freq: @{path: ..., minsize: ..., chunked: ...@}}. + @end itemize @node Релиз 5.0.0 diff --git a/doc/news.texi b/doc/news.texi index 2617f96..0516ecf 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -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 diff --git a/src/cfg.go b/src/cfg.go index a4450e0..ca8099e 100644 --- a/src/cfg.go +++ b/src/cfg.go @@ -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, diff --git a/src/cmd/nncp-file/main.go b/src/cmd/nncp-file/main.go index f3572ca..8274d0e 100644 --- a/src/cmd/nncp-file/main.go +++ b/src/cmd/nncp-file/main.go @@ -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. `) } diff --git a/src/node.go b/src/node.go index ac78301..165cd86 100644 --- a/src/node.go +++ b/src/node.go @@ -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 diff --git a/src/toss.go b/src/toss.go index 43b72f5..5652c68 100644 --- a/src/toss.go +++ b/src/toss.go @@ -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, diff --git a/src/toss_test.go b/src/toss_test.go index 825ec09..4bb5980 100644 --- a/src/toss_test.go +++ b/src/toss_test.go @@ -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 -- 2.44.0