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
49 func (ctx *Ctx) CallNode(
55 onlineDeadline, maxOnlineTime time.Duration,
58 onlyPkts map[[32]byte]bool,
60 for _, addr := range addrs {
61 les := LEs{{"Node", node.Id}, {"Addr", addr}}
62 ctx.LogD("calling", les, func(les LEs) string {
63 return fmt.Sprintf("Calling %s (%s)", node.Name, addr)
65 var conn ConnDeadlined
68 conn, err = NewPipeConn(addr[1:])
70 conn, err = net.Dial("tcp", addr)
73 ctx.LogD("calling", append(les, LE{"Err", err}), func(les LEs) string {
74 return fmt.Sprintf("Calling %s (%s)", node.Name, addr)
78 ctx.LogD("call-connected", les, func(les LEs) string {
79 return fmt.Sprintf("Connected %s (%s)", node.Name, addr)
85 onlineDeadline: onlineDeadline,
86 maxOnlineTime: maxOnlineTime,
94 if err = state.StartI(conn); err == nil {
95 ctx.LogI("call-started", les, func(les LEs) string {
96 return fmt.Sprintf("Connection to %s (%s)", node.Name, addr)
99 ctx.LogI("call-finished", append(
101 LE{"Duration", int64(state.Duration.Seconds())},
102 LE{"RxBytes", state.RxBytes},
103 LE{"RxSpeed", state.RxSpeed},
104 LE{"TxBytes", state.TxBytes},
105 LE{"TxSpeed", state.TxSpeed},
106 ), func(les LEs) string {
108 "Finished call with %s (%d:%d:%d): %s received (%s/sec), %s transferred (%s/sec)",
110 int(state.Duration.Hours()),
111 int(state.Duration.Minutes()),
112 int(state.Duration.Seconds()),
113 humanize.IBytes(uint64(state.RxBytes)),
114 humanize.IBytes(uint64(state.RxSpeed)),
115 humanize.IBytes(uint64(state.TxBytes)),
116 humanize.IBytes(uint64(state.TxSpeed)),
120 conn.Close() // #nosec G104
123 ctx.LogE("call-started", les, err, func(les LEs) string {
124 return fmt.Sprintf("Connection to %s (%s)", node.Name, addr)
126 conn.Close() // #nosec G104