nice: 64
-
cron: "30 * * * 5-6"
- onlinedeadline: 10
+ onlinedeadline: 1800
+ maxonlinetime: 1750
nice: 64
-
cron: "0 * * * 5-6"
disconnect after an hour of inactivity and process only relatively high
priority packets (presumably mail ones). So we connect and hold
connection for very long time to pass only emails. On weekends call that
-node only each half-hour for processing high-priority packets and
-quickly disconnect. Also only on weekends try to connect to that node
-every hour only using LAN address and only receiving any (any priority)
-packets (assume that low priority huge file transmission are done
-additionally via offline connections).
+node only each half-hour for processing high-priority packets. Also only
+on weekends try to connect to that node every hour only using LAN
+address and only receiving any (any priority) packets (assume that low
+priority huge file transmission are done additionally via offline
+connections).
It contains the following fields (only @emph{cron} is required):
Optional. Override @ref{CfgOnlineDeadline, @emph{onlinedeadline}}
configuration option when calling.
+@item maxonlinetime
+Optional. Override @ref{CfgMaxOnlineTime, @emph{maxonlinetime}}
+configuration option when calling.
+
@end table
noisepub: UBM5K...VI42A
sendmail: ["/bin/sh", "-c", "false"]
incoming: /home/alice/incoming
- onlinedeadline: 3600
+ onlinedeadline: 1800
+ maxonlinetime: 3600
addrs:
lan: "[fe80::1234%igb0]:5400"
internet: alice.com:3389
alive (to reduce handshake overhead and delays), wait for appearing
packets ready to send and notifying remote side about their appearance.
+@anchor{CfgMaxOnlineTime}
+@item maxonlinetime
+If greater than zero, then it is maximal amount of time connect could be
+alive. Forcefully disconnect if it is exceeded.
+
@anchor{CfgCalls}
@item calls
List of @ref{Call, call configuration}s. Can be omitted if
@section nncp-call
@verbatim
-% nncp-call [options] [-onlinedeadline INT] [-rx|-tx] NODE[:ADDR] [FORCEADDR]
+% nncp-call [options] [-onlinedeadline INT] [-maxonlinetime INT] [-rx|-tx]
+ NODE[:ADDR] [FORCEADDR]
@end verbatim
Call (connect to) specified @option{NODE} and run @ref{Sync,
Synchronization protocol allows resuming and bidirectional packets
transfer.
-If @option{-rx} option is specified then only inbound packets transmission
-is performed. If @option{-tx} option is specified, then only outbound
-transmission is performed.
+If @option{-rx} option is specified then only inbound packets
+transmission is performed. If @option{-tx} option is specified, then
+only outbound transmission is performed. @option{-onlinedeadline}
+overrides @ref{CfgOnlineDeadline, @emph{onlinedeadline}}.
+@option{-maxonlinetime} overrides @ref{CfgMaxOnlineTime,
+@emph{maxonlinetime}}.
@node nncp-caller
@section nncp-caller
"strconv"
)
-func (ctx *Ctx) CallNode(node *Node, addrs []string, nice uint8, xxOnly *TRxTx, onlineDeadline int) (isGood bool) {
+func (ctx *Ctx) CallNode(node *Node, addrs []string, nice uint8, xxOnly *TRxTx, onlineDeadline, maxOnlineTime uint) (isGood bool) {
for _, addr := range addrs {
sds := SDS{"node": node.Id, "addr": addr}
ctx.LogD("call", sds, "dialing")
continue
}
ctx.LogD("call", sds, "connected")
- state, err := ctx.StartI(conn, node.Id, nice, xxOnly, onlineDeadline)
+ state, err := ctx.StartI(
+ conn,
+ node.Id,
+ nice,
+ xxOnly,
+ onlineDeadline,
+ maxOnlineTime,
+ )
if err == nil {
ctx.LogI("call-start", sds, "connected")
state.Wait()
Addrs map[string]string `addrs,omitempty`
- OnlineDeadline *int `onlinedeadline,omitempty`
+ OnlineDeadline *uint `onlinedeadline,omitempty`
+ MaxOnlineTime *uint `maxonlinetime,omitempty`
}
type CallYAML struct {
Nice *int `nice,omitempty`
Xx *string `xx,omitempty`
Addr *string `addr,omitempty`
- OnlineDeadline *int `onlinedeadline,omitempty`
+ OnlineDeadline *uint `onlinedeadline,omitempty`
+ MaxOnlineTime *uint `maxonlinetime,omitempty`
}
type NodeOurYAML struct {
freq = &fr
}
- defOnlineDeadline := int(DefaultDeadline)
+ defOnlineDeadline := uint(DefaultDeadline)
if yml.OnlineDeadline != nil {
if *yml.OnlineDeadline <= 0 {
return nil, errors.New("OnlineDeadline must be at least 1 second")
}
defOnlineDeadline = *yml.OnlineDeadline
}
+ var defMaxOnlineTime uint
+ if yml.MaxOnlineTime != nil {
+ defMaxOnlineTime = *yml.MaxOnlineTime
+ }
var calls []*Call
for _, callYml := range yml.Calls {
}
onlineDeadline = *callYml.OnlineDeadline
}
+ var maxOnlineTime uint
+ if callYml.MaxOnlineTime != nil {
+ maxOnlineTime = *callYml.MaxOnlineTime
+ }
calls = append(calls, &Call{
Cron: expr,
Nice: nice,
Xx: &xx,
Addr: addr,
OnlineDeadline: onlineDeadline,
+ MaxOnlineTime: maxOnlineTime,
})
}
Calls: calls,
Addrs: yml.Addrs,
OnlineDeadline: defOnlineDeadline,
+ MaxOnlineTime: defMaxOnlineTime,
}
copy(node.ExchPub[:], exchPub)
if len(noisePub) > 0 {
version = flag.Bool("version", false, "Print version information")
warranty = flag.Bool("warranty", false, "Print warranty information")
- onlineDeadline = flag.Int("onlinedeadline", 0, "Override onlinedeadline option")
+ onlineDeadline = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option")
+ maxOnlineTime = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option")
)
flag.Usage = usage
flag.Parse()
if *onlineDeadline == 0 {
onlineDeadline = &node.OnlineDeadline
}
+ if *maxOnlineTime == 0 {
+ maxOnlineTime = &node.MaxOnlineTime
+ }
var xxOnly nncp.TRxTx
if *rxOnly {
}
}
- if !ctx.CallNode(node, addrs, nice, &xxOnly, *onlineDeadline) {
+ if !ctx.CallNode(node, addrs, nice, &xxOnly, *onlineDeadline, *maxOnlineTime) {
os.Exit(1)
}
}
} else {
node.Busy = true
node.Unlock()
- ctx.CallNode(node, addrs, call.Nice, call.Xx, call.OnlineDeadline)
+ ctx.CallNode(
+ node,
+ addrs,
+ call.Nice,
+ call.Xx,
+ call.OnlineDeadline,
+ call.MaxOnlineTime,
+ )
node.Lock()
node.Busy = false
node.Unlock()
Freq *string
Via []*NodeId
Addrs map[string]string
- OnlineDeadline int
+ OnlineDeadline uint
+ MaxOnlineTime uint
Calls []*Call
Busy bool
Nice uint8
Xx *TRxTx
Addr *string
- OnlineDeadline int
+ OnlineDeadline uint
+ MaxOnlineTime uint
}
func NewNodeGenerate() (*NodeOur, error) {
type SPState struct {
ctx *Ctx
Node *Node
- onlineDeadline int
+ onlineDeadline uint
+ maxOnlineTime uint
nice uint8
hs *noise.HandshakeState
csOur *noise.CipherState
}
func (state *SPState) NotAlive() bool {
+ if state.isDead {
+ return true
+ }
now := time.Now()
- return state.isDead || (int(now.Sub(state.RxLastSeen).Seconds()) >= state.onlineDeadline && int(now.Sub(state.TxLastSeen).Seconds()) >= state.onlineDeadline)
+ if state.maxOnlineTime > 0 && state.started.Add(time.Duration(state.maxOnlineTime)*time.Second).Before(now) {
+ return true
+ }
+ return uint(now.Sub(state.RxLastSeen).Seconds()) >= state.onlineDeadline && uint(now.Sub(state.TxLastSeen).Seconds()) >= state.onlineDeadline
}
func (state *SPState) dirUnlock() {
return payloadsSplit(payloads)
}
-func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly *TRxTx, onlineDeadline int) (*SPState, error) {
+func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly *TRxTx, onlineDeadline, maxOnlineTime uint) (*SPState, error) {
err := ctx.ensureRxDir(nodeId)
if err != nil {
return nil, err
hs: noise.NewHandshakeState(conf),
Node: node,
onlineDeadline: onlineDeadline,
+ maxOnlineTime: maxOnlineTime,
nice: nice,
payloads: make(chan []byte),
infosTheir: make(map[[32]byte]*SPInfo),
}
state.Node = node
state.onlineDeadline = node.OnlineDeadline
+ state.maxOnlineTime = node.MaxOnlineTime
sds := SDS{"node": node.Id, "nice": strconv.Itoa(int(nice))}
if ctx.ensureRxDir(node.Id); err != nil {