]> Cypherpunks repositories - nncp.git/commitdiff
nncp-call -pkts option
authorSergey Matveev <stargrave@stargrave.org>
Sat, 27 Apr 2019 20:38:57 +0000 (23:38 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 27 Apr 2019 20:38:57 +0000 (23:38 +0300)
doc/cmds.texi
doc/news.ru.texi
doc/news.texi
src/cypherpunks.ru/nncp/call.go
src/cypherpunks.ru/nncp/cmd/nncp-call/main.go
src/cypherpunks.ru/nncp/cmd/nncp-caller/main.go
src/cypherpunks.ru/nncp/sp.go

index 4e8210257863840baee6d6c58c84fecc09a62edb..ac665ace0d3a1c166a31f10ba8f685a11c5a3bdc 100644 (file)
@@ -96,6 +96,7 @@ their integrity.
     [-maxonlinetime INT]
     [-rx|-tx]
     [-list]
+    [-pkts PKT,PKT,...]
     [-rxrate INT]
     [-txrate INT]
     NODE[:ADDR] [FORCEADDR]
@@ -117,6 +118,9 @@ overrides @ref{CfgOnlineDeadline, @emph{onlinedeadline}}.
 @ref{CfgXxRate, rxrate/txrate}. @option{-list} option allows you to list
 packets of remote node, without any transmission.
 
+You can specify what packets your want to download, by specifying
+@option{-pkts} option with comma-separated list of packets identifiers.
+
 @node nncp-caller
 @section nncp-caller
 
index 4eb8fecab28fee1d7669e185de11b3c2b102a0a4..480a565f109d0f2d288d6ce94b94ecc1e7df7da3 100644 (file)
@@ -17,6 +17,8 @@
 @command{nncp-call} теперь может только показывать список пакетов на
 удалённой машине, без их передачи.
 @item
+@command{nncp-call} может скачивать только чётко указанные пакеты.
+@item
 Зависимые библиотеки обновлены.
 @item
 Небольшие исправления ошибок.
index 571a094065f20a31912db59f264c62ec0aa583d5..baf52c094c514685a61d462ca91d0b3f30595a26 100644 (file)
@@ -18,6 +18,8 @@ Available free space checking before copying in @command{nncp-xfer},
 @command{nncp-call} has ability only to listen packets on remote node,
 without its transmission.
 @item
+@command{nncp-call} has ability to download only specified packets.
+@item
 Dependant libraries are updated.
 @item
 Minor bugfixes.
index 853dbaec3df58d9b5b512818c2be6d1b78bd1a9c..4a56950aca4a72b23a768ae7c3e18220a49883be 100644 (file)
@@ -43,7 +43,8 @@ func (ctx *Ctx) CallNode(
        xxOnly TRxTx,
        rxRate, txRate int,
        onlineDeadline, maxOnlineTime uint,
-       listOnly bool) (isGood bool) {
+       listOnly bool,
+       onlyPkts map[[32]byte]bool) (isGood bool) {
        for _, addr := range addrs {
                sds := SDS{"node": node.Id, "addr": addr}
                ctx.LogD("call", sds, "dialing")
@@ -63,6 +64,7 @@ func (ctx *Ctx) CallNode(
                        onlineDeadline,
                        maxOnlineTime,
                        listOnly,
+                       onlyPkts,
                )
                if err == nil {
                        ctx.LogI("call-start", sds, "connected")
index d853443e381a469cc455ad676e895707e32cb9e4..7919b6a55386c836c5fd4644b15bb29cead89e04 100644 (file)
@@ -39,19 +39,20 @@ func usage() {
 
 func main() {
        var (
-               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw   = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness")
-               rxOnly    = flag.Bool("rx", false, "Only receive packets")
-               txOnly    = flag.Bool("tx", false, "Only transmit packets")
-               listOnly  = flag.Bool("list", false, "Only list remote packets")
-               rxRate    = flag.Int("rxrate", 0, "Maximal receive rate, pkts/sec")
-               txRate    = flag.Int("txrate", 0, "Maximal transmit rate, pkts/sec")
-               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.String("nice", nncp.NicenessFmt(255), "Minimal required niceness")
+               rxOnly      = flag.Bool("rx", false, "Only receive packets")
+               txOnly      = flag.Bool("tx", false, "Only transmit packets")
+               listOnly    = flag.Bool("list", false, "Only list remote packets")
+               onlyPktsRaw = flag.String("pkts", "", "Recieve only that packets, comma separated")
+               rxRate      = flag.Int("rxrate", 0, "Maximal receive rate, pkts/sec")
+               txRate      = flag.Int("txrate", 0, "Maximal transmit rate, pkts/sec")
+               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")
 
                onlineDeadline = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option")
                maxOnlineTime  = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option")
@@ -124,6 +125,21 @@ func main() {
                }
        }
 
+       var onlyPkts map[[32]byte]bool
+       if len(*onlyPktsRaw) > 0 {
+               splitted = strings.Split(*onlyPktsRaw, ",")
+               onlyPkts = make(map[[32]byte]bool, len(splitted))
+               for _, pktIdRaw := range splitted {
+                       pktId, err := nncp.FromBase32(pktIdRaw)
+                       if err != nil {
+                               log.Fatalln("Invalid packet specified: ", err)
+                       }
+                       pktIdArr := new([32]byte)
+                       copy(pktIdArr[:], pktId)
+                       onlyPkts[*pktIdArr] = true
+               }
+       }
+
        if !ctx.CallNode(
                node,
                addrs,
@@ -134,6 +150,7 @@ func main() {
                *onlineDeadline,
                *maxOnlineTime,
                *listOnly,
+               onlyPkts,
        ) {
                os.Exit(1)
        }
index 24334cf9b198651b6d5d60bde38f50570b006e3a..19307153a7e57c3f02eebf6f584f338a0ff31e4d 100644 (file)
@@ -133,6 +133,7 @@ func main() {
                                                        call.OnlineDeadline,
                                                        call.MaxOnlineTime,
                                                        false,
+                                                       nil,
                                                )
                                                node.Lock()
                                                node.Busy = false
index 22078c55110a41dfe2096a05d317211acee07cdc..f188fd3580075c0e261e37b9688cc77fde61b8c5 100644 (file)
@@ -198,6 +198,7 @@ type SPState struct {
        txRate         int
        isDead         bool
        listOnly       bool
+       onlyPkts       map[[32]byte]bool
        sync.RWMutex
 }
 
@@ -288,7 +289,9 @@ func (ctx *Ctx) StartI(
        xxOnly TRxTx,
        rxRate, txRate int,
        onlineDeadline, maxOnlineTime uint,
-       listOnly bool) (*SPState, error) {
+       listOnly bool,
+       onlyPkts map[[32]byte]bool,
+) (*SPState, error) {
        err := ctx.ensureRxDir(nodeId)
        if err != nil {
                return nil, err
@@ -340,6 +343,7 @@ func (ctx *Ctx) StartI(
                rxRate:         rxRate,
                txRate:         txRate,
                listOnly:       listOnly,
+               onlyPkts:       onlyPkts,
        }
 
        var infosPayloads [][]byte
@@ -839,7 +843,7 @@ func (state *SPState) ProcessSP(payload []byte) ([][]byte, error) {
                                SdsAdd(sdsp, SDS{"offset": strconv.FormatInt(offset, 10)}),
                                "",
                        )
-                       if !state.listOnly {
+                       if !state.listOnly && (state.onlyPkts == nil || state.onlyPkts[*info.Hash]) {
                                replies = append(replies, MarshalSP(
                                        SPTypeFreq,
                                        SPFreq{info.Hash, uint64(offset)},