Remove entries from the failedConnection list when they succeed.

Avoids unsightly error messages where both ends make the same
connection and we then have to drop one of them.
This commit is contained in:
Bryan Boreham committed 2014-09-05 15:45:32 +01:00
1 parent 2d387e3847
commit 5c7010625a
1 file changed
+11 -3
+11 -3
View File
@@ -24,7 +24,8 @@ const (
MaxAttemptCount = 100 MaxAttemptCount = 100
CMEnsure = iota CMEnsure = iota
CMStatus = iota CMStatus = iota
CMConnAttemptFinished = iota CMConnSucceeded = iota
CMConnFailed = iota
) )
func StartConnectionMaker(router *Router) *ConnectionMaker { func StartConnectionMaker(router *Router) *ConnectionMaker {
@@ -74,7 +75,10 @@ func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteractio
} }
case query.code == CMStatus: case query.code == CMStatus:
query.resultChan <- cm.status() query.resultChan <- cm.status()
case query.code == CMConnAttemptFinished: case query.code == CMConnSucceeded:
delete(cm.attempting, ConnectionMakerPair{query.foundAt, query.name})
delete(cm.failedConnections[query.name].foundAt, query.foundAt)
case query.code == CMConnFailed:
delete(cm.attempting, ConnectionMakerPair{query.foundAt, query.name}) delete(cm.attempting, ConnectionMakerPair{query.foundAt, query.name})
default: default:
log.Fatal("Unexpected connection maker query:", query) log.Fatal("Unexpected connection maker query:", query)
@@ -86,6 +90,8 @@ func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteractio
if _, found := cm.router.Ourself.ConnectionTo(name); found { if _, found := cm.router.Ourself.ConnectionTo(name); found {
delete(cm.failedConnections, name) delete(cm.failedConnections, name)
continue continue
} else if len(failedConn.foundAt) == 0 {
delete(cm.failedConnections, name)
} else if failedConn.attemptCount == MaxAttemptCount { } else if failedConn.attemptCount == MaxAttemptCount {
delete(cm.failedConnections, name) delete(cm.failedConnections, name)
continue continue
@@ -154,12 +160,14 @@ func (cm *ConnectionMaker) status() string {
} }
func (cm *ConnectionMaker) attemptConnection(foundAt string, targetName PeerName) { func (cm *ConnectionMaker) attemptConnection(foundAt string, targetName PeerName) {
var conncode = CMConnSucceeded
if err := cm.router.Ourself.CreateConnection(foundAt, targetName); err != nil { if err := cm.router.Ourself.CreateConnection(foundAt, targetName); err != nil {
log.Println(err) log.Println(err)
conncode = CMConnFailed
} }
// Tell the query loop we've finished this attempt // Tell the query loop we've finished this attempt
cm.queryChan <- &ConnectionMakerInteraction{ cm.queryChan <- &ConnectionMakerInteraction{
Interaction: Interaction{code: CMConnAttemptFinished}, Interaction: Interaction{code: conncode},
name: targetName, name: targetName,
foundAt: foundAt} foundAt: foundAt}
} }