/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
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
package nncp
import (
+ "errors"
"fmt"
"net"
+ "os"
+ "strings"
"time"
"github.com/dustin/go-humanize"
"github.com/gorhill/cronexpr"
)
+const YggdrasilPrefix = "yggdrasil:"
+
type Call struct {
Cron *cronexpr.Expression
Nice uint8
AutoTossNoFreq bool
AutoTossNoExec bool
AutoTossNoTrns bool
+ AutoTossNoArea bool
}
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}}
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, YggdrasilPrefix) {
+ conn, err = NewYggdrasilConn(
+ ctx.YggdrasilAliases,
+ strings.TrimPrefix(addr, YggdrasilPrefix),
+ )
} 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
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)),
)
})
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