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
50 func (ctx *Ctx) CallNode(
56 onlineDeadline, maxOnlineTime time.Duration,
59 onlyPkts map[[MTHSize]byte]bool,
61 for _, addr := range addrs {
62 les := LEs{{"Node", node.Id}, {"Addr", addr}}
63 ctx.LogD("calling", les, func(les LEs) string {
64 return fmt.Sprintf("Calling %s (%s)", node.Name, addr)
66 var conn ConnDeadlined
69 conn, err = NewPipeConn(addr[1:])
71 conn, err = net.Dial("tcp", addr)
74 ctx.LogD("calling", append(les, LE{"Err", err}), func(les LEs) string {
75 return fmt.Sprintf("Calling %s (%s)", node.Name, addr)
79 ctx.LogD("call-connected", les, func(les LEs) string {
80 return fmt.Sprintf("Connected %s (%s)", node.Name, addr)
86 onlineDeadline: onlineDeadline,
87 maxOnlineTime: maxOnlineTime,
95 if err = state.StartI(conn); err == nil {
96 ctx.LogI("call-started", les, func(les LEs) string {
97 return fmt.Sprintf("Connection to %s (%s)", node.Name, addr)
100 ctx.LogI("call-finished", append(
102 LE{"Duration", int64(state.Duration.Seconds())},
103 LE{"RxBytes", state.RxBytes},
104 LE{"RxSpeed", state.RxSpeed},
105 LE{"TxBytes", state.TxBytes},
106 LE{"TxSpeed", state.TxSpeed},
107 ), func(les LEs) string {
109 "Finished call with %s (%d:%d:%d): %s received (%s/sec), %s transferred (%s/sec)",
111 int(state.Duration.Hours()),
112 int(state.Duration.Minutes()),
113 int(state.Duration.Seconds())%60,
114 humanize.IBytes(uint64(state.RxBytes)),
115 humanize.IBytes(uint64(state.RxSpeed)),
116 humanize.IBytes(uint64(state.TxBytes)),
117 humanize.IBytes(uint64(state.TxSpeed)),
121 conn.Close() // #nosec G104
124 ctx.LogE("call-started", les, err, func(les LEs) string {
125 return fmt.Sprintf("Connection to %s (%s)", node.Name, addr)
127 conn.Close() // #nosec G104