Suspend connecting to targets that seem invalid, if they are 'direct' targets.
Introduce TargetSuspended state to reflect this.
This commit is contained in:
1 parent
537868008f
commit
2e4d56efd6
2 files changed
+11
-2
No files matched your search
@@ -32,6 +32,7 @@ const (
|
|||||||
TargetWaiting TargetState = iota // we are waiting to connect there
|
TargetWaiting TargetState = iota // we are waiting to connect there
|
||||||
TargetAttempting // we are attempting to connect there
|
TargetAttempting // we are attempting to connect there
|
||||||
TargetConnected // we are connected to there
|
TargetConnected // we are connected to there
|
||||||
|
TargetSuspended // not currently attempting to connect here
|
||||||
)
|
)
|
||||||
|
|
||||||
// Information about an address where we may find a peer
|
// Information about an address where we may find a peer
|
||||||
@@ -266,16 +267,23 @@ func (cm *ConnectionMaker) connectToTargets(validTarget map[string]struct{}, dir
|
|||||||
now := time.Now() // make sure we catch items just added
|
now := time.Now() // make sure we catch items just added
|
||||||
after := MaxDuration
|
after := MaxDuration
|
||||||
for address, target := range cm.targets {
|
for address, target := range cm.targets {
|
||||||
if target.state != TargetWaiting {
|
if target.state != TargetWaiting && target.state != TargetSuspended {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, valid := validTarget[address]; !valid {
|
if _, valid := validTarget[address]; !valid {
|
||||||
delete(cm.targets, address)
|
// Not valid: suspend reconnects if direct peer,
|
||||||
|
// otherwise forget this target entirely
|
||||||
|
if _, direct := directTarget[address]; direct {
|
||||||
|
target.state = TargetSuspended
|
||||||
|
} else {
|
||||||
|
delete(cm.targets, address)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if target.tryAfter.IsZero() {
|
if target.tryAfter.IsZero() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
target.state = TargetWaiting
|
||||||
switch duration := target.tryAfter.Sub(now); {
|
switch duration := target.tryAfter.Sub(now); {
|
||||||
case duration <= 0:
|
case duration <= 0:
|
||||||
target.state = TargetAttempting
|
target.state = TargetAttempting
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus
|
|||||||
add("retrying", target.lastError.Error())
|
add("retrying", target.lastError.Error())
|
||||||
}
|
}
|
||||||
case TargetConnected:
|
case TargetConnected:
|
||||||
|
case TargetSuspended:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resultChan <- slice
|
resultChan <- slice
|
||||||
|
|||||||
Reference in new issue
Block a user