Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in periodic peer pinging #579

Merged
merged 5 commits into from Apr 9, 2020
Merged

Fix bug in periodic peer pinging #579

merged 5 commits into from Apr 9, 2020

Conversation

aarshkshah1992
Copy link
Contributor

Need to set the maxThreshold correctly.

dht.go Outdated
maxLastSuccessfulOutboundThreshold time.Duration
// maxLastSuccessfulOutboundThreshold is the max threshold/upper limit on the time duration
// between the current time and the last time a peer was useful to us.
maxLastSuccessfulOutboundThreshold float64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why make this a float? it's only used here to compare with a time duration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's calculated using a formula that translates to a float64. Take a look at:

maxLastSuccessfulOutboundThreshold := l1 / l2 * float64(cfg.routingTable.refreshInterval)

if queryPeer {
dht.routingTable.UpdateLastSuccessfulOutboundQuery(p, time.Now())
if newlyAdded && queryPeer {
dht.routingTable.UpdateLastUsefulAt(p, time.Now())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a new peer, don't set this to now in addPeer regardless?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarshkshah1992 not blocking a merge on this as it shouldn't really matter. We can fix this later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stebalien The idea is that if we discover and add a peer because of an inbound/outbound query, we do NOT want to evict the peer for one ''cycle".

Note that the time will NOT be "now" for peers we connect to without querying them .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talking this over with @aschmahmann, I think I was right. In addPeer (in the routing table), if queryPeer is true, we'll set "last useful" to now when the peer wasn't already in our routing table. Then, when the peer wasn't already in our routing table, we'll mark them as useful again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stebalien I see what you mean. I am removing this particular check from here and adding this commit so when we first query a peer after connecting to it(that's two calls to addPeer, once on connection and once upon a successful query), we give it one and ONLY one usefulness bump.

@Stebalien Stebalien merged commit bfa23ff into master Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants