From 9004931fa87dd347c086ee750c6ee08e698683a1 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 25 Jan 2022 19:35:04 +0300 Subject: [PATCH] nncp-call -mcd-wait --- doc/cmd/nncp-call.texi | 5 +++++ doc/news.ru.texi | 4 ++++ doc/news.texi | 4 ++++ src/cmd/nncp-call/main.go | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/doc/cmd/nncp-call.texi b/doc/cmd/nncp-call.texi index a4ea6d9..6c58b5c 100644 --- a/doc/cmd/nncp-call.texi +++ b/doc/cmd/nncp-call.texi @@ -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. diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 1dd6478..1a65bfa 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -11,6 +11,10 @@ выражениями. По умолчанию @command{nncp-cfgnew} не комментирует их теперь и прописывает @code{.*} имя интерфейса. +@item +У @command{nncp-call} команды появился @option{-mcd-wait} аргумент, +позволяющий дожидаться multicast сообщения об адресе ноды. + @end itemize @node Релиз 8.3.0 diff --git a/doc/news.texi b/doc/news.texi index 2101ce0..6922d4b 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -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 diff --git a/src/cmd/nncp-call/main.go b/src/cmd/nncp-call/main.go index 077a907..8a5b867 100644 --- a/src/cmd/nncp-call/main.go +++ b/src/cmd/nncp-call/main.go @@ -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, ",") -- 2.44.0