mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
only add tokens to the catch on request. increased seedtime and expire time for tokens in the cache to sync it better with the master heartbeats
This commit is contained in:
parent
1c05f9ad6a
commit
27012ac42d
|
@ -266,6 +266,7 @@ int CRegister::RegisterProcessPacket(CNetChunk *pPacket, TOKEN Token)
|
|||
if(m_RegisterFirst && m_RegisterState != REGISTERSTATE_REGISTERED)
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "no firewall/nat problems detected");
|
||||
RegisterNewState(REGISTERSTATE_REGISTERED);
|
||||
m_pNetServer->AddToken(&pPacket->m_Address, Token);
|
||||
return 1;
|
||||
}
|
||||
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWERROR) &&
|
||||
|
|
|
@ -82,16 +82,19 @@ enum
|
|||
NET_PACKETFLAG_CONNLESS=8,
|
||||
|
||||
// token
|
||||
NET_SEEDTIME = 10,
|
||||
NET_SEEDTIME = 16,
|
||||
|
||||
NET_TOKENCACHE_SIZE = 64,
|
||||
NET_TOKENCACHE_ADDRESSEXPIRY = NET_SEEDTIME/2,
|
||||
NET_TOKENCACHE_PACKETEXPIRY = NET_TOKENCACHE_ADDRESSEXPIRY,
|
||||
NET_TOKENCACHE_ADDRESSEXPIRY = NET_SEEDTIME,
|
||||
NET_TOKENCACHE_PACKETEXPIRY = 5,
|
||||
|
||||
NET_TOKEN_MAX = 0xfffff,
|
||||
NET_TOKEN_NONE = NET_TOKEN_MAX,
|
||||
NET_TOKEN_MASK = NET_TOKEN_MAX,
|
||||
|
||||
NET_TOKENFLAG_ALLOWBROADCAST = 1,
|
||||
NET_TOKENFLAG_RESPONSEONLY = 2,
|
||||
|
||||
//
|
||||
NET_MAX_CLIENTS = 16,
|
||||
NET_MAX_CONSOLE_CLIENTS = 4,
|
||||
|
@ -218,7 +221,7 @@ public:
|
|||
void SendPacketConnless(const NETADDR *pAddr, const void *pData, int DataSize, CSendCBData *pCallbackData = 0);
|
||||
void PurgeStoredPacket(int TrackID);
|
||||
void FetchToken(const NETADDR *pAddr);
|
||||
void AddToken(const NETADDR *pAddr, TOKEN PeerToken, bool AllowBroadcasts);
|
||||
void AddToken(const NETADDR *pAddr, TOKEN PeerToken, int TokenFlag);
|
||||
TOKEN GetToken(const NETADDR *pAddr);
|
||||
void Update();
|
||||
|
||||
|
@ -423,6 +426,7 @@ public:
|
|||
int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0);
|
||||
int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE);
|
||||
int Update();
|
||||
void AddToken(const NETADDR *pAddr, TOKEN Token) { m_TokenCache.AddToken(pAddr, Token, 0); };
|
||||
|
||||
//
|
||||
int Drop(int ClientID, const char *pReason);
|
||||
|
|
|
@ -97,7 +97,7 @@ int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken)
|
|||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL)
|
||||
{
|
||||
if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN)
|
||||
m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, true);
|
||||
m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, NET_TOKENFLAG_ALLOWBROADCAST|NET_TOKENFLAG_RESPONSEONLY);
|
||||
}
|
||||
else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS && Accept != -1)
|
||||
{
|
||||
|
|
|
@ -212,7 +212,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken)
|
|||
}
|
||||
}
|
||||
else if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN)
|
||||
m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, false);
|
||||
m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, NET_TOKENFLAG_RESPONSEONLY);
|
||||
}
|
||||
else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
|
||||
{
|
||||
|
|
|
@ -255,28 +255,22 @@ void CNetTokenCache::FetchToken(const NETADDR *pAddr)
|
|||
NET_CTRLMSG_TOKEN, m_pTokenManager->GenerateToken(pAddr));
|
||||
}
|
||||
|
||||
void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, bool AllowBroadcasts)
|
||||
void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, int TokenFLag)
|
||||
{
|
||||
if(Token == NET_TOKEN_NONE)
|
||||
return;
|
||||
|
||||
CAddressInfo Info;
|
||||
Info.m_Addr = *pAddr;
|
||||
Info.m_Token = Token;
|
||||
Info.m_Expiry = time_get() + time_freq() * NET_TOKENCACHE_ADDRESSEXPIRY;
|
||||
|
||||
(*m_TokenCache.Allocate(sizeof(Info))) = Info;
|
||||
|
||||
// search the list of packets to be sent
|
||||
// for this address
|
||||
CConnlessPacketInfo *pPrevInfo = 0;
|
||||
CConnlessPacketInfo *pInfo = m_pConnlessPacketList;
|
||||
bool Found = false;
|
||||
while(pInfo)
|
||||
{
|
||||
static NETADDR NullAddr = { 0 };
|
||||
NullAddr.type = 7; // cover broadcasts
|
||||
NullAddr.port = pAddr->port;
|
||||
if(net_addr_comp(&pInfo->m_Addr, pAddr) == 0 || (AllowBroadcasts && net_addr_comp(&pInfo->m_Addr, &NullAddr) == 0))
|
||||
if(net_addr_comp(&pInfo->m_Addr, pAddr) == 0 || ((TokenFLag&NET_TOKENFLAG_ALLOWBROADCAST) && net_addr_comp(&pInfo->m_Addr, &NullAddr) == 0))
|
||||
{
|
||||
// notify the user that the packet gets delivered
|
||||
if(pInfo->m_pfnCallback)
|
||||
|
@ -301,6 +295,16 @@ void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, bool AllowBroad
|
|||
pInfo = pInfo->m_pNext;
|
||||
}
|
||||
}
|
||||
|
||||
// add the token
|
||||
if(Found || !(TokenFLag&NET_TOKENFLAG_RESPONSEONLY))
|
||||
{
|
||||
CAddressInfo Info;
|
||||
Info.m_Addr = *pAddr;
|
||||
Info.m_Token = Token;
|
||||
Info.m_Expiry = time_get() + time_freq() * NET_TOKENCACHE_ADDRESSEXPIRY;
|
||||
(*m_TokenCache.Allocate(sizeof(Info))) = Info;
|
||||
}
|
||||
}
|
||||
|
||||
void CNetTokenCache::Update()
|
||||
|
|
Loading…
Reference in a new issue