forked from cwtch.im/cwtch
Fixup Contact Retry to Play Nicely with Appear Offline Mode
This commit is contained in:
parent
45d6d76a7d
commit
58b1008cae
|
@ -349,14 +349,17 @@ func (cr *contactRetry) processStatus() {
|
||||||
// Loop through connections. Reset state, and requeue...
|
// Loop through connections. Reset state, and requeue...
|
||||||
cr.connections.Range(func(k, v interface{}) bool {
|
cr.connections.Range(func(k, v interface{}) bool {
|
||||||
p := v.(*contact)
|
p := v.(*contact)
|
||||||
p.queued = true
|
|
||||||
|
|
||||||
// prioritize connections made recently...
|
// only reload connections if they are on the authorized peers list
|
||||||
log.Debugf("adding %v to queue", p.id)
|
if _, exists := cr.authorizedPeers.Load(p.id); exists {
|
||||||
if time.Since(p.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours {
|
p.queued = true
|
||||||
cr.priorityQueue.insert(p)
|
// prioritize connections made recently...
|
||||||
} else {
|
log.Debugf("adding %v to queue", p.id)
|
||||||
cr.pendingQueue.insert(p)
|
if time.Since(p.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours {
|
||||||
|
cr.priorityQueue.insert(p)
|
||||||
|
} else {
|
||||||
|
cr.pendingQueue.insert(p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -397,10 +400,14 @@ func (cr *contactRetry) requeueReady() {
|
||||||
|
|
||||||
cr.connections.Range(func(k, v interface{}) bool {
|
cr.connections.Range(func(k, v interface{}) bool {
|
||||||
p := v.(*contact)
|
p := v.(*contact)
|
||||||
if p.state == connections.DISCONNECTED && !p.queued {
|
|
||||||
timeout := time.Duration((math.Pow(2, float64(p.failedCount)))*float64(adjustedBaseTimeout /*baseTimeoutSec*/)) * time.Second
|
// Don't retry anyone who isn't on the authorized peers list
|
||||||
if time.Since(p.lastAttempt) > timeout {
|
if _, exists := cr.authorizedPeers.Load(p.id); exists {
|
||||||
retryable = append(retryable, p)
|
if p.state == connections.DISCONNECTED && !p.queued {
|
||||||
|
timeout := time.Duration((math.Pow(2, float64(p.failedCount)))*float64(adjustedBaseTimeout /*baseTimeoutSec*/)) * time.Second
|
||||||
|
if time.Since(p.lastAttempt) > timeout {
|
||||||
|
retryable = append(retryable, p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -114,11 +114,11 @@ func TestFileSharing(t *testing.T) {
|
||||||
t.Logf("** Waiting for Alice, Bob...")
|
t.Logf("** Waiting for Alice, Bob...")
|
||||||
alice := app2.WaitGetPeer(app, "alice")
|
alice := app2.WaitGetPeer(app, "alice")
|
||||||
app.ActivatePeerEngine(alice.GetOnion())
|
app.ActivatePeerEngine(alice.GetOnion())
|
||||||
app.ConfigureConnections(alice.GetOnion(), true, true, true);
|
app.ConfigureConnections(alice.GetOnion(), true, true, true)
|
||||||
bob := app2.WaitGetPeer(app, "bob")
|
bob := app2.WaitGetPeer(app, "bob")
|
||||||
app.ActivatePeerEngine(bob.GetOnion())
|
app.ActivatePeerEngine(bob.GetOnion())
|
||||||
app.ConfigureConnections(bob.GetOnion(), true, true, true);
|
app.ConfigureConnections(bob.GetOnion(), true, true, true)
|
||||||
|
|
||||||
alice.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
alice.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
||||||
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,6 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
||||||
settings.Experiments[constants.GroupsExperiment] = true
|
settings.Experiments[constants.GroupsExperiment] = true
|
||||||
app.UpdateSettings(settings)
|
app.UpdateSettings(settings)
|
||||||
|
|
||||||
|
|
||||||
log.Infoln("Creating Alice...")
|
log.Infoln("Creating Alice...")
|
||||||
app.CreateProfile("Alice", "asdfasdf", true)
|
app.CreateProfile("Alice", "asdfasdf", true)
|
||||||
|
|
||||||
|
@ -169,7 +168,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
||||||
alice := app2.WaitGetPeer(app, "Alice")
|
alice := app2.WaitGetPeer(app, "Alice")
|
||||||
aliceBus := app.GetEventBus(alice.GetOnion())
|
aliceBus := app.GetEventBus(alice.GetOnion())
|
||||||
app.ActivatePeerEngine(alice.GetOnion())
|
app.ActivatePeerEngine(alice.GetOnion())
|
||||||
app.ConfigureConnections(alice.GetOnion(), true, true, true);
|
app.ConfigureConnections(alice.GetOnion(), true, true, true)
|
||||||
log.Infoln("Alice created:", alice.GetOnion())
|
log.Infoln("Alice created:", alice.GetOnion())
|
||||||
// alice.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, "Alice") <- This is now done automatically by ProfileValueExtension, keeping this here for clarity
|
// alice.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, "Alice") <- This is now done automatically by ProfileValueExtension, keeping this here for clarity
|
||||||
alice.AutoHandleEvents([]event.Type{event.PeerStateChange, event.ServerStateChange, event.NewGroupInvite, event.NewRetValMessageFromPeer})
|
alice.AutoHandleEvents([]event.Type{event.PeerStateChange, event.ServerStateChange, event.NewGroupInvite, event.NewRetValMessageFromPeer})
|
||||||
|
@ -177,7 +176,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
||||||
bob := app2.WaitGetPeer(app, "Bob")
|
bob := app2.WaitGetPeer(app, "Bob")
|
||||||
bobBus := app.GetEventBus(bob.GetOnion())
|
bobBus := app.GetEventBus(bob.GetOnion())
|
||||||
app.ActivatePeerEngine(bob.GetOnion())
|
app.ActivatePeerEngine(bob.GetOnion())
|
||||||
app.ConfigureConnections(bob.GetOnion(), true, true, true);
|
app.ConfigureConnections(bob.GetOnion(), true, true, true)
|
||||||
log.Infoln("Bob created:", bob.GetOnion())
|
log.Infoln("Bob created:", bob.GetOnion())
|
||||||
// bob.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, "Bob") <- This is now done automatically by ProfileValueExtension, keeping this here for clarity
|
// bob.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, "Bob") <- This is now done automatically by ProfileValueExtension, keeping this here for clarity
|
||||||
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.ServerStateChange, event.NewGroupInvite, event.NewRetValMessageFromPeer})
|
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.ServerStateChange, event.NewGroupInvite, event.NewRetValMessageFromPeer})
|
||||||
|
@ -185,7 +184,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
||||||
carol := app2.WaitGetPeer(app, "Carol")
|
carol := app2.WaitGetPeer(app, "Carol")
|
||||||
carolBus := app.GetEventBus(carol.GetOnion())
|
carolBus := app.GetEventBus(carol.GetOnion())
|
||||||
app.ActivatePeerEngine(carol.GetOnion())
|
app.ActivatePeerEngine(carol.GetOnion())
|
||||||
app.ConfigureConnections(carol.GetOnion(), true, true, true);
|
app.ConfigureConnections(carol.GetOnion(), true, true, true)
|
||||||
log.Infoln("Carol created:", carol.GetOnion())
|
log.Infoln("Carol created:", carol.GetOnion())
|
||||||
// carol.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, "Carol") <- This is now done automatically by ProfileValueExtension, keeping this here for clarity
|
// carol.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, "Carol") <- This is now done automatically by ProfileValueExtension, keeping this here for clarity
|
||||||
carol.AutoHandleEvents([]event.Type{event.PeerStateChange, event.ServerStateChange, event.NewGroupInvite, event.NewRetValMessageFromPeer})
|
carol.AutoHandleEvents([]event.Type{event.PeerStateChange, event.ServerStateChange, event.NewGroupInvite, event.NewRetValMessageFromPeer})
|
||||||
|
|
|
@ -116,10 +116,10 @@ func TestFileSharing(t *testing.T) {
|
||||||
t.Logf("** Waiting for Alice, Bob...")
|
t.Logf("** Waiting for Alice, Bob...")
|
||||||
alice := app2.WaitGetPeer(app, "alice")
|
alice := app2.WaitGetPeer(app, "alice")
|
||||||
app.ActivatePeerEngine(alice.GetOnion())
|
app.ActivatePeerEngine(alice.GetOnion())
|
||||||
app.ConfigureConnections(alice.GetOnion(), true, true, true);
|
app.ConfigureConnections(alice.GetOnion(), true, true, true)
|
||||||
bob := app2.WaitGetPeer(app, "bob")
|
bob := app2.WaitGetPeer(app, "bob")
|
||||||
app.ActivatePeerEngine(bob.GetOnion())
|
app.ActivatePeerEngine(bob.GetOnion())
|
||||||
app.ConfigureConnections(bob.GetOnion(), true, true, true);
|
app.ConfigureConnections(bob.GetOnion(), true, true, true)
|
||||||
alice.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
alice.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
||||||
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue