prepend the agent types of interest with the number that follow

This commit is contained in:
Stephen Birarda 2013-06-10 12:18:25 -07:00
parent 5efff3857a
commit ed79a9f72a
2 changed files with 9 additions and 8 deletions

View file

@ -127,14 +127,14 @@ int main(int argc, const char * argv[])
currentBufferPos = broadcastPacket + sizeof(PACKET_HEADER);
startPointer = currentBufferPos;
char* agentTypesOfInterest = (char*) currentBufferPos + sizeof(AGENT_TYPE) + numBytesSocket;
int numInterestTypes = strlen(agentTypesOfInterest);
char* agentTypesOfInterest = (char*) currentBufferPos + sizeof(AGENT_TYPE) + numBytesSocket + sizeof(unsigned char);
int numInterestTypes = *(agentTypesOfInterest - 1);
if (numInterestTypes > 0) {
// if the agent has sent no types of interest, assume they want nothing but their own ID back
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)
&& memchr(agentTypesOfInterest, agent->getType(), strlen(agentTypesOfInterest))) {
&& memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) {
// this is not the agent themselves
// and this is an agent of a type in the passed agent types of interest
// or the agent did not pass us any specific types they are interested in

View file

@ -208,11 +208,11 @@ void AgentList::sendDomainServerCheckIn() {
static unsigned char* checkInPacket = NULL;
if (!checkInPacket) {
int numBytesAgentsOfInterest = _agentTypesOfInterest ? strlen((char*) _agentTypesOfInterest) : NULL;
int numBytesAgentsOfInterest = _agentTypesOfInterest ? strlen((char*) _agentTypesOfInterest) : 0;
// check in packet has header, agent type, port, IP, agent types of interest, null termination
int numPacketBytes = sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE) + sizeof(uint16_t) + (sizeof(char) * 4) +
numBytesAgentsOfInterest + sizeof(char);
numBytesAgentsOfInterest + sizeof(unsigned char);
checkInPacket = new unsigned char[numPacketBytes];
@ -223,14 +223,15 @@ void AgentList::sendDomainServerCheckIn() {
packSocket(checkInPacket + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE), getLocalAddress(), htons(_socketListenPort));
// add the number of bytes for agent types of interest
checkInPacket[numPacketBytes] = numBytesAgentsOfInterest;
// copy over the bytes for agent types of interest, if required
if (numBytesAgentsOfInterest > 0) {
memcpy(checkInPacket + numPacketBytes - sizeof(char) - numBytesAgentsOfInterest,
memcpy(checkInPacket + numPacketBytes + sizeof(unsigned char),
_agentTypesOfInterest,
numBytesAgentsOfInterest);
}
checkInPacket[numPacketBytes - 1] = '\0';
}
_agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, strlen((char*) checkInPacket));