Skip to content

Correct peer outgoing address for incomming peers#244

Merged
ikatson merged 8 commits intoikatson:mainfrom
izderadicka:correct_peer_address
Oct 1, 2024
Merged

Correct peer outgoing address for incomming peers#244
ikatson merged 8 commits intoikatson:mainfrom
izderadicka:correct_peer_address

Conversation

@izderadicka
Copy link
Copy Markdown
Contributor

For live torrents peers are kept in DashMap with their SocketAddress as the key. Both outgoing and incoming peers are there.
For incoming peers SocketAddress key is the address of client, but it is used when retrying connection (in case of changing "only files" for instance). In these retries this address is used as peer listening address, which will not work. But we can have peer listening port and ip address from Extended Handshake, so this can be used instead, if available.

This PR is trying to implement this - only retry incoming peers if we know their listening address, otherwise keep them as not need (as we do not know where to connect them).

There is still an issue with the peers map, one peer can be there multiple times - once with outgoing listening SocketAddress and more times with client incoming SocketAddress - but to change this will require more significant change to logic - probably using Peer ID as key. So this is only partial fix, but it looks like having same peer in hash table does not cause problems.

Copy link
Copy Markdown
Owner

@ikatson ikatson left a comment

Choose a reason for hiding this comment

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

Looks good to me, but please address the 3-state comment

@ikatson
Copy link
Copy Markdown
Owner

ikatson commented Sep 29, 2024

You raise a very good point - that the "peers" map has SocketAddr as key, which doesn't make sense for incoming peers - as it promotes duplicates. Would be nice to fix it, but agree that it's a rather substantial refactor.

@izderadicka
Copy link
Copy Markdown
Contributor Author

Though not ideal still I think helps mainly in cases of "restarting" live torrent - by changing only files:

  • incoming peers will be retries only if we know their listening socket address

@ikatson ikatson merged commit abe4cf5 into ikatson:main Oct 1, 2024
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.

2 participants