-
Notifications
You must be signed in to change notification settings - Fork 36
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
Refresh Cpl's, not buckets #46
Conversation
1978548
to
a58d596
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor changes but otherwise lgtm.
table.go
Outdated
@@ -21,6 +21,15 @@ var log = logging.Logger("table") | |||
var ErrPeerRejectedHighLatency = errors.New("peer rejected; latency too high") | |||
var ErrPeerRejectedNoCapacity = errors.New("peer rejected; insufficient capacity") | |||
|
|||
// MaxCplForRefresh is the maximum cpl we support for refresh. | |||
// This limit exists because we can only generate 'MaxCplForRefresh' bit prefixes for now. | |||
var MaxCplForRefresh uint = 15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a constant (and private).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
table.go
Outdated
rt.tabLock.RLock() | ||
bucketLen := len(rt.Buckets) | ||
rt.tabLock.RUnlock() | ||
var cpls []*CplRefresh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's pre-allocate this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
table.go
Outdated
} | ||
// GetTrackedCplsForRefresh returns the Cpl's we are tracking for refresh. | ||
// Caller is free to modify the returned slice as it is a defensive copy. | ||
func (rt *RoutingTable) GetTrackedCplsForRefresh() []*CplRefresh { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can avoid a bunch of allocations by removing the pointer. That is, []CplRefresh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@Stebalien Have made the changes. Please take a look. Thank you ! :) Also, if you are happy with this & merge it, please can you cut a release so we can get the changes done in Dht. |
table.go
Outdated
targetCpl = uint(bucketID) | ||
i := 0 | ||
for c, t := range rt.cplRefreshedAt { | ||
cpls[i] = CplRefresh{c, t} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cpls := make([]CplRefresh, 0, len(rt.cplRefreshedAt))
...
for ... {
cpls = append(cpls, CplRefresh{c, t})
}
Make takes a type, length (optional), and capacity (optional). When building a slice with a known length, you can allocate with a known capacity to avoid having to re-allocate every time you run out of capacity.
@Stebalien Thanks for the slice make suggestion. Have made the change. Please can you merge & cut a release if you are happy with this ? |
@Stebalien
For libp2p/go-libp2p-kad-dht#406
Please review.