Use stun servers that return XOR mapped address

This commit is contained in:
Benau 2018-03-02 22:38:04 +08:00
parent 4f9af9d438
commit 4e2863294d
2 changed files with 30 additions and 27 deletions

View File

@ -719,31 +719,17 @@ namespace UserConfigParams
PARAM_PREFIX StringListUserConfigParam m_stun_servers
PARAM_DEFAULT( StringListUserConfigParam("Stun_servers", "The stun servers"
" that will be used to know the public address.",
24,
"provserver.televolution.net",
"sip1.lakedestiny.cordiaip.com",
"stun1.voiceeclipse.net",
"stun01.sipphone.com",
10,
"stun.cope.es",
"stun.12connect.com",
"stun.callwithus.com",
"stun.counterpath.net",
"stun.endigovoip.com",
"stun.ekiga.net",
"stun.ideasip.com",
"stun.internetcalls.com",
"stun.ipns.com",
"stun.noc.ams-ix.net",
"stun.phonepower.com",
"stun.phoneserve.com",
"stun.rnktel.com",
"stun.softjoys.com",
"stunserver.org",
"stun.sipgate.net",
"stun.schlund.de",
"stun.stunprotocol.org",
"stun.voip.aebc.com",
"stun.voipbuster.com",
"stun.voxalot.com",
"stun.voxgratia.org",
"stun.xten.com") );
"numb.viagenie.ca",
"stun.ivao.aero") );
// ---- Gamemode setup
PARAM_PREFIX IntToIntUserConfigParam m_num_karts_per_gamemode

View File

@ -506,12 +506,11 @@ void STKHost::setPublicAddress()
// The stun message is valid, so we parse it now:
// Those are the port and the address to be detected
bool found = false;
TransportAddress non_xor_addr, xor_addr;
while (true)
{
if (response.size() < 4)
{
Log::error("STKHost", "STUN response is invalid.");
break;
}
unsigned type = response.getUInt16();
@ -558,11 +557,14 @@ void STKHost::setPublicAddress()
// Obfuscation is described in Section 15.2 of RFC 5389.
port ^= magic_cookie >> 16;
ip ^= magic_cookie;
xor_addr.setPort(port);
xor_addr.setIP(ip);
}
else
{
non_xor_addr.setPort(port);
non_xor_addr.setIP(ip);
}
m_public_address.setPort(port);
m_public_address.setIP(ip);
found = true;
break;
} // type == mapped_address || type == xor_mapped_address
else
{
@ -573,8 +575,23 @@ void STKHost::setPublicAddress()
}
} // while true
// Found public address and port
if (found)
if (!xor_addr.isUnset() || !non_xor_addr.isUnset())
{
// Use XOR mapped address when possible to avoid translation of
// the packet content by application layer gateways (ALGs) that
// perform deep packet inspection in an attempt to perform
// alternate NAT traversal methods.
if (!xor_addr.isUnset())
{
m_public_address.copy(xor_addr);
}
else
{
Log::warn("STKHost", "Only non xor-mapped address returned.");
m_public_address.copy(non_xor_addr);
}
untried_server.clear();
}
}
} // setPublicAddress