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:
oy 2018-11-21 12:17:27 +01:00
parent 1c05f9ad6a
commit 27012ac42d
5 changed files with 24 additions and 15 deletions

View file

@ -266,6 +266,7 @@ int CRegister::RegisterProcessPacket(CNetChunk *pPacket, TOKEN Token)
if(m_RegisterFirst && m_RegisterState != REGISTERSTATE_REGISTERED) if(m_RegisterFirst && m_RegisterState != REGISTERSTATE_REGISTERED)
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "no firewall/nat problems detected"); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "no firewall/nat problems detected");
RegisterNewState(REGISTERSTATE_REGISTERED); RegisterNewState(REGISTERSTATE_REGISTERED);
m_pNetServer->AddToken(&pPacket->m_Address, Token);
return 1; return 1;
} }
else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWERROR) && else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWERROR) &&

View file

@ -82,16 +82,19 @@ enum
NET_PACKETFLAG_CONNLESS=8, NET_PACKETFLAG_CONNLESS=8,
// token // token
NET_SEEDTIME = 10, NET_SEEDTIME = 16,
NET_TOKENCACHE_SIZE = 64, NET_TOKENCACHE_SIZE = 64,
NET_TOKENCACHE_ADDRESSEXPIRY = NET_SEEDTIME/2, NET_TOKENCACHE_ADDRESSEXPIRY = NET_SEEDTIME,
NET_TOKENCACHE_PACKETEXPIRY = NET_TOKENCACHE_ADDRESSEXPIRY, NET_TOKENCACHE_PACKETEXPIRY = 5,
NET_TOKEN_MAX = 0xfffff, NET_TOKEN_MAX = 0xfffff,
NET_TOKEN_NONE = NET_TOKEN_MAX, NET_TOKEN_NONE = NET_TOKEN_MAX,
NET_TOKEN_MASK = NET_TOKEN_MAX, NET_TOKEN_MASK = NET_TOKEN_MAX,
NET_TOKENFLAG_ALLOWBROADCAST = 1,
NET_TOKENFLAG_RESPONSEONLY = 2,
// //
NET_MAX_CLIENTS = 16, NET_MAX_CLIENTS = 16,
NET_MAX_CONSOLE_CLIENTS = 4, NET_MAX_CONSOLE_CLIENTS = 4,
@ -218,7 +221,7 @@ public:
void SendPacketConnless(const NETADDR *pAddr, const void *pData, int DataSize, CSendCBData *pCallbackData = 0); void SendPacketConnless(const NETADDR *pAddr, const void *pData, int DataSize, CSendCBData *pCallbackData = 0);
void PurgeStoredPacket(int TrackID); void PurgeStoredPacket(int TrackID);
void FetchToken(const NETADDR *pAddr); 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); TOKEN GetToken(const NETADDR *pAddr);
void Update(); void Update();
@ -423,6 +426,7 @@ public:
int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0); int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0);
int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE); int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE);
int Update(); int Update();
void AddToken(const NETADDR *pAddr, TOKEN Token) { m_TokenCache.AddToken(pAddr, Token, 0); };
// //
int Drop(int ClientID, const char *pReason); int Drop(int ClientID, const char *pReason);

View file

@ -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_Flags&NET_PACKETFLAG_CONTROL)
{ {
if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN) 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) else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS && Accept != -1)
{ {

View file

@ -212,7 +212,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken)
} }
} }
else if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN) 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) else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
{ {

View file

@ -255,28 +255,22 @@ void CNetTokenCache::FetchToken(const NETADDR *pAddr)
NET_CTRLMSG_TOKEN, m_pTokenManager->GenerateToken(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) if(Token == NET_TOKEN_NONE)
return; 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 // search the list of packets to be sent
// for this address // for this address
CConnlessPacketInfo *pPrevInfo = 0; CConnlessPacketInfo *pPrevInfo = 0;
CConnlessPacketInfo *pInfo = m_pConnlessPacketList; CConnlessPacketInfo *pInfo = m_pConnlessPacketList;
bool Found = false;
while(pInfo) while(pInfo)
{ {
static NETADDR NullAddr = { 0 }; static NETADDR NullAddr = { 0 };
NullAddr.type = 7; // cover broadcasts NullAddr.type = 7; // cover broadcasts
NullAddr.port = pAddr->port; 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 // notify the user that the packet gets delivered
if(pInfo->m_pfnCallback) if(pInfo->m_pfnCallback)
@ -301,6 +295,16 @@ void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, bool AllowBroad
pInfo = pInfo->m_pNext; 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() void CNetTokenCache::Update()