-
Notifications
You must be signed in to change notification settings - Fork 214
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
[Merged by Bors] - fetch: check if hash peer is connected before using it #4939
Changes from 2 commits
1d4c8e5
2add05e
265f827
6f16791
58648df
f1ee5cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,18 +482,28 @@ func (f *Fetch) organizeRequests(requests []RequestMessage) map[p2p.Peer][][]Req | |
} | ||
return nil | ||
} | ||
pm := map[p2p.Peer]struct{}{} | ||
for _, p := range peers { | ||
pm[p] = struct{}{} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it is better to ask host.Connected or something like that. creating a map from peer list on every request is not ideal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks. will add a method that checks fh.Network().Connectedness(p) == network.Connected |
||
|
||
for _, req := range requests { | ||
p, exists := f.hashToPeers.GetRandom(req.Hash, req.Hint, rng) | ||
if !exists { | ||
p = randomPeer(peers) | ||
target := p2p.NoPeer | ||
hashPeers := f.hashToPeers.GetRandom(req.Hash, req.Hint, rng) | ||
for _, p := range hashPeers { | ||
if _, ok := pm[p]; ok { | ||
target = p | ||
break | ||
} | ||
} | ||
|
||
_, ok := peer2requests[p] | ||
if target == p2p.NoPeer { | ||
target = randomPeer(peers) | ||
} | ||
_, ok := peer2requests[target] | ||
if !ok { | ||
peer2requests[p] = []RequestMessage{req} | ||
peer2requests[target] = []RequestMessage{req} | ||
} else { | ||
peer2requests[p] = append(peer2requests[p], req) | ||
peer2requests[target] = append(peer2requests[target], req) | ||
} | ||
} | ||
|
||
|
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.
maps.Keys
extracts the keys from amap
by ranging over it.range
for maps doesn't produce a deterministic order:https://go.dev/play/p/nImOnOek6c3
So shuffling might not be necessary.