You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @Nehliin, as discussed in #91, I'd like to take on this issue. I'm mostly familiar with the CLI and still getting used to the core code, so I'll ask any specific questions here. Thanks!
Hey @Nehliin, quick question about implementing the sorting, I wanted to double-check a couple of structural things:
I added my new PeerPriority struct inside src/peer_comm/canonical_priority.rs to handle the calculations. Let me know if that's the right module/file layout.
For applying it, I found the Command::ConnectToPeers arm inside handle_commands in bittorrent/src/event_loop.rs:
for addr in addrs.into_iter().map(|addr| addr.into()){
connection_manager.maybe_connect_to_peer(addr, io);}
Should I sort and check the priorities right here in this loop before connecting, or is that sorting logic supposed to happen somewhere else (like connection manager) instead?
Also, to calculate the priority we need our own listening SocketAddr (our_addr) as one of the inputs. Where can I find that inside the event loop?
I do not currently have a strong opinion where the calculation can live in the structure so peer_comm/canonical_priority could work! Start with that and we can evaluate during PR review later on.
Yes! That's where I want the prioritization to take effect, but I think it makes more sense to move the logic into the connection manager itself. So I think we should change the api for the connection_manager to instead accept a list of peers and both sort + determine if they have been banned or not. You can add a connect_to_peers method that accepts the list and under the hood does the snippet you posted + the sorting.
The listening adder of the socket can be propagated to the ConnectionManager::new function and it can save it internally for future calculations. Look at the run method inside of the EventLoop there you see the listener being provided as an argument. Use that to propagate the SocketAddr to the connection manager.
Hope that clarifies things! Let me know if you have more questions
Activity
tkalum commentedon Oct 20, 2026
Hi @Nehliin, as discussed in #91, I'd like to take on this issue. I'm mostly familiar with the CLI and still getting used to the core code, so I'll ask any specific questions here. Thanks!
tkalum commentedon Oct 25, 2026
Hey @Nehliin, quick question about implementing the sorting, I wanted to double-check a couple of structural things:
I added my new
PeerPrioritystruct insidesrc/peer_comm/canonical_priority.rsto handle the calculations. Let me know if that's the right module/file layout.For applying it, I found the
Command::ConnectToPeersarm inside handle_commands inbittorrent/src/event_loop.rs:Should I sort and check the priorities right here in this loop before connecting, or is that sorting logic supposed to happen somewhere else (like connection manager) instead?
Also, to calculate the priority we need our own listening SocketAddr (our_addr) as one of the inputs. Where can I find that inside the event loop?
Nehliin commentedon Oct 25, 2026
I do not currently have a strong opinion where the calculation can live in the structure so peer_comm/canonical_priority could work! Start with that and we can evaluate during PR review later on.
Yes! That's where I want the prioritization to take effect, but I think it makes more sense to move the logic into the connection manager itself. So I think we should change the api for the connection_manager to instead accept a list of peers and both sort + determine if they have been banned or not. You can add a
connect_to_peersmethod that accepts the list and under the hood does the snippet you posted + the sorting.The listening adder of the socket can be propagated to the
ConnectionManager::newfunction and it can save it internally for future calculations. Look at therunmethod inside of theEventLoopthere you see thelistenerbeing provided as an argument. Use that to propagate the SocketAddr to the connection manager.Hope that clarifies things! Let me know if you have more questions