mirror of https://github.com/redinet/redcore
Moved processing code for receive queue to redprocessor.h
This commit is contained in:
parent
5e7f9f9c32
commit
3f074bf9a9
|
@ -5,7 +5,7 @@ clean:
|
|||
rm testSend
|
||||
|
||||
redcore:
|
||||
gcc redcore.c redpacket.c route.c redhost.c redinterface.c redprotocol.c redctl.c -o redcore -Wconversion -Wsign-compare
|
||||
gcc redcore.c redpacket.c route.c redhost.c redinterface.c redprotocol.c redctl.c redprocessor.c -o redcore -Wconversion -Wsign-compare
|
||||
|
||||
testSend:
|
||||
gcc testSend.c redpacket.c -o testSend
|
||||
|
|
101
src/redcore.c
101
src/redcore.c
|
@ -70,6 +70,7 @@
|
|||
#include<unistd.h>
|
||||
#include "redprotocol.h"
|
||||
#include "redctl.h"
|
||||
#include "redprocessor.h"
|
||||
|
||||
/**
|
||||
* Prototypes (TODO: Own header file)
|
||||
|
@ -81,8 +82,6 @@ int eProcessorLoop();
|
|||
int iPacketLoop();
|
||||
int ePacketLoop();
|
||||
void startup(char**, long);
|
||||
void process(struct redPacket);
|
||||
void ingest(struct redPacket);
|
||||
char startSubsystems();
|
||||
void tidyUp();
|
||||
|
||||
|
@ -119,7 +118,7 @@ void config(char* filename)
|
|||
/* List of interface names to run on*/
|
||||
char** interfaceNames;
|
||||
|
||||
char isBroadcastAddress(unsigned long);
|
||||
|
||||
|
||||
int main(int argc, char** args)
|
||||
{
|
||||
|
@ -306,103 +305,7 @@ int eProcessorLoop()
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given address
|
||||
* is an address assigned to this redNode
|
||||
*
|
||||
* @param true if address is local, false
|
||||
* otherwise
|
||||
*/
|
||||
char isLocalAddress(long address)
|
||||
{
|
||||
return 1; /* TODO: Implement me */
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given address
|
||||
* is a broadcast address
|
||||
*
|
||||
* @param true if address is broadcast,
|
||||
* false otherwise
|
||||
*/
|
||||
char isBroadcastAddress(unsigned long address)
|
||||
{
|
||||
/* The broadcast address is all 1-bits/highest-value unsigned long */
|
||||
return address == -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a packet into the system
|
||||
* and passes it up to the correct
|
||||
* protocol handler
|
||||
*/
|
||||
void ingest(struct redPacket rp)
|
||||
{
|
||||
/* TODO: Implement the redControl handler */
|
||||
|
||||
printf("Ingestion happenine\n");
|
||||
|
||||
/**
|
||||
* If the protocol type is 0, then
|
||||
* handle the redControl packet
|
||||
*/
|
||||
if(!rp.type)
|
||||
{
|
||||
/* TODO: Implement */
|
||||
}
|
||||
/* Search for a protocol handler */
|
||||
else
|
||||
{
|
||||
/* TODO: Implement protocol handlers array search */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void process(struct redPacket rp)
|
||||
{
|
||||
/* Only continue if the version is 0 */
|
||||
if(!rp.version)
|
||||
{
|
||||
/* TODO: Destination address handling */
|
||||
/**
|
||||
* If the address is a broadcast address
|
||||
* or one of ours
|
||||
*/
|
||||
if(isBroadcastAddress(rp.destination) || isLocalAddress(rp.destination))
|
||||
{
|
||||
/* Accept the redPacket into the protocol dispatcher */
|
||||
printf("Packet destined to us\n");
|
||||
ingest(rp);
|
||||
}
|
||||
/* TODO: Multicast handling */
|
||||
/* If the packet wasn't destined to us */
|
||||
else
|
||||
{
|
||||
/* TODO: Check if forwarding is enabled */
|
||||
if(isForwarding)
|
||||
{
|
||||
/* TODO: Implement forwarding */
|
||||
|
||||
/* TODO: Implement ttl check before anything else */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Drop it */
|
||||
printf("Received packet with address not destined to us, dropping (forwarding disabled)\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* TODO: Possible source address handling */
|
||||
|
||||
/* TODO: Dependant on destination address, check TTL */
|
||||
}
|
||||
/* If not, then drop the redPacket */
|
||||
else
|
||||
{
|
||||
printf("Dropping redPacket with non-zero version field: %u\n", rp.version);
|
||||
}
|
||||
}
|
||||
|
||||
void initializeProtocolHandlers(struct redProtocol* protocols, long count)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
extern char isForwarding;
|
||||
|
||||
#include "redpacket.h"
|
||||
|
||||
/**
|
||||
* Returns true if the given address
|
||||
* is an address assigned to this redNode
|
||||
*
|
||||
* @param true if address is local, false
|
||||
* otherwise
|
||||
*/
|
||||
char isLocalAddress(long address)
|
||||
{
|
||||
return 1; /* TODO: Implement me */
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given address
|
||||
* is a broadcast address
|
||||
*
|
||||
* @param true if address is broadcast,
|
||||
* false otherwise
|
||||
*/
|
||||
char isBroadcastAddress(unsigned long address)
|
||||
{
|
||||
/* The broadcast address is all 1-bits/highest-value unsigned long */
|
||||
return address == -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a packet into the system
|
||||
* and passes it up to the correct
|
||||
* protocol handler
|
||||
*/
|
||||
void ingest(struct redPacket rp)
|
||||
{
|
||||
/* TODO: Implement the redControl handler */
|
||||
|
||||
printf("Ingestion happenine\n");
|
||||
|
||||
/**
|
||||
* If the protocol type is 0, then
|
||||
* handle the redControl packet
|
||||
*/
|
||||
if(!rp.type)
|
||||
{
|
||||
/* TODO: Implement */
|
||||
}
|
||||
/* Search for a protocol handler */
|
||||
else
|
||||
{
|
||||
/* TODO: Implement protocol handlers array search */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void process(struct redPacket rp)
|
||||
{
|
||||
/* Only continue if the version is 0 */
|
||||
if(!rp.version)
|
||||
{
|
||||
/* TODO: Destination address handling */
|
||||
/**
|
||||
* If the address is a broadcast address
|
||||
* or one of ours
|
||||
*/
|
||||
if(isBroadcastAddress(rp.destination) || isLocalAddress(rp.destination))
|
||||
{
|
||||
/* Accept the redPacket into the protocol dispatcher */
|
||||
printf("Packet destined to us\n");
|
||||
ingest(rp);
|
||||
}
|
||||
/* TODO: Multicast handling */
|
||||
/* If the packet wasn't destined to us */
|
||||
else
|
||||
{
|
||||
/* TODO: Check if forwarding is enabled */
|
||||
if(isForwarding)
|
||||
{
|
||||
/* TODO: Implement forwarding */
|
||||
|
||||
/* TODO: Implement ttl check before anything else */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Drop it */
|
||||
printf("Received packet with address not destined to us, dropping (forwarding disabled)\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* TODO: Possible source address handling */
|
||||
|
||||
/* TODO: Dependant on destination address, check TTL */
|
||||
}
|
||||
/* If not, then drop the redPacket */
|
||||
else
|
||||
{
|
||||
printf("Dropping redPacket with non-zero version field: %u\n", rp.version);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
void process(struct redPacket);
|
||||
void ingest(struct redPacket);
|
||||
char isBroadcastAddress(unsigned long);
|
||||
char isLocalAddress(long);
|
Loading…
Reference in New Issue