PUD: remove nodeId cache from wireformat library
authorFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 3 Feb 2012 14:48:53 +0000 (15:48 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 14 Feb 2012 13:32:59 +0000 (14:32 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/configuration.c
lib/pud/src/gpsConversion.c
lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h
lib/pud/wireformat/src/wireFormat.c

index 890c66d..c323da1 100644 (file)
@@ -329,13 +329,7 @@ static bool setupNodeIdBinaryMAC(void) {
        memcpy(&nodeIdBinary.mac, mac, PUD_NODEIDTYPE_MAC_BYTES);
        nodeIdBinaryLength = PUD_NODEIDTYPE_MAC_BYTES;
        nodeIdBinarySet = true;
-
-       if (setupNodeIdBinaryBufferForOlsrCache(mac, PUD_NODEIDTYPE_MAC_BYTES)) {
-               return true;
-       }
-
-       pudError(false, "%s value \"MAC address\" could not be setup", PUD_NODE_ID_NAME);
-       return false;
+       return true;
 }
 
 /**
@@ -378,12 +372,7 @@ static bool setupNodeIdBinaryLongLong(unsigned long long min,
 
        nodeIdBinaryLength = bytes;
        nodeIdBinarySet = true;
-
-       if (setupNodeIdBinaryBufferForOlsrCache(&nodeIdBinary.longValue, bytes)) {
-               return true;
-       }
-
-       return false;
+       return true;
 }
 
 /**
@@ -416,14 +405,7 @@ static bool setupNodeIdBinaryString(void) {
        memcpy(&nodeIdBinary.stringValue[0], &nodeid[0], nodeidlength + 1);
        nodeIdBinaryLength = nodeIdLength + 1;
        nodeIdBinarySet = true;
-
-       /* including trailing \0 */
-       if (setupNodeIdBinaryBufferForOlsrCache(&nodeid[0], nodeidlength + 1)) {
-               return true;
-       }
-
-       pudError(false, "%s value \"%s\" is too long", PUD_NODE_ID_NAME, &nodeid[0]);
-       return false;
+       return true;
 }
 
 /**
@@ -448,13 +430,7 @@ static bool setupNodeIdBinaryIp(void) {
        memcpy(&nodeIdBinary.ip, src, length);
        nodeIdBinaryLength = length;
        nodeIdBinarySet = true;
-
-       if (setupNodeIdBinaryBufferForOlsrCache(src, length)) {
-               return true;
-       }
-
-       pudError(false, "%s value \"OLSRd main IP address\" could not be setup", PUD_NODE_ID_NAME);
-       return false;
+       return true;
 }
 
 /**
index 1d613dc..bed7720 100644 (file)
@@ -258,10 +258,9 @@ unsigned int gpsToOlsr(nmeaINFO *nmeaInfo, union olsr_message *olsrMessage,
                unsigned int olsrMessageSize, unsigned long long validityTime) {
        unsigned int aligned_size;
        unsigned int aligned_size_remainder;
-       NodeIdType nodeIdType;
-       unsigned char * nodeId;
-       size_t nodeIdLength;
        size_t nodeLength;
+       size_t nodeidbinarylength;
+       unsigned char * nodeidbinary = NULL;
 
        PudOlsrPositionUpdate * olsrGpsMessage =
                        getOlsrMessagePayload(olsr_cnf->ip_version, olsrMessage);
@@ -317,17 +316,9 @@ unsigned int gpsToOlsr(nmeaINFO *nmeaInfo, union olsr_message *olsrMessage,
                setPositionUpdateHdop(olsrGpsMessage, PUD_HDOP_MAX);
        }
 
-       nodeIdType = getNodeIdTypeNumber();
-       if (unlikely(nodeIdType == PUD_NODEIDTYPE_MAC)) {
-               nodeLength = setPositionUpdateNodeInfo(olsr_cnf->ip_version,
-                               olsrGpsMessage, olsrMessageSize, nodeIdType,
-                               getMainIpMacAddress(), PUD_NODEIDTYPE_MAC_BYTES);
-       } else {
-               nodeId = getNodeIdWithLength(&nodeIdLength);
-               nodeLength = setPositionUpdateNodeInfo(olsr_cnf->ip_version,
-                               olsrGpsMessage, olsrMessageSize, nodeIdType, nodeId,
-                               nodeIdLength);
-       }
+       nodeidbinary = getNodeIdBinaryWithLength(&nodeidbinarylength);
+       nodeLength = setPositionUpdateNodeInfo(olsr_cnf->ip_version, olsrGpsMessage,
+                       olsrMessageSize, getNodeIdTypeNumber(), nodeidbinary, nodeidbinarylength);
 
        /*
         * Messages in OLSR are 4-byte aligned: align
index 9a13207..018a4d8 100644 (file)
@@ -885,8 +885,6 @@ static inline void setPositionUpdateHdop(PudOlsrPositionUpdate * olsrGpsMessage,
  * NodeInfo
  */
 
-bool setupNodeIdBinaryBufferForOlsrCache(void * val, size_t bytes);
-
 /**
  Get the nodeIdType of the position update message
 
index ccceae8..f969291 100644 (file)
@@ -22,45 +22,6 @@ static void setupCachedValidityTimeMsn(void) {
        cachedValidityTimeMsnValid = true;
 }
 
-/* ************************************************************************
- * NODEID CACHE
- * ************************************************************************ */
-
-/** The size of the cached nodeId buffer */
-#define PUD_CACHED_NODEID_BUFFER_SIZE 256
-
-/** The cached nodeId buffer: contains a pre-processed version of the nodeId
- in order to improve performance. It is currently used for nodeIdTypes
- PUD_NODEIDTYPE_MSISDN, PUD_NODEIDTYPE_TETRA, PUD_NODEIDTYPE_MMSI,
- PUD_NODEIDTYPE_URN, PUD_NODEIDTYPE_192, PUD_NODEIDTYPE_193
- (so basically for numbers that will not change) */
-static unsigned char cachedNodeIdBuffer[PUD_CACHED_NODEID_BUFFER_SIZE];
-
-/** The number of bytes stored in cachedNodeIdBuffer */
-static unsigned int cachedNodeIdBufferLength = 0;
-
-/**
- Setup a nodeId buffer in the cachedNodeIdBuffer.
-
- @param val
- The value to setup in the cache
- @param bytes
- The number of bytes used by the number in the wire format
-
- @return
- - true when the number is valid
- - false otherwise
- */
-bool setupNodeIdBinaryBufferForOlsrCache(void * val, size_t bytes) {
-       if (bytes >= PUD_CACHED_NODEID_BUFFER_SIZE) {
-               return false;
-       }
-
-       memcpy(cachedNodeIdBuffer, val, bytes);
-       cachedNodeIdBufferLength = bytes;
-       return true;
-}
-
 /* ************************************************************************
  * Validity Time
  * ************************************************************************ */
@@ -306,7 +267,7 @@ void getPositionUpdateNodeId(int ipVersion, union olsr_message * olsrMessage,
  @param nodeIdType
  The nodeIdType
  @param nodeId
- The (configured) nodeId
+ The (configured) nodeId in binary/wireformat representation
  @param nodeIdLength
  The number of bytes in the nodeId
 
@@ -317,16 +278,11 @@ void getPositionUpdateNodeId(int ipVersion, union olsr_message * olsrMessage,
 size_t setPositionUpdateNodeInfo(int ipVersion,
                PudOlsrPositionUpdate * olsrGpsMessage, unsigned int olsrMessageSize,
                NodeIdType nodeIdType, unsigned char * nodeId, size_t nodeIdLength) {
-       unsigned char * buffer;
        unsigned int length = 0;
 
        setPositionUpdateNodeIdType(olsrGpsMessage, nodeIdType);
        switch (nodeIdType) {
        case PUD_NODEIDTYPE_MAC: /* hardware address */
-               length = nodeIdLength;
-               setPositionUpdateNodeId(olsrGpsMessage, nodeId, nodeIdLength, false);
-               break;
-
        case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
        case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
        case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
@@ -334,9 +290,8 @@ size_t setPositionUpdateNodeInfo(int ipVersion,
        case PUD_NODEIDTYPE_192:
        case PUD_NODEIDTYPE_193:
        case PUD_NODEIDTYPE_194:
-               buffer = &cachedNodeIdBuffer[0];
-               length = cachedNodeIdBufferLength;
-               setPositionUpdateNodeId(olsrGpsMessage, buffer, length, false);
+               length = nodeIdLength;
+               setPositionUpdateNodeId(olsrGpsMessage, nodeId, nodeIdLength, false);
                break;
 
        case PUD_NODEIDTYPE_DNS: /* DNS name */