X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-call%2Fmain.go;h=4d8fb0648a3eaf547b4d635bec8cf0a584e70a16;hb=2e59e1d8da61bc5dee797d351e50e8ed114aa4c7;hp=7b0a0d827089728ff67e9125ff0f31c241d7b1a6;hpb=ccad5367ba83c3cda46762b47ea9f84b2ecf724a;p=nncp.git diff --git a/src/cmd/nncp-call/main.go b/src/cmd/nncp-call/main.go index 7b0a0d8..4d8fb06 100644 --- a/src/cmd/nncp-call/main.go +++ b/src/cmd/nncp-call/main.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2020 Sergey Matveev +Copyright (C) 2016-2022 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 @@ -22,11 +22,13 @@ import ( "flag" "fmt" "log" + "net" "os" + "regexp" "strings" "time" - "go.cypherpunks.ru/nncp/v5" + "go.cypherpunks.ru/nncp/v8" ) func usage() { @@ -40,11 +42,14 @@ func usage() { func main() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") + ucspi = flag.Bool("ucspi", false, "Is it started as UCSPI-TCP client") 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") + noCK = flag.Bool("nock", false, "Do no checksum checking") onlyPktsRaw = flag.String("pkts", "", "Recieve only that packets, comma separated") + mcdWait = flag.Uint("mcd-wait", 0, "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") @@ -56,9 +61,19 @@ func main() { version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") - onlineDeadline = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option") - maxOnlineTimeSec = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option") + onlineDeadlineSec = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option") + maxOnlineTimeSec = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option") + + autoToss = flag.Bool("autotoss", false, "Toss after call is finished") + autoTossDoSeen = flag.Bool("autotoss-seen", false, "Create seen/ files during tossing") + autoTossNoFile = flag.Bool("autotoss-nofile", false, "Do not process \"file\" packets during tossing") + autoTossNoFreq = flag.Bool("autotoss-nofreq", false, "Do not process \"freq\" packets during tossing") + autoTossNoExec = flag.Bool("autotoss-noexec", false, "Do not process \"exec\" packets during tossing") + autoTossNoTrns = flag.Bool("autotoss-notrns", false, "Do not process \"trns\" packets during tossing") + autoTossNoArea = flag.Bool("autotoss-noarea", false, "Do not process \"area\" packets during tossing") + autoTossNoACK = flag.Bool("autotoss-noack", false, "Do not process \"ack\" packets during tossing") ) + log.SetFlags(log.Lshortfile) flag.Usage = usage flag.Parse() if *warranty { @@ -106,13 +121,12 @@ func main() { log.Fatalln("Node does not have online communication capability") } - if *onlineDeadline == 0 { - onlineDeadline = &node.OnlineDeadline + onlineDeadline := node.OnlineDeadline + if *onlineDeadlineSec != 0 { + onlineDeadline = time.Duration(*onlineDeadlineSec) * time.Second } - var maxOnlineTime time.Duration - if *maxOnlineTimeSec == 0 { - maxOnlineTime = node.MaxOnlineTime - } else { + maxOnlineTime := node.MaxOnlineTime + if *maxOnlineTimeSec != 0 { maxOnlineTime = time.Duration(*maxOnlineTimeSec) * time.Second } @@ -124,7 +138,9 @@ func main() { } var addrs []string - if flag.NArg() == 2 { + if *ucspi { + addrs = append(addrs, nncp.UCSPITCPClient) + } else if flag.NArg() == 2 { addrs = append(addrs, flag.Arg(1)) } else if len(splitted) == 2 { addr, known := ctx.Neigh[*node.Id].Addrs[splitted[1]] @@ -138,12 +154,47 @@ 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, ",") onlyPkts = make(map[[32]byte]bool, len(splitted)) for _, pktIdRaw := range splitted { - pktId, err := nncp.FromBase32(pktIdRaw) + pktId, err := nncp.Base32Codec.DecodeString(pktIdRaw) if err != nil { log.Fatalln("Invalid packet specified: ", err) } @@ -154,18 +205,43 @@ func main() { } ctx.Umask() - if !ctx.CallNode( + + var autoTossFinish chan struct{} + var autoTossBadCode chan bool + if *autoToss { + autoTossFinish, autoTossBadCode = ctx.AutoToss( + node.Id, + nice, + *autoTossDoSeen, + *autoTossNoFile, + *autoTossNoFreq, + *autoTossNoExec, + *autoTossNoTrns, + *autoTossNoArea, + *autoTossNoACK, + ) + } + + badCode := !ctx.CallNode( node, addrs, nice, xxOnly, *rxRate, *txRate, - *onlineDeadline, + onlineDeadline, maxOnlineTime, *listOnly, + *noCK, onlyPkts, - ) { + ) + + if *autoToss { + close(autoTossFinish) + badCode = (<-autoTossBadCode) || badCode + } + nncp.SPCheckerWg.Wait() + if badCode { os.Exit(1) } }