client-interface-cleanup (#6)
Refactoring and code cleanup. Improved client command interface.
This commit is contained in:
@@ -154,6 +154,8 @@ func (r *remoteFSM) stateServer_onInit(msg controlMsg[packetInit]) {
|
||||
Version: version,
|
||||
}
|
||||
|
||||
// Reset traceID to force state update on SYN.
|
||||
r.traceID = 0
|
||||
r.sendControl(conf, init.Marshal(r.buf))
|
||||
}
|
||||
|
||||
@@ -161,23 +163,19 @@ func (r *remoteFSM) stateServer_onSyn(msg controlMsg[packetSyn]) {
|
||||
r.lastSeen = time.Now()
|
||||
p := msg.Packet
|
||||
|
||||
// Before we can respond to this packet, we need to make sure the
|
||||
// route is setup properly.
|
||||
conf := r.conf()
|
||||
logSyn := !conf.Up || conf.Direct != p.Direct
|
||||
|
||||
conf.Up = true
|
||||
conf.Direct = p.Direct
|
||||
conf.DirectAddr = msg.SrcAddr
|
||||
// New trace ID => Update the route configuration.
|
||||
if p.TraceID != r.traceID {
|
||||
r.traceID = p.TraceID
|
||||
|
||||
conf.Up = true
|
||||
conf.Direct = p.Direct
|
||||
conf.DirectAddr = msg.SrcAddr
|
||||
|
||||
// Update data cipher if the key has changed.
|
||||
if !conf.DataCipher.HasKey(p.SharedKey) {
|
||||
conf.DataCipher = newDataCipherFromKey(p.SharedKey)
|
||||
}
|
||||
|
||||
r.updateConf(conf)
|
||||
|
||||
if logSyn {
|
||||
r.updateConf(conf)
|
||||
r.logf("Got SYN.")
|
||||
}
|
||||
|
||||
@@ -191,13 +189,14 @@ func (r *remoteFSM) stateServer_onSyn(msg controlMsg[packetSyn]) {
|
||||
return
|
||||
}
|
||||
|
||||
// Send probes if not a direct connection.
|
||||
// Send probes if not a direct connection. The server sends probes without
|
||||
// trace IDs unless responding to a client probe.
|
||||
for _, addr := range msg.Packet.PossibleAddrs {
|
||||
if !addr.IsValid() {
|
||||
break
|
||||
}
|
||||
r.logf("Probing %v...", addr)
|
||||
r.sendControlToAddr(packetProbe{TraceID: r.NewTraceID()}.Marshal(r.buf), addr)
|
||||
r.sendControlToAddr(packetProbe{}.Marshal(r.buf), addr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +212,8 @@ func (r *remoteFSM) stateServer_onProbe(msg controlMsg[packetProbe]) {
|
||||
func (r *remoteFSM) stateServer_onPingTimer() {
|
||||
conf := r.conf()
|
||||
if time.Since(r.lastSeen) > timeoutInterval && conf.Up {
|
||||
// Reset trace ID to ensure connection goes up on next SYN.
|
||||
r.traceID = 0
|
||||
conf.Up = false
|
||||
r.updateConf(conf)
|
||||
r.logf("Timeout.")
|
||||
@@ -310,7 +311,7 @@ func (r *remoteFSM) stateClientInit_onPing() stateFunc {
|
||||
|
||||
func (r *remoteFSM) enterClient() stateFunc {
|
||||
conf := r.conf()
|
||||
r.probes = make(map[uint64]sentProbe, 8)
|
||||
clear(r.probes)
|
||||
|
||||
r.traceID = r.NewTraceID()
|
||||
r.stateClient_sendSyn(conf)
|
||||
|
||||
Reference in New Issue
Block a user