]> Cypherpunks.ru repositories - nncp.git/commitdiff
Freqed files have different niceness
authorSergey Matveev <stargrave@stargrave.org>
Thu, 15 Feb 2018 21:02:03 +0000 (00:02 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 16 Feb 2018 07:09:58 +0000 (10:09 +0300)
13 files changed:
VERSION
doc/cfg.texi
doc/news.ru.texi
doc/news.texi
doc/pkt.texi
src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go
src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go
src/cypherpunks.ru/nncp/pkt.go
src/cypherpunks.ru/nncp/pkt_test.go
src/cypherpunks.ru/nncp/toss.go
src/cypherpunks.ru/nncp/toss_test.go
src/cypherpunks.ru/nncp/tx.go
src/cypherpunks.ru/nncp/tx_test.go

diff --git a/VERSION b/VERSION
index 879b416e609a820dafeff67d679a7e3849fe8a09..9f55b2ccb5f234fc6b87ada62389a3d73815d0d1 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1
+3.0
index f898493feb5cc847cdf9121d9a38394aab1bf05b..3483f11c53fb1eec2b821cc98f3ec7146943136c 100644 (file)
@@ -91,7 +91,7 @@ An array containing path to executable and its command line arguments
 that is called for mail sending. If it is empty, then no mail processing
 will be performed from that node. Sendmail command
 @command{["/bin/foo", "bar"]} called the following way:
-@command{NNCP_SENDER=NODEID /bin/foo bar RCPT1 RCPT2 ... < MSG}.
+@command{NNCP_NICE=NICE NNCP_SENDER=NODEID /bin/foo bar RCPT1 RCPT2 ... < MSG}.
 
 @anchor{CfgIncoming}
 @item incoming
index fd37894b61382d35c11bb9bf2ec276eacf312011..de2d9d40ef6845cc6df813cbfb75fa418763319b 100644 (file)
@@ -1,8 +1,8 @@
 @node Новости
 @section Новости
 
-@node Релиз 2.1
-@subsection Релиз 2.1
+@node Релиз 3.0
+@subsection Релиз 3.0
 @itemize
 @item
 Возможность переопределить @option{via} опцию конфигурации для целевого
 @item
 Chunked файлы, меньшего размера чем указанный chunk, отправляются просто
 в виде одного файла.
+@item
+@strong{Несовместимое} изменение формата простых пакетов. Добавлено поле
+@emph{NICE}. Работа со старыми версиями не поддерживается.
+@item
+Sendmail команда вызывается с дополнительной переменной окружения
+@env{NNCP_NICE} содержащая значение приоритета пакета с сообщением.
+@item
+Отправляемые файлы в ответ на запрос имеют приоритет указанный в запросе.
+Указать их желаемый приоритет во время вызова @command{nncp-freq} можно
+аргументом @option{-replynice}.
 @end itemize
 
 @node Релиз 2.0
@@ -115,7 +125,7 @@ HKDF-BLAKE2b-256 KDF алгоритм заменён на BLAKE2Xb XOF. Ещё 
 @option{-mkdir} для ясности.
 
 @item
-Опция @option{-minsize} задётся в KiB, а не байтах, для удобства.
+Опция @option{-minsize} задаётся в KiB, а не байтах, для удобства.
 
 @item
 Команда @command{nncp-newcfg} переименована в @command{nncp-cfgnew},
index 475583e86e66da5eea9fd46aeb8c1d21aaef1daf..9a5bd2d69aeccc312ae25207ed56518fb59b7acd 100644 (file)
@@ -3,8 +3,8 @@
 
 See also this page @ref{Новости, on russian}.
 
-@node Release 2.1
-@section Release 2.1
+@node Release 3.0
+@section Release 3.0
 @itemize
 @item
 Ability to override @option{via} configuration option for destination
@@ -13,6 +13,16 @@ node via @option{-via} command line option for following commands:
 @item
 Chunked files, having size less than specified chunk size, will be sent
 as an ordinary single file.
+@item
+@strong{Incompatible} plain packet format changes. @emph{NICE} field is
+added. Older versions are not supported.
+@item
+Sendmail command is invoked with additional @env{NNCP_FILE} environment
+variable containing niceness level from incoming message packet.
+@item
+Files, that are sent as a reply to freq, have niceness level taken from
+the freq packet. You can set desired niceness during @command{nncp-freq}
+invocation using @option{-replynice} option.
 @end itemize
 
 @node Release 2.0
index 0f5d693e50b992128c8e4d0afff6e38320faf374..9c8c32e262da4a90ce1578b469eeec9c46f79f6f 100644 (file)
@@ -19,9 +19,9 @@ drive.
 
 @verbatim
             HEADER
-+-------------------------------+--...---+
-| MAGIC | TYPE | PATHLEN | PATH | PAYLOAD|
-+-------------------------------+--...---+
++--------------------------------------+--...---+
+| MAGIC | TYPE | NICE | PATHLEN | PATH | PAYLOAD|
++--------------------------------------+--...---+
 @end verbatim
 
 @multitable @columnfractions 0.2 0.3 0.5
@@ -32,6 +32,9 @@ drive.
 @item Payload type @tab
     unsigned integer @tab
     0 (file), 1 (freq), 2 (mail), 3 (transition)
+@item Niceness @tab
+    unsigned integer @tab
+    1-255, preferred packet @ref{Niceness, niceness} level
 @item Path length @tab
     unsigned integer @tab
     actual length of @emph{path} field's payload
@@ -59,6 +62,14 @@ Depending on the packet's type, payload could store:
 @item Whole encrypted packet we need to relay on
 @end itemize
 
+Also depending on packet's type, niceness level means:
+
+@itemize
+@item Preferable niceness level for files sent by freq
+@item @env{NNCP_NICE} variable's value passed during
+    @ref{CfgSendmail} invocation.
+@end itemize
+
 @node Encrypted
 @section Encrypted packet
 
index 18d93b64be32a83fedcce40aece9bf97b64e61b1..9f09660d98cc1e83b951f9d17e50d7d88cb885be 100644 (file)
@@ -39,16 +39,17 @@ func usage() {
 
 func main() {
        var (
-               cfgPath     = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw     = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness")
-               minSize     = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
-               viaOverride = flag.String("via", "", "Override Via path to destination node")
-               spoolPath   = flag.String("spool", "", "Override path to spool")
-               logPath     = flag.String("log", "", "Override path to logfile")
-               quiet       = flag.Bool("quiet", false, "Print only errors")
-               debug       = flag.Bool("debug", false, "Print debug messages")
-               version     = flag.Bool("version", false, "Print version information")
-               warranty    = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath      = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               niceRaw      = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness")
+               replyNiceRaw = flag.Int("replynice", nncp.DefaultNiceFile, "Reply file packet niceness")
+               minSize      = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
+               viaOverride  = flag.String("via", "", "Override Via path to destination node")
+               spoolPath    = flag.String("spool", "", "Override path to spool")
+               logPath      = flag.String("log", "", "Override path to logfile")
+               quiet        = flag.Bool("quiet", false, "Print only errors")
+               debug        = flag.Bool("debug", false, "Print debug messages")
+               version      = flag.Bool("version", false, "Print version information")
+               warranty     = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -68,6 +69,10 @@ func main() {
                log.Fatalln("-nice must be between 1 and 255")
        }
        nice := uint8(*niceRaw)
+       if *replyNiceRaw < 1 || *replyNiceRaw > 255 {
+               log.Fatalln("-replynice must be between 1 and 255")
+       }
+       replyNice := uint8(*replyNiceRaw)
 
        ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
@@ -109,6 +114,7 @@ func main() {
        if err = ctx.TxFreq(
                node,
                nice,
+               replyNice,
                splitted[1],
                dst,
                int64(*minSize)*1024,
index e52ee6a746d2af72a9243bdf7faf7d57115d3694..4f4a523e8e1da863ea0ed8ada10537bea627a9e0 100644 (file)
@@ -68,7 +68,7 @@ func main() {
        }
        var pkt nncp.Pkt
        _, err = xdr.Unmarshal(bytes.NewReader(beginning), &pkt)
-       if err == nil && pkt.Magic == nncp.MagicNNCPPv1 {
+       if err == nil && pkt.Magic == nncp.MagicNNCPPv2 {
                if *dump {
                        bufW := bufio.NewWriter(os.Stdout)
                        var r io.Reader
@@ -106,7 +106,10 @@ func main() {
                default:
                        path = string(pkt.Path[:pkt.PathLen])
                }
-               fmt.Printf("Packet type: plain\nPayload type: %s\nPath: %s\n", payloadType, path)
+               fmt.Printf(
+                       "Packet type: plain\nPayload type: %s\nNiceness: %d\nPath: %s\n",
+                       payloadType, pkt.Nice, path,
+               )
                return
        }
        var pktEnc nncp.PktEnc
index 7150f67bc41875ece8e7daa2531e7374f180e37d..0e98d4beacb4c7d7483793c293e3b2fd99990134 100644 (file)
@@ -55,7 +55,7 @@ const (
 )
 
 var (
-       MagicNNCPPv1 [8]byte = [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 1}
+       MagicNNCPPv2 [8]byte = [8]byte{'N', 'N', 'C', 'P', 'P', 0, 0, 2}
        MagicNNCPEv3 [8]byte = [8]byte{'N', 'N', 'C', 'P', 'E', 0, 0, 3}
        BadMagic     error   = errors.New("Unknown magic number")
        BadPktType   error   = errors.New("Unknown packet type")
@@ -67,6 +67,7 @@ var (
 type Pkt struct {
        Magic   [8]byte
        Type    PktType
+       Nice    uint8
        PathLen uint8
        Path    *[MaxPathSize]byte
 }
@@ -120,14 +121,15 @@ func init() {
        PktEncOverhead = int64(n)
 }
 
-func NewPkt(typ PktType, path string) (*Pkt, error) {
+func NewPkt(typ PktType, nice uint8, path string) (*Pkt, error) {
        pb := []byte(path)
        if len(pb) > MaxPathSize {
                return nil, errors.New("Too long path")
        }
        pkt := Pkt{
-               Magic:   MagicNNCPPv1,
+               Magic:   MagicNNCPPv2,
                Type:    typ,
+               Nice:    nice,
                PathLen: uint8(len(pb)),
                Path:    new([MaxPathSize]byte),
        }
index 9e90fd9e975e530b39e74d764717c0426cec8aaa..6f8506a10918073fc20124b52ba2d1deb94b01e5 100644 (file)
@@ -41,7 +41,7 @@ func TestPktEncWrite(t *testing.T) {
                if len(path) > int(pathSize) {
                        path = path[:int(pathSize)]
                }
-               pkt, err := NewPkt(PktTypeFile, path)
+               pkt, err := NewPkt(PktTypeFile, 123, path)
                if err != nil {
                        panic(err)
                }
@@ -87,7 +87,7 @@ func TestPktEncRead(t *testing.T) {
                if len(path) > int(pathSize) {
                        path = path[:int(pathSize)]
                }
-               pkt, err := NewPkt(PktTypeFile, path)
+               pkt, err := NewPkt(PktTypeFile, 123, path)
                if err != nil {
                        panic(err)
                }
index 5e98840cbc6015f68faea1e2090162fcdd7b4c0a..eb44f26a9878e2d95a3d7ab0c87f3354c620ab2c 100644 (file)
@@ -118,6 +118,7 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool {
                                        )...,
                                )
                                cmd.Env = append(cmd.Env, "NNCP_SENDER="+sender.Id.String())
+                               cmd.Env = append(cmd.Env, "NNCP_NICE="+strconv.Itoa(int(pkt.Nice)))
                                cmd.Stdin = decompressor
                                if err = cmd.Run(); err != nil {
                                        ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "sendmail")
@@ -249,7 +250,7 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool {
                                if sender.FreqChunked == 0 {
                                        err = ctx.TxFile(
                                                sender,
-                                               job.PktEnc.Nice,
+                                               pkt.Nice,
                                                filepath.Join(*freq, src),
                                                dst,
                                                sender.FreqMinSize,
@@ -257,7 +258,7 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool {
                                } else {
                                        err = ctx.TxFileChunked(
                                                sender,
-                                               job.PktEnc.Nice,
+                                               pkt.Nice,
                                                filepath.Join(*freq, src),
                                                dst,
                                                sender.FreqMinSize,
index d50b40b8312ab0591efb96a3921a1d7849b28d26..0e75be2fc97b4a5a7a141d0c0d39d3736c375aaa 100644 (file)
@@ -293,7 +293,7 @@ func TestTossFileSameName(t *testing.T) {
 }
 
 func TestTossFreq(t *testing.T) {
-       f := func(fileSizes []uint8) bool {
+       f := func(fileSizes []uint8, replyNice uint8) bool {
                if len(fileSizes) == 0 {
                        return true
                }
@@ -328,6 +328,7 @@ func TestTossFreq(t *testing.T) {
                        if err := ctx.TxFreq(
                                ctx.Neigh[*nodeOur.Id],
                                DefaultNiceFreq,
+                               replyNice,
                                fileName,
                                fileName,
                                1<<15,
@@ -374,6 +375,9 @@ func TestTossFreq(t *testing.T) {
                                t.Error(err)
                                return false
                        }
+                       if pkt.Nice != replyNice {
+                               return false
+                       }
                        dst := string(pkt.Path[:int(pkt.PathLen)])
                        if bytes.Compare(buf.Bytes(), files[dst]) != 0 {
                                return false
@@ -426,7 +430,7 @@ func TestTossTrns(t *testing.T) {
                os.MkdirAll(txPath, os.FileMode(0700))
                for _, data := range datum {
                        pktTrans := Pkt{
-                               Magic:   MagicNNCPPv1,
+                               Magic:   MagicNNCPPv2,
                                Type:    PktTypeTrns,
                                PathLen: blake2b.Size256,
                                Path:    new([MaxPathSize]byte),
index 0569ccef2860d589e092e9529c49f247f022cb6f..a7e8b15eadb6215f6551b7dcdd59490bae5eb0a7 100644 (file)
@@ -69,7 +69,7 @@ func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size, minSize int64, src io
        var pipeRPrev io.Reader
        for i := 1; i < len(hops); i++ {
                pktTrans := Pkt{
-                       Magic:   MagicNNCPPv1,
+                       Magic:   MagicNNCPPv2,
                        Type:    PktTypeTrns,
                        PathLen: blake2b.Size256,
                        Path:    new([MaxPathSize]byte),
@@ -157,7 +157,7 @@ func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string, minSize
        if filepath.IsAbs(dstPath) {
                return errors.New("Relative destination path required")
        }
-       pkt, err := NewPkt(PktTypeFile, dstPath)
+       pkt, err := NewPkt(PktTypeFile, nice, dstPath)
        if err != nil {
                return err
        }
@@ -212,7 +212,7 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m
        }
 
        if fileSize <= chunkSize {
-               pkt, err := NewPkt(PktTypeFile, dstPath)
+               pkt, err := NewPkt(PktTypeFile, nice, dstPath)
                if err != nil {
                        return err
                }
@@ -263,7 +263,7 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m
                        sizeToSend = chunkSize
                }
                path = dstPath + ChunkedSuffixPart + strconv.Itoa(chunkNum)
-               pkt, err = NewPkt(PktTypeFile, path)
+               pkt, err = NewPkt(PktTypeFile, nice, path)
                if err != nil {
                        return err
                }
@@ -313,7 +313,7 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m
                return err
        }
        path = dstPath + ChunkedSuffixMeta
-       pkt, err = NewPkt(PktTypeFile, path)
+       pkt, err = NewPkt(PktTypeFile, nice, path)
        if err != nil {
                return err
        }
@@ -342,7 +342,7 @@ func (ctx *Ctx) TxFileChunked(node *Node, nice uint8, srcPath, dstPath string, m
        return err
 }
 
-func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string, minSize int64) error {
+func (ctx *Ctx) TxFreq(node *Node, nice, replyNice uint8, srcPath, dstPath string, minSize int64) error {
        dstPath = filepath.Clean(dstPath)
        if filepath.IsAbs(dstPath) {
                return errors.New("Relative destination path required")
@@ -351,7 +351,7 @@ func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string, minSize
        if filepath.IsAbs(srcPath) {
                return errors.New("Relative source path required")
        }
-       pkt, err := NewPkt(PktTypeFreq, srcPath)
+       pkt, err := NewPkt(PktTypeFreq, replyNice, srcPath)
        if err != nil {
                return err
        }
@@ -380,7 +380,7 @@ func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string, minSize
 }
 
 func (ctx *Ctx) TxMail(node *Node, nice uint8, recipient string, body []byte, minSize int64) error {
-       pkt, err := NewPkt(PktTypeMail, recipient)
+       pkt, err := NewPkt(PktTypeMail, nice, recipient)
        if err != nil {
                return err
        }
index d97be3debc487f5955388b4a7808e333745d6492..0a4485f6b04f816333b1d31df468ab430a02f9f9 100644 (file)
@@ -76,7 +76,7 @@ func TestTx(t *testing.T) {
                        privates[*node.Id] = node
                        nodeTgt.Via = append(nodeTgt.Via, node.Id)
                }
-               pkt, err := NewPkt(PktTypeMail, pathSrc)
+               pkt, err := NewPkt(PktTypeMail, 123, pathSrc)
                src := strings.NewReader(data)
                dstNode, err := ctx.Tx(
                        nodeTgt,