From 3fa849bb64028212caa96cf6b2e6c95e3f09cb7d Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 2 Apr 2017 17:21:19 +0300 Subject: [PATCH] nncp-rm command --- VERSION | 2 +- common.mk | 6 +- doc/cmds.texi | 11 +++ doc/news.texi | 7 ++ ports/nncp/Makefile | 3 +- src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go | 96 +++++++++++++++++++++ 6 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go diff --git a/VERSION b/VERSION index 2eb3c4f..5a2a580 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5 +0.6 diff --git a/common.mk b/common.mk index c13ba52..e949d12 100644 --- a/common.mk +++ b/common.mk @@ -17,7 +17,6 @@ LDFLAGS = \ -X cypherpunks.ru/nncp.DefaultLogPath=$(LOGPATH) ALL = \ - nncp-mail \ nncp-call \ nncp-caller \ nncp-check \ @@ -25,9 +24,11 @@ ALL = \ nncp-file \ nncp-freq \ nncp-log \ + nncp-mail \ nncp-mincfg \ nncp-newcfg \ nncp-pkt \ + nncp-rm \ nncp-stat \ nncp-toss \ nncp-xfer @@ -67,6 +68,9 @@ nncp-newcfg: nncp-pkt: GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-pkt +nncp-rm: + GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-rm + nncp-stat: GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/nncp/cmd/nncp-stat diff --git a/doc/cmds.texi b/doc/cmds.texi index 42197da..4fa1045 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -289,3 +289,14 @@ configuration file version without any private keys. @file{DIR} directory has the following structure: @file{RECIPIENT/SENDER/PACKET}, where @file{RECIPIENT} is Base32 encoded destination node, @file{SENDER} is Base32 encoded sender node. + +@node nncp-rm +@section nncp-rm + +@verbatim +% nncp-rm [options] NODE PKT +@end verbatim + +Remove specified packet (Base32 name) in @option{NODE}'s queues. This +command is useful when you want to remove the packet that is failing to +be processed. diff --git a/doc/news.texi b/doc/news.texi index 0105b90..ec43ffc 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -1,6 +1,13 @@ @node News @unnumbered News +@node Release 0.6 +@section Release 0.6 +@itemize +@item Small @command{nncp-rm} command appeared. +@item Cryptographic libraries (dependecies) are updated. +@end itemize + @node Release 0.5 @section Release 0.5 @itemize diff --git a/ports/nncp/Makefile b/ports/nncp/Makefile index 309cff8..00d8d55 100644 --- a/ports/nncp/Makefile +++ b/ports/nncp/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ PORTNAME= nncp -PORTVERSION= 0.5 +PORTVERSION= 0.6 CATEGORIES= net MASTER_SITES= http://www.nncpgo.org/download/ \ http://sourceforge.net/projects/nncp/files/ @@ -37,6 +37,7 @@ PLIST_FILES= bin/nncp-call \ bin/nncp-mincfg \ bin/nncp-newcfg \ bin/nncp-pkt \ + bin/nncp-rm \ bin/nncp-stat \ bin/nncp-toss \ bin/nncp-xfer \ diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go new file mode 100644 index 0000000..00a13a4 --- /dev/null +++ b/src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go @@ -0,0 +1,96 @@ +/* +NNCP -- Node to Node copy, utilities for store-and-forward data exchange +Copyright (C) 2016-2017 Sergey Matveev + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +// Remove packet from the queue +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + + "cypherpunks.ru/nncp" +) + +func usage() { + fmt.Fprintf(os.Stderr, nncp.UsageHeader()) + fmt.Fprintln(os.Stderr, "nncp-rm -- remove packet\n") + fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE PKT\nOptions:\n", os.Args[0]) + flag.PrintDefaults() +} + +func main() { + var ( + cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") + 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() + if *warranty { + fmt.Println(nncp.Warranty) + return + } + if *version { + fmt.Println(nncp.VersionGet()) + return + } + if flag.NArg() != 2 { + usage() + os.Exit(1) + } + + cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath)) + if err != nil { + log.Fatalln("Can not read config:", err) + } + ctx, err := nncp.CfgParse(cfgRaw) + if err != nil { + log.Fatalln("Can not parse config:", err) + } + ctx.Quiet = *quiet + ctx.Debug = *debug + + node, err := ctx.FindNode(flag.Arg(0)) + if err != nil { + log.Fatalln("Invalid NODE specified:", err) + } + + pktName := flag.Arg(1) + remove := func(xx nncp.TRxTx) bool { + for job := range ctx.Jobs(node.Id, xx) { + job.Fd.Close() + if filepath.Base(job.Fd.Name()) == pktName { + if err = os.Remove(job.Fd.Name()); err != nil { + log.Fatalln("Can not remove packet:", err) + } + return true + } + } + return false + } + + if !(remove(nncp.TRx) || remove(nncp.TTx)) { + log.Fatalln("Have not found specified packet") + } +} -- 2.44.0