2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "github.com/dustin/go-humanize"
26 "github.com/gorhill/cronexpr"
30 Cron *cronexpr.Expression
36 OnlineDeadline time.Duration
37 MaxOnlineTime time.Duration
51 func (ctx *Ctx) CallNode(
57 onlineDeadline, maxOnlineTime time.Duration,
60 onlyPkts map[[MTHSize]byte]bool,
62 for _, addr := range addrs {
63 les := LEs{{"Node", node.Id}, {"Addr", addr}}
64 ctx.LogD("calling", les, func(les LEs) string {
65 return fmt.Sprintf("Calling %s (%s)", node.Name, addr)
67 var conn ConnDeadlined
70 conn, err = NewPipeConn(addr[1:])
72 conn, err = net.Dial("tcp", addr)
75 ctx.LogD("calling", append(les, LE{"Err", err}), func(les LEs) string {
76 return fmt.Sprintf("Calling %s (%s)", node.Name, addr)
80 ctx.LogD("call-connected", les, func(les LEs) string {
81 return fmt.Sprintf("Connected %s (%s)", node.Name, addr)
87 onlineDeadline: onlineDeadline,
88 maxOnlineTime: maxOnlineTime,
96 if err = state.StartI(conn); err == nil {
97 ctx.LogI("call-started", les, func(les LEs) string {
98 return fmt.Sprintf("Connection to %s (%s)", node.Name, addr)
101 ctx.LogI("call-finished", append(
103 LE{"Duration", int64(state.Duration.Seconds())},
104 LE{"RxBytes", state.RxBytes},
105 LE{"RxSpeed", state.RxSpeed},
106 LE{"TxBytes", state.TxBytes},
107 LE{"TxSpeed", state.TxSpeed},
108 ), func(les LEs) string {
110 "Finished call with %s (%d:%d:%d): %s received (%s/sec), %s transferred (%s/sec)",
112 int(state.Duration.Hours()),
113 int(state.Duration.Minutes()),
114 int(state.Duration.Seconds())%60,
115 humanize.IBytes(uint64(state.RxBytes)),
116 humanize.IBytes(uint64(state.RxSpeed)),
117 humanize.IBytes(uint64(state.TxBytes)),
118 humanize.IBytes(uint64(state.TxSpeed)),
122 conn.Close() // #nosec G104
125 ctx.LogE("call-started", les, err, func(les LEs) string {
126 return fmt.Sprintf("Connection to %s (%s)", node.Name, addr)
128 conn.Close() // #nosec G104