From: Sergey Matveev Date: Thu, 15 Feb 2018 21:02:03 +0000 (+0300) Subject: Freqed files have different niceness X-Git-Tag: 3.0^2~11 X-Git-Url: http://www.git.cypherpunks.ru/?a=commitdiff_plain;h=ded811e9e4736ad182636fe7bf8221ac9a95e08b;p=nncp.git Freqed files have different niceness --- diff --git a/VERSION b/VERSION index 879b416..9f55b2c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1 +3.0 diff --git a/doc/cfg.texi b/doc/cfg.texi index f898493..3483f11 100644 --- a/doc/cfg.texi +++ b/doc/cfg.texi @@ -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 diff --git a/doc/news.ru.texi b/doc/news.ru.texi index fd37894..de2d9d4 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -1,8 +1,8 @@ @node Новости @section Новости -@node Релиз 2.1 -@subsection Релиз 2.1 +@node Релиз 3.0 +@subsection Релиз 3.0 @itemize @item Возможность переопределить @option{via} опцию конфигурации для целевого @@ -11,6 +11,16 @@ @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}, diff --git a/doc/news.texi b/doc/news.texi index 475583e..9a5bd2d 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -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 diff --git a/doc/pkt.texi b/doc/pkt.texi index 0f5d693..9c8c32e 100644 --- a/doc/pkt.texi +++ b/doc/pkt.texi @@ -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 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go index 18d93b6..9f09660 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go @@ -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, diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go index e52ee6a..4f4a523 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go @@ -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 diff --git a/src/cypherpunks.ru/nncp/pkt.go b/src/cypherpunks.ru/nncp/pkt.go index 7150f67..0e98d4b 100644 --- a/src/cypherpunks.ru/nncp/pkt.go +++ b/src/cypherpunks.ru/nncp/pkt.go @@ -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), } diff --git a/src/cypherpunks.ru/nncp/pkt_test.go b/src/cypherpunks.ru/nncp/pkt_test.go index 9e90fd9..6f8506a 100644 --- a/src/cypherpunks.ru/nncp/pkt_test.go +++ b/src/cypherpunks.ru/nncp/pkt_test.go @@ -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) } diff --git a/src/cypherpunks.ru/nncp/toss.go b/src/cypherpunks.ru/nncp/toss.go index 5e98840..eb44f26 100644 --- a/src/cypherpunks.ru/nncp/toss.go +++ b/src/cypherpunks.ru/nncp/toss.go @@ -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, diff --git a/src/cypherpunks.ru/nncp/toss_test.go b/src/cypherpunks.ru/nncp/toss_test.go index d50b40b..0e75be2 100644 --- a/src/cypherpunks.ru/nncp/toss_test.go +++ b/src/cypherpunks.ru/nncp/toss_test.go @@ -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), diff --git a/src/cypherpunks.ru/nncp/tx.go b/src/cypherpunks.ru/nncp/tx.go index 0569cce..a7e8b15 100644 --- a/src/cypherpunks.ru/nncp/tx.go +++ b/src/cypherpunks.ru/nncp/tx.go @@ -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 } diff --git a/src/cypherpunks.ru/nncp/tx_test.go b/src/cypherpunks.ru/nncp/tx_test.go index d97be3d..0a4485f 100644 --- a/src/cypherpunks.ru/nncp/tx_test.go +++ b/src/cypherpunks.ru/nncp/tx_test.go @@ -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,