]> Cypherpunks.ru repositories - nncp.git/commitdiff
nncp-call -mcd-wait
authorSergey Matveev <stargrave@stargrave.org>
Tue, 25 Jan 2022 16:35:04 +0000 (19:35 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 25 Jan 2022 18:27:36 +0000 (21:27 +0300)
doc/cmd/nncp-call.texi
doc/news.ru.texi
doc/news.texi
src/cmd/nncp-call/main.go

index a4ea6d97969d383370a30d2576061b54874783b3..6c58b5c152f269e59c72b3d2fe6f3fee4fff5497 100644 (file)
@@ -13,6 +13,7 @@ $ nncp-call [options]
     [-autotoss*]
     [-nock]
     [-ucspi]
+    [-mcd-wait INT]
     NODE[:ADDR] [FORCEADDR]
 @end example
 
@@ -48,6 +49,10 @@ If you specify @option{-ucspi} option, then it is assumed that you run
 @command{nncp-call} command under some UCSPI-TCP compatible utility,
 that provides read/write channels through 6/7 file descriptors.
 
+@option{-mcd-wait} options tells to wait up to specified number of
+seconds for the @ref{MCD} packet from the specified @code{NODE}. When
+the packet is received, initiate a call.
+
 @option{-autotoss} option runs tosser on node's spool every second
 during the call. All @option{-autotoss-*} options is the same as in
 @ref{nncp-toss} command.
index 1dd64787e88409d9a168fc1d7ad572b4d78374b5..1a65bfa033f968916563b0ed7348358d90303cf6 100644 (file)
 выражениями. По умолчанию @command{nncp-cfgnew} не комментирует
 их теперь и прописывает @code{.*} имя интерфейса.
 
+@item
+У @command{nncp-call} команды появился @option{-mcd-wait} аргумент,
+позволяющий дожидаться multicast сообщения об адресе ноды.
+
 @end itemize
 
 @node Релиз 8.3.0
index 2101ce085c6b4b8c923b4d9eca9569c841c94a00..6922d4bfe30584745612dd57496b44f83c6e8de5 100644 (file)
@@ -12,6 +12,10 @@ Multicast related interface names (@code{mcd-listen} and @code{mcd-send}
 configuration options) are now regular expressions. By default
 @command{nncp-cfgnew} uncomments them now with @code{.*} interface name.
 
+@item
+@command{nncp-call} command has @option{-mcd-wait} option to wait for
+multicast packet about node's address.
+
 @end itemize
 
 @node Release 8_3_0
index 077a907fdcd45761de28ac2bcf1629415bcb954f..8a5b8670de7a379d5e6f9afdff1e6f2f6f64fe1b 100644 (file)
@@ -22,7 +22,9 @@ import (
        "flag"
        "fmt"
        "log"
+       "net"
        "os"
+       "regexp"
        "strings"
        "time"
 
@@ -47,6 +49,7 @@ func main() {
                listOnly    = flag.Bool("list", false, "Only list remote packets")
                noCK        = flag.Bool("nock", false, "Do no checksum checking")
                onlyPktsRaw = flag.String("pkts", "", "Recieve only that packets, comma separated")
+               mcdWait     = flag.Uint("mcd-wait", 60, "Wait for MCD for specified number of seconds")
                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")
@@ -150,6 +153,41 @@ func main() {
                }
        }
 
+       if *mcdWait > 0 {
+               ifis, err := net.Interfaces()
+               if err != nil {
+                       log.Fatalln("Can not get network interfaces list:", err)
+               }
+               for _, ifiReString := range ctx.MCDRxIfis {
+                       ifiRe, err := regexp.CompilePOSIX(ifiReString)
+                       if err != nil {
+                               log.Fatalf("Can not compile POSIX regexp \"%s\": %s", ifiReString, err)
+                       }
+                       for _, ifi := range ifis {
+                               if ifiRe.MatchString(ifi.Name) {
+                                       if err = ctx.MCDRx(ifi.Name); err != nil {
+                                               log.Printf("Can not run MCD reception on %s: %s", ifi.Name, err)
+                                       }
+                               }
+                       }
+               }
+               addrs = nil
+               for i := int(*mcdWait); i > 0; i-- {
+                       nncp.MCDAddrsM.RLock()
+                       for _, mcdAddr := range nncp.MCDAddrs[*node.Id] {
+                               addrs = append(addrs, mcdAddr.Addr.String())
+                       }
+                       if len(addrs) > 0 {
+                               break
+                       }
+                       nncp.MCDAddrsM.RUnlock()
+                       time.Sleep(time.Second)
+               }
+               if len(addrs) == 0 {
+                       log.Fatalf("No MCD packets from the node during %d seconds", *mcdWait)
+               }
+       }
+
        var onlyPkts map[[32]byte]bool
        if len(*onlyPktsRaw) > 0 {
                splitted = strings.Split(*onlyPktsRaw, ",")