handle IPv6 NAT during LTEP handshake (#5565)

* fix: peer handshake reported wrong ipv6 address

https://github.com/transmission/transmission/issues/5542#issuecomment-1556710922
This commit is contained in:
tearfur 2023-06-19 08:06:31 +08:00 committed by GitHub
parent fd583ac878
commit b8ff35c4ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -958,10 +958,14 @@ void sendLtepHandshake(tr_peerMsgsImpl* msgs)
tr_variantInitDict(&val, 8);
tr_variantDictAddBool(&val, TR_KEY_e, msgs->session->encryptionMode() != TR_CLEAR_PREFERRED);
if (auto const addr = msgs->session->publicAddress(TR_AF_INET6); !addr.is_any())
// If connecting to global peer, then use global address
// Otherwise we are connecting to local peer, use bind address directly
if (auto const addr = msgs->io->address().is_global_unicast_address() ? msgs->session->global_address(TR_AF_INET6) :
msgs->session->publicAddress(TR_AF_INET6);
addr && !addr->is_any())
{
TR_ASSERT(addr.is_ipv6());
tr_variantDictAddRaw(&val, TR_KEY_ipv6, &addr.addr.addr6, sizeof(addr.addr.addr6));
TR_ASSERT(addr->is_ipv6());
tr_variantDictAddRaw(&val, TR_KEY_ipv6, &addr->addr.addr6, sizeof(addr->addr.addr6));
}
// http://bittorrent.org/beps/bep_0009.html