X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcall.go;h=c4e04cbd9d2a1a47a1e5c5f27a62410b159d0a0c;hb=15ff8ac40bbf354f5319a6e753cf8c0963b15a53;hp=ab254b2dd5b6e8e9affb7e6280373111038c6117;hpb=5a9bf58a2638e42f2d42fa4d43c363a664fe8198;p=nncp.git diff --git a/src/call.go b/src/call.go index ab254b2..c4e04cb 100644 --- a/src/call.go +++ b/src/call.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 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 @@ -18,12 +18,16 @@ along with this program. If not, see . package nncp import ( + "errors" "fmt" "net" + "os" + "strings" "time" "github.com/dustin/go-humanize" "github.com/gorhill/cronexpr" + nncpYggdrasil "go.cypherpunks.ru/nncp/v8/yggdrasil" ) type Call struct { @@ -37,6 +41,7 @@ type Call struct { MaxOnlineTime time.Duration WhenTxExists bool NoCK bool + MCDIgnore bool AutoToss bool AutoTossDoSeen bool @@ -44,6 +49,7 @@ type Call struct { AutoTossNoFreq bool AutoTossNoExec bool AutoTossNoTrns bool + AutoTossNoArea bool } func (ctx *Ctx) CallNode( @@ -55,7 +61,7 @@ func (ctx *Ctx) CallNode( onlineDeadline, maxOnlineTime time.Duration, listOnly bool, noCK bool, - onlyPkts map[[32]byte]bool, + onlyPkts map[[MTHSize]byte]bool, ) (isGood bool) { for _, addr := range addrs { les := LEs{{"Node", node.Id}, {"Addr", addr}} @@ -66,11 +72,26 @@ func (ctx *Ctx) CallNode( var err error if addr[0] == '|' { conn, err = NewPipeConn(addr[1:]) + } else if addr == UCSPITCPClient { + ucspiConn := UCSPIConn{R: os.NewFile(6, "R"), W: os.NewFile(7, "W")} + if ucspiConn.R == nil { + err = errors.New("no 6 file descriptor") + } + if ucspiConn.W == nil { + err = errors.New("no 7 file descriptor") + } + conn = ucspiConn + addr = UCSPITCPRemoteAddr() + if addr == "" { + addr = UCSPITCPClient + } + } else if strings.HasPrefix(addr, "yggdrasilc://") { + conn, err = nncpYggdrasil.NewConn(ctx.YggdrasilAliases, addr) } else { conn, err = net.Dial("tcp", addr) } if err != nil { - ctx.LogD("calling", append(les, LE{"Err", err}), func(les LEs) string { + ctx.LogE("calling", les, err, func(les LEs) string { return fmt.Sprintf("Calling %s (%s)", node.Name, addr) }) continue @@ -109,7 +130,7 @@ func (ctx *Ctx) CallNode( node.Name, int(state.Duration.Hours()), int(state.Duration.Minutes()), - int(state.Duration.Seconds()), + int(state.Duration.Seconds())%60, humanize.IBytes(uint64(state.RxBytes)), humanize.IBytes(uint64(state.RxSpeed)), humanize.IBytes(uint64(state.TxBytes)), @@ -117,13 +138,13 @@ func (ctx *Ctx) CallNode( ) }) isGood = true - conn.Close() // #nosec G104 + conn.Close() break } else { ctx.LogE("call-started", les, err, func(les LEs) string { return fmt.Sprintf("Connection to %s (%s)", node.Name, addr) }) - conn.Close() // #nosec G104 + conn.Close() } } return