forked from cwtch.im/cwtch
Merge pull request 'Fixup Contact Retry to Play Nicely with Appear Offline Mode' (#532) from stable-blockers into master
Reviewed-on: cwtch.im/cwtch#532 Reviewed-by: Dan Ballard <dan@openprivacy.ca>
This commit is contained in:
commit
13583f3e8c
|
@ -349,14 +349,17 @@ func (cr *contactRetry) processStatus() {
|
|||
// Loop through connections. Reset state, and requeue...
|
||||
cr.connections.Range(func(k, v interface{}) bool {
|
||||
p := v.(*contact)
|
||||
p.queued = true
|
||||
|
||||
// prioritize connections made recently...
|
||||
log.Debugf("adding %v to queue", p.id)
|
||||
if time.Since(p.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours {
|
||||
cr.priorityQueue.insert(p)
|
||||
} else {
|
||||
cr.pendingQueue.insert(p)
|
||||
// only reload connections if they are on the authorized peers list
|
||||
if _, exists := cr.authorizedPeers.Load(p.id); exists {
|
||||
p.queued = true
|
||||
// prioritize connections made recently...
|
||||
log.Debugf("adding %v to queue", p.id)
|
||||
if time.Since(p.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours {
|
||||
cr.priorityQueue.insert(p)
|
||||
} else {
|
||||
cr.pendingQueue.insert(p)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -397,10 +400,14 @@ func (cr *contactRetry) requeueReady() {
|
|||
|
||||
cr.connections.Range(func(k, v interface{}) bool {
|
||||
p := v.(*contact)
|
||||
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)
|
||||
|
||||
// Don't retry anyone who isn't on the authorized peers list
|
||||
if _, exists := cr.authorizedPeers.Load(p.id); exists {
|
||||
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
|
||||
|
|
|
@ -114,10 +114,10 @@ func TestFileSharing(t *testing.T) {
|
|||
t.Logf("** Waiting for Alice, Bob...")
|
||||
alice := app2.WaitGetPeer(app, "alice")
|
||||
app.ActivatePeerEngine(alice.GetOnion())
|
||||
app.ConfigureConnections(alice.GetOnion(), true, true, true);
|
||||
app.ConfigureConnections(alice.GetOnion(), true, true, true)
|
||||
bob := app2.WaitGetPeer(app, "bob")
|
||||
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})
|
||||
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
||||
|
|
|
@ -156,7 +156,6 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
settings.Experiments[constants.GroupsExperiment] = true
|
||||
app.UpdateSettings(settings)
|
||||
|
||||
|
||||
log.Infoln("Creating Alice...")
|
||||
app.CreateProfile("Alice", "asdfasdf", true)
|
||||
|
||||
|
@ -169,7 +168,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
alice := app2.WaitGetPeer(app, "Alice")
|
||||
aliceBus := app.GetEventBus(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())
|
||||
// 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})
|
||||
|
@ -177,7 +176,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
bob := app2.WaitGetPeer(app, "Bob")
|
||||
bobBus := app.GetEventBus(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())
|
||||
// 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})
|
||||
|
@ -185,7 +184,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
carol := app2.WaitGetPeer(app, "Carol")
|
||||
carolBus := app.GetEventBus(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())
|
||||
// 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})
|
||||
|
|
|
@ -116,10 +116,10 @@ func TestFileSharing(t *testing.T) {
|
|||
t.Logf("** Waiting for Alice, Bob...")
|
||||
alice := app2.WaitGetPeer(app, "alice")
|
||||
app.ActivatePeerEngine(alice.GetOnion())
|
||||
app.ConfigureConnections(alice.GetOnion(), true, true, true);
|
||||
app.ConfigureConnections(alice.GetOnion(), true, true, true)
|
||||
bob := app2.WaitGetPeer(app, "bob")
|
||||
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})
|
||||
bob.AutoHandleEvents([]event.Type{event.PeerStateChange, event.NewRetValMessageFromPeer})
|
||||
|
||||
|
|
Loading…
Reference in New Issue