-
Notifications
You must be signed in to change notification settings - Fork 37
Conversation
makes TestDialBackoff happy
|
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.
In terms of testing, the codecov comments are actually pretty useful.
} | ||
|
||
// the request has some pending or new dials, track it and schedule new dials | ||
reqno++ |
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 also just use the request object as a key, right?
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.
Not really. We need to pack request ids in the addrDial
struct and then check to see if they have been complete (removed from the tracking).
If we used the request object as key we'd have to copy the requests all over the place and then do extra management stuff to keep them up-to-date.
What's wrong with using an integer? It doesn't cost anything.
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.
It works, it's just something else to track.
If we used the request object as key we'd have to copy the requests all over the place and then do extra management stuff to keep them up-to-date.
Can't we use the pointers? No need to copy anything and should be the same size as an int.
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.
(obviously not a huge deal)
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.
Well, we could use a req pointer but then we'd have to reify the struct and move it to the heap -- which is strictly worse than using integers, because there is one more thing for the gc to track. Not a huge impact though.
I would agree with tracking overhead, but the way we use the integers is really simple,
The reqno is incremented at exactly one place, right before we add to the tracking map, so there is very little mental overhead involved.
I am really inclined to leave it as is, unless you feel very strongly about it.
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.
I'm happy to leave it as it is, but I think I'm confused about something. The request is allocated here:
and we're storing it by reference in the requests
map. It should be possible to just change the requests map to map[*pendRequest]struct{}
. and ad.requests
to []*pendRequest
.
Actually... I think we can even get rid of the requests
map.
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.
We can't that easily, we will have to track what request is still active.
That's the main reason for the indirection, and that's why I like the integers as pointers approach -- it forces you to check for validity when you want to use it.
First pass review. I like the approach. |
i want to use binary literals; technically only requires 1.13, but let's not be ancient
for consistency with the old dialer behaviour.
we might get more connections because simultaneous dials can succeed and we have both TCP and QUIC addrs by default
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.
Looking good but I want to take a closer look when I'm more awake (got a bit distracted today).
However, can we please break the batching into a separate PR? This PR is already very large and the batching going to trigger another few rounds of discussion.
} | ||
|
||
// the request has some pending or new dials, track it and schedule new dials | ||
reqno++ |
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.
(obviously not a huge deal)
Sure, I'll do that after fixing the test package situation. |
Removed the dial batching -- follow up pr in #252. |
967e89f
to
01014c8
Compare
so that we exercise the dialWorker dial to self error path
01014c8
to
43b0382
Compare
they work with private data types, so there is no point in having them public
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.
Nice! We'll have to deploy this on infra to test but we might as well merge it now then back out if we find an issue.
} | ||
|
||
// the request has some pending or new dials, track it and schedule new dials | ||
reqno++ |
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.
I'm happy to leave it as it is, but I think I'm confused about something. The request is allocated here:
and we're storing it by reference in the requests
map. It should be possible to just change the requests map to map[*pendRequest]struct{}
. and ad.requests
to []*pendRequest
.
Actually... I think we can even get rid of the requests
map.
return goodAddrs, nil | ||
} | ||
|
||
func (s *Swarm) mergeDialContexts(a, b context.Context) context.Context { |
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.
I really don't like this but let's punt on making any more changes till a followup.
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.
ok, fair enough.
// NonWS > WS | ||
// Private > Public | ||
// UDP > TCP | ||
func (s *Swarm) rankAddrs(addrs []ma.Multiaddr) []ma.Multiaddr { |
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.
Is this really any better?
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.
Hm. Yes it is.
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.
It's consistent, the code is not a jumble mess of ifs, and it is extensible...
// Private > Public | ||
// UDP > TCP | ||
func (s *Swarm) rankAddrs(addrs []ma.Multiaddr) []ma.Multiaddr { | ||
addrTier := func(a ma.Multiaddr) (tier int) { |
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 could make this more generic by ranking according to a list of functions.
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.
I.e.:
var rankFunctions = []func(ma.Multiaddr) bool{}
func rank(m ma.Multiaddr) int {
rank := 0
for i, f := range rankFunctions {
if f(m) {
rank |= (1<<i)
}
}
return rank
}
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.
yes, we could -- let's keep this in mind for subsequent iterations; it's just 4 bits now.
@vyzo merge when ready. This is a great step forward. |
Alternative to #246
This implements a join/split algorithm for synchronizing simultaneous dials through a dial worker.