if(isClient != 0) context->flags |= 0x2;
context->threadFlags = 0;
context->conMap = UDPC_HashMap_init(13, sizeof(UDPC_INTERNAL_ConnectionData));
+ context->idMap = UDPC_HashMap_init(13, sizeof(UDPC_INTERNAL_ConnectionData*));
timespec_get(&context->lastUpdated, TIME_UTC);
context->atostrBuf[UDPC_ATOSTR_BUF_SIZE - 1] = 0;
context->connectedEvents = UDPC_Deque_init(
CleanupSocket(ctx->socketHandle);
UDPC_HashMap_itercall(ctx->conMap, UDPC_INTERNAL_destroy_conMap, NULL);
UDPC_HashMap_destroy(ctx->conMap);
+ UDPC_HashMap_destroy(ctx->idMap);
UDPC_Deque_destroy(ctx->connectedEvents);
UDPC_Deque_destroy(ctx->disconnectedEvents);
}
UDPC_Deque_destroy(cd->priorityPktQueue);
+ if((cd->flags & 0x10) != 0)
+ {
+ UDPC_HashMap_remove(ctx->idMap, cd->id);
+ }
UDPC_HashMap_remove(ctx->conMap, *key);
}
UDPC_Deque_destroy(us.removedQueue);
UDPC_INTERNAL_atostr(ctx, receivedData.sin_addr.s_addr),
ntohs(receivedData.sin_port));
UDPC_INTERNAL_ConnectionData newCD = {
- 0x9,
+ 0x19,
UDPC_INTERNAL_generate_id(ctx),
0,
0,
0.0f
};
UDPC_HashMap_insert(ctx->conMap, newCD.addr, &newCD);
+ UDPC_HashMap_insert(ctx->idMap, newCD.id, UDPC_HashMap_get(ctx->conMap, newCD.addr));
if(UDPC_Deque_get_available(ctx->connectedEvents) == 0)
{
UDPC_Deque_pop_front(ctx->connectedEvents, 4);
if(!cd) { return; }
cd->flags &= 0xFFFFFFF7;
+ cd->flags |= 0x10;
cd->id = conID;
UDPC_INTERNAL_log(ctx, 2, "Got id %u from server %s", conID,
UDPC_INTERNAL_atostr(ctx, receivedData.sin_addr.s_addr));
while(newID == 0x10000000)
{
newID = rand() % 0x10000000;
- UDPC_HashMap_itercall(ctx->conMap, UDPC_INTERNAL_check_ids, &newID);
+ if(UDPC_HashMap_has(ctx->idMap, newID) != 0)
+ {
+ newID = 0x10000000;
+ }
}
return newID;
}
-void UDPC_INTERNAL_check_ids(void *userData, uint32_t addr, char *data)
-{
- UDPC_INTERNAL_ConnectionData *cd = (UDPC_INTERNAL_ConnectionData*)data;
- if(cd->id == *((uint32_t*)userData))
- {
- *((uint32_t*)userData) = 0x10000000;
- }
-}
-
uint32_t UDPC_strtoa(const char *addrStr)
{
uint32_t addr = 0;
* 0x1 - trigger send
* 0x2 - is good mode
* 0x4 - is good rtt
- * 0x8 - is id not set yet / initiating connection to server
+ * 0x8 - initiating connection to server
+ * 0x10 - is id set
*/
uint32_t flags;
uint32_t id;
mtx_t tflagsMtx;
cnd_t threadCV;
UDPC_HashMap *conMap;
+ UDPC_HashMap *idMap;
struct timespec lastUpdated;
char atostrBuf[UDPC_ATOSTR_BUF_SIZE];
char recvBuf[UDPC_PACKET_MAX_SIZE];
uint32_t UDPC_INTERNAL_generate_id(UDPC_Context *ctx);
-void UDPC_INTERNAL_check_ids(void *userData, uint32_t addr, char *data);
-
/*1
* \brief Converts a IPV4 string to a 32-bit unsigned integer address in big-endian
* \return 0 if string is invalid, address in big-endian format otherwise