From: Sergey Matveev Date: Sat, 29 Apr 2017 08:23:17 +0000 (+0300) Subject: Ability to do chunked freqing X-Git-Tag: 0.7^2~18 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0ac8e9854e50e8c8a6eb53dc4c23ad5b19ad08c5;p=nncp.git Ability to do chunked freqing --- diff --git a/doc/cfg.texi b/doc/cfg.texi index 653c801..ea104f5 100644 --- a/doc/cfg.texi +++ b/doc/cfg.texi @@ -49,6 +49,8 @@ neigh: signpub: GTGXG...IE3OA sendmail: [/usr/sbin/sendmail] freq: /home/bob/pub + freqchunked: 1024 + freqminsize: 2097152 via: [alice] @end verbatim @@ -99,6 +101,14 @@ omitted to forbid file uploading on that node. Full path to directory from where file requests will queue files for transmission. May be omitted to forbid freqing from that node. +@item freqchunked +If set, then enable @ref{Chunked, chunked} file transmission during +freqing. This is the desired chunk size in KiBs. + +@item freqminsize +If set, then apply @ref{OptMinSize, -minsize} option during file +transmission. + @item via An array of node identifiers that will be used as a relay to that node. For example @verb{|[foo,bar]|} means that packet can reach current node diff --git a/doc/cmds.texi b/doc/cmds.texi index 5d7d633..b8da1d9 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -10,9 +10,10 @@ Nearly all commands have the following common options: @item -debug Print debug messages. Normally this option should not be used. @item -minsize - Minimal required resulting packet size. For example if you send 2 - KiB file and set @option{-minsize 4096}, then resulting packet will - be 4 KiB (containing file itself and some junk). + @anchor{OptMinSize} + Minimal required resulting packet size, in bytes. For example if you + send 2 KiB file and set @option{-minsize 4096}, then resulting + packet will be 4 KiB (containing file itself and some junk). @item -nice Set desired outgoing packet @ref{Niceness, niceness level}. 1-255 values are allowed. diff --git a/doc/news.texi b/doc/news.texi index 77e63a1..5f3bd27 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -7,8 +7,10 @@ @item Ability to feed @command{nncp-file} from stdin, that uses an encrypted temporary file for that. @item Chunked files transmission appeared with corresponding -@command{nncp-reass} command. Useful for transferring big files over -small storage devices. +@command{nncp-reass} command and @option{freqchunked} configuration file +entry. Useful for transferring big files over small storage devices. +@item @option{freqminsize} configuration file option, analogue to +@option{-minsize} one. @item Cryptographic libraries (dependecies) are updated. @end itemize diff --git a/src/cypherpunks.ru/nncp/cfg.go b/src/cypherpunks.ru/nncp/cfg.go index f89c106..ce70963 100644 --- a/src/cypherpunks.ru/nncp/cfg.go +++ b/src/cypherpunks.ru/nncp/cfg.go @@ -40,15 +40,17 @@ var ( ) type NodeYAML struct { - Id string - ExchPub string - SignPub string - NoisePub *string `noisepub,omitempty` - Sendmail []string `sendmail,omitempty` - Incoming *string `incoming,omitempty` - Freq *string `freq,omitempty` - Via []string `via,omitempty` - Calls []CallYAML `calls,omitempty` + Id string + ExchPub string + SignPub string + NoisePub *string `noisepub,omitempty` + Sendmail []string `sendmail,omitempty` + Incoming *string `incoming,omitempty` + Freq *string `freq,omitempty` + FreqChunked *uint64 `freqchunked,omitempty` + FreqMinSize *uint64 `freqminsize,omitempty` + Via []string `via,omitempty` + Calls []CallYAML `calls,omitempty` Addrs map[string]string `addrs,omitempty` @@ -144,6 +146,17 @@ func NewNode(name string, yml NodeYAML) (*Node, error) { } freq = &fr } + var freqChunked int64 + if yml.FreqChunked != nil { + if *yml.FreqChunked == 0 { + return nil, errors.New("freqchunked value must be greater than zero") + } + freqChunked = int64(*yml.FreqChunked) + } + var freqMinSize int64 + if yml.FreqMinSize != nil { + freqMinSize = int64(*yml.FreqMinSize) + } defOnlineDeadline := uint(DefaultDeadline) if yml.OnlineDeadline != nil { @@ -218,6 +231,8 @@ func NewNode(name string, yml NodeYAML) (*Node, error) { Sendmail: yml.Sendmail, Incoming: incoming, Freq: freq, + FreqChunked: freqChunked, + FreqMinSize: freqMinSize, Calls: calls, Addrs: yml.Addrs, OnlineDeadline: defOnlineDeadline, diff --git a/src/cypherpunks.ru/nncp/node.go b/src/cypherpunks.ru/nncp/node.go index 7992f4b..22fa3fb 100644 --- a/src/cypherpunks.ru/nncp/node.go +++ b/src/cypherpunks.ru/nncp/node.go @@ -45,6 +45,8 @@ type Node struct { Sendmail []string Incoming *string Freq *string + FreqChunked int64 + FreqMinSize int64 Via []*NodeId Addrs map[string]string OnlineDeadline uint diff --git a/src/cypherpunks.ru/nncp/toss.go b/src/cypherpunks.ru/nncp/toss.go index 8a48e91..4ae9711 100644 --- a/src/cypherpunks.ru/nncp/toss.go +++ b/src/cypherpunks.ru/nncp/toss.go @@ -264,7 +264,25 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun bool) bool { goto Closing } if !dryRun { - if err = ctx.TxFile(sender, job.PktEnc.Nice, filepath.Join(*freq, src), dst, 0); err != nil { + if sender.FreqChunked == 0 { + err = ctx.TxFile( + sender, + job.PktEnc.Nice, + filepath.Join(*freq, src), + dst, + sender.FreqMinSize, + ) + } else { + err = ctx.TxFileChunked( + sender, + job.PktEnc.Nice, + filepath.Join(*freq, src), + dst, + sender.FreqMinSize, + sender.FreqChunked, + ) + } + if err != nil { ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "tx file") isBad = true goto Closing