]> Cypherpunks.ru repositories - nncp.git/commitdiff
Ability to skip tossing of specified packet types
authorSergey Matveev <stargrave@stargrave.org>
Fri, 16 Feb 2018 19:55:17 +0000 (22:55 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 17 Feb 2018 08:31:19 +0000 (11:31 +0300)
doc/cmds.texi
doc/news.ru.texi
doc/news.texi
src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go
src/cypherpunks.ru/nncp/toss.go
src/cypherpunks.ru/nncp/toss_test.go

index ce0855a972db3c43334c86f44e7422a0f864de53..49a34c618c3806e62483ce5d90a9268ff68460df 100644 (file)
@@ -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
 
index de2d9d40ef6845cc6df813cbfb75fa418763319b..4b2acf4d5ad4063c8a062598b21839dd290c78ff 100644 (file)
@@ -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
index 9a5bd2d69aeccc312ae25207ed56518fb59b7acd..f45e40e6d667fae20a9421b048d0c0240d78954c 100644 (file)
@@ -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
index 1127c46edb6018f4abe1110f1e062ee2a995bf1f..398923f1da002f8ed47c5fd69673cda1aed003d8 100644 (file)
@@ -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)
index dcdee6cd04c75dc3b55316741d78a0ccbc0685cb..a207785c32cf92ad2c5bb8a658f7ee84ea557cc6 100644 (file)
@@ -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)
index 0e75be2fc97b4a5a7a141d0c0d39d3736c375aaa..037c777321a62752541cd3d46b2bfc3eb31efd5c 100644 (file)
@@ -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
                }