"fmt"
"io/ioutil"
"log"
- "net"
"os"
- "strconv"
"strings"
"cypherpunks.ru/nncp"
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.Int("onlinedeadline", 0, "Override onlinedeadline option")
)
flag.Usage = usage
flag.Parse()
log.Fatalln("Node does not have online communication capability")
}
+ if *onlineDeadline == 0 {
+ onlineDeadline = &node.OnlineDeadline
+ }
+
var xxOnly nncp.TRxTx
if *rxOnly {
xxOnly = nncp.TRx
}
}
- isGood := false
- for _, addr := range addrs {
- ctx.LogD("call", nncp.SDS{"addr": addr}, "dialing")
- conn, err := net.Dial("tcp", addr)
- if err != nil {
- log.Println("Can not connect:", err)
- continue
- }
- ctx.LogD("call", nncp.SDS{"addr": addr}, "connected")
- state, err := ctx.StartI(conn, node.Id, nice, &xxOnly)
- if err == nil {
- ctx.LogI("call-start", nncp.SDS{"node": state.NodeId}, "connected")
- state.Wait()
- ctx.LogI("call-finish", nncp.SDS{
- "node": state.NodeId,
- "duration": strconv.FormatInt(int64(state.Duration.Seconds()), 10),
- "rxbytes": strconv.FormatInt(state.RxBytes, 10),
- "txbytes": strconv.FormatInt(state.TxBytes, 10),
- "rxspeed": strconv.FormatInt(state.RxSpeed, 10),
- "txspeed": strconv.FormatInt(state.TxSpeed, 10),
- }, "")
- isGood = true
- conn.Close()
- break
- } else {
- ctx.LogE("call-start", nncp.SDS{"node": state.NodeId, "err": err}, "")
- conn.Close()
- }
- }
- if !isGood {
+ if !ctx.CallNode(node, addrs, nice, &xxOnly, *onlineDeadline) {
os.Exit(1)
}
}