From 868ca53b56cccb2a9da7077a17e2cf02998da296 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 16 Feb 2018 22:55:17 +0300 Subject: [PATCH] Ability to skip tossing of specified packet types --- doc/cmds.texi | 12 ++++++++++- doc/news.ru.texi | 4 ++++ doc/news.texi | 4 ++++ src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go | 15 +++++++++++++- src/cypherpunks.ru/nncp/toss.go | 14 ++++++++++++- src/cypherpunks.ru/nncp/toss_test.go | 20 +++++++++---------- 6 files changed, 56 insertions(+), 13 deletions(-) diff --git a/doc/cmds.texi b/doc/cmds.texi index ce0855a..49a34c6 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -451,7 +451,14 @@ queues. @section nncp-toss @verbatim -% nncp-toss [options] [-dryrun] [-cycle INT] [-seen] +% nncp-toss [options] + [-dryrun] + [-cycle INT] + [-seen] + [-nofile] + [-nofreq] + [-nomail] + [-notrns] @end verbatim Perform "tossing" operation on all inbound packets. This is the tool @@ -471,6 +478,9 @@ successful tossing of @file{XXX} packet. @ref{nncp-xfer} and @ref{nncp-bundle} commands skip inbound packets that has been already seen, processed and tossed. This is helpful to defeat duplicates. +@option{-nofile}, @option{-nofreq}, @option{-nomail}, @option{-notrns} +options allow to disable any kind of packet types processing. + @node nncp-xfer @section nncp-xfer diff --git a/doc/news.ru.texi b/doc/news.ru.texi index de2d9d4..4b2acf4 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -21,6 +21,10 @@ Sendmail команда вызывается с дополнительной п Отправляемые файлы в ответ на запрос имеют приоритет указанный в запросе. Указать их желаемый приоритет во время вызова @command{nncp-freq} можно аргументом @option{-replynice}. +@item +Команде @command{nncp-toss} можно сказать не обрабатывать определённые +типы пакетов, за счёт опций @option{-nofile}, @option{-nofreq}, +@option{-nomail}, @option{-notrns}. @end itemize @node Релиз 2.0 diff --git a/doc/news.texi b/doc/news.texi index 9a5bd2d..f45e40e 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -23,6 +23,10 @@ variable containing niceness level from incoming message packet. 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. +@item +@command{nncp-toss} command can ignore specified packet types during +processing: @option{-nofile}, @option{-nofreq}, @option{-nomail}, +@option{-notrns}. @end itemize @node Release 2.0 diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go index 1127c46..398923f 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go @@ -44,6 +44,10 @@ func main() { dryRun = flag.Bool("dryrun", false, "Do not actually write any tossed data") doSeen = flag.Bool("seen", false, "Create .seen files") cycle = flag.Uint("cycle", 0, "Repeat tossing after N seconds in infinite loop") + noFile = flag.Bool("nofile", false, "Do not process packets with type: file") + noFreq = flag.Bool("nofreq", false, "Do not process packets with type: freq") + noMail = flag.Bool("nomail", false, "Do not process packets with type: mail") + noTrns = flag.Bool("notrns", false, "Do not process packets with type: transitional") spoolPath = flag.String("spool", "", "Override path to spool") logPath = flag.String("log", "", "Override path to logfile") quiet = flag.Bool("quiet", false, "Print only errors") @@ -88,7 +92,16 @@ Cycle: if nodeOnly != nil && nodeId != *nodeOnly.Id { continue } - isBad = ctx.Toss(node.Id, nice, *dryRun, *doSeen) + isBad = ctx.Toss( + node.Id, + nice, + *dryRun, + *doSeen, + *noFile, + *noFreq, + *noMail, + *noTrns, + ) } if *cycle > 0 { time.Sleep(time.Duration(*cycle) * time.Second) diff --git a/src/cypherpunks.ru/nncp/toss.go b/src/cypherpunks.ru/nncp/toss.go index dcdee6c..a207785 100644 --- a/src/cypherpunks.ru/nncp/toss.go +++ b/src/cypherpunks.ru/nncp/toss.go @@ -52,7 +52,7 @@ func newNotification(fromTo *FromToYAML, subject string) io.Reader { )) } -func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool { +func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen, noFile, noFreq, noMail, noTrns bool) bool { isBad := false for job := range ctx.Jobs(nodeId, TRx) { pktName := filepath.Base(job.Fd.Name()) @@ -94,6 +94,9 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool { ctx.LogD("rx", sds, "taken") switch pkt.Type { case PktTypeMail: + if noMail { + goto Closing + } recipients := make([]string, 0) for _, recipient := range bytes.Split(pkt.Path[:int(pkt.PathLen)], []byte{0}) { recipients = append(recipients, string(recipient)) @@ -140,6 +143,9 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool { } } case PktTypeFile: + if noFile { + goto Closing + } dst := string(pkt.Path[:int(pkt.PathLen)]) sds := SdsAdd(sds, SDS{"type": "file", "dst": dst}) if filepath.IsAbs(dst) { @@ -225,6 +231,9 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool { } } case PktTypeFreq: + if noFreq { + goto Closing + } src := string(pkt.Path[:int(pkt.PathLen)]) if filepath.IsAbs(src) { ctx.LogE("rx", sds, "non-relative source path") @@ -298,6 +307,9 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool { } } case PktTypeTrns: + if noTrns { + goto Closing + } dst := new([blake2b.Size256]byte) copy(dst[:], pkt.Path[:int(pkt.PathLen)]) nodeId := NodeId(*dst) diff --git a/src/cypherpunks.ru/nncp/toss_test.go b/src/cypherpunks.ru/nncp/toss_test.go index 0e75be2..037c777 100644 --- a/src/cypherpunks.ru/nncp/toss_test.go +++ b/src/cypherpunks.ru/nncp/toss_test.go @@ -108,12 +108,12 @@ func TestTossEmail(t *testing.T) { if len(dirFiles(rxPath)) == 0 { continue } - ctx.Toss(ctx.Self.Id, DefaultNiceMail-1, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceMail-1, false, false, false, false, false, false) if len(dirFiles(rxPath)) == 0 { return false } ctx.Neigh[*nodeOur.Id].Sendmail = []string{"/bin/sh", "-c", "false"} - ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false, false, false, false, false) if len(dirFiles(rxPath)) == 0 { return false } @@ -121,7 +121,7 @@ func TestTossEmail(t *testing.T) { "/bin/sh", "-c", fmt.Sprintf("cat >> %s", filepath.Join(spool, "mbox")), } - ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceMail, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false } @@ -195,12 +195,12 @@ func TestTossFile(t *testing.T) { } rxPath := filepath.Join(spool, ctx.Self.Id.String(), string(TRx)) os.Rename(filepath.Join(spool, ctx.Self.Id.String(), string(TTx)), rxPath) - ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) if len(dirFiles(rxPath)) == 0 { return false } ctx.Neigh[*nodeOur.Id].Incoming = &incomingPath - ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false } @@ -270,7 +270,7 @@ func TestTossFileSameName(t *testing.T) { rxPath := filepath.Join(spool, ctx.Self.Id.String(), string(TRx)) os.Rename(filepath.Join(spool, ctx.Self.Id.String(), string(TTx)), rxPath) ctx.Neigh[*nodeOur.Id].Incoming = &incomingPath - ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFile, false, false, false, false, false, false) expected := make(map[string]struct{}) expected["samefile"] = struct{}{} for i := 0; i < files-1; i++ { @@ -341,12 +341,12 @@ func TestTossFreq(t *testing.T) { txPath := filepath.Join(spool, ctx.Self.Id.String(), string(TTx)) os.Rename(txPath, rxPath) os.MkdirAll(txPath, os.FileMode(0700)) - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 { return false } ctx.Neigh[*nodeOur.Id].Freq = &spool - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) if len(dirFiles(txPath)) != 0 || len(dirFiles(rxPath)) == 0 { return false } @@ -359,7 +359,7 @@ func TestTossFreq(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false) + ctx.Toss(ctx.Self.Id, DefaultNiceFreq, false, false, false, false, false, false) if len(dirFiles(txPath)) == 0 || len(dirFiles(rxPath)) != 0 { return false } @@ -459,7 +459,7 @@ func TestTossTrns(t *testing.T) { panic(err) } } - ctx.Toss(ctx.Self.Id, 123, false, false) + ctx.Toss(ctx.Self.Id, 123, false, false, false, false, false, false) if len(dirFiles(rxPath)) != 0 { return false } -- 2.48.1