예제 #1
0
v_networkHashValue
v_networkHashValueCalculate(
    const char * key1,
    const char * key2)
{
    v_networkHashValue result = {0xa0, 0x22, 0x8d, 0x07};
    const char *currentPtr;

    assert(key1);

#define NW_ROT_CHAR(val, rot) ((c_octet) (((val) << (rot)) + ((val) >> (8-(rot)))))
    currentPtr = key1;
    while (*currentPtr != '\0') {
        /* gcc2.96 gave internal compile errrors (with optimisation enabled)
         * when compiling the NW_ROT_CHAR macro twice in same command :
         * these assignments are deliberatly split over 2 lines as workaround.
         */
        result.h1 = (c_octet) (NW_ROT_CHAR(result.h1, 1) + NW_ROT_CHAR(*currentPtr, 4));
        result.h2 = (c_octet) (NW_ROT_CHAR(result.h2, 2) + NW_ROT_CHAR(*currentPtr, 7));
        result.h3 = (c_octet) (NW_ROT_CHAR(result.h3, 3) + NW_ROT_CHAR(*currentPtr, 1));
        result.h4 = (c_octet) (NW_ROT_CHAR(result.h4, 4) + NW_ROT_CHAR(*currentPtr, 5));
        currentPtr++;
    }

    currentPtr = key2;
    while (currentPtr && *currentPtr != '\0') {
        result.h1 = (c_octet) (NW_ROT_CHAR(result.h1, 4) + NW_ROT_CHAR(*currentPtr, 7));
        result.h2 = (c_octet) (NW_ROT_CHAR(result.h2, 3) + NW_ROT_CHAR(*currentPtr, 1));
        result.h3 = (c_octet) (NW_ROT_CHAR(result.h3, 2) + NW_ROT_CHAR(*currentPtr, 5));
        result.h4 = (c_octet) (NW_ROT_CHAR(result.h4, 1) + NW_ROT_CHAR(*currentPtr, 4));
        currentPtr++;
    }
#undef NW_ROT_CHAR
    return result;
}
예제 #2
0
static v_networkHashValue
v_networkReaderEntryCalculateHashValue(
    v_networkReaderEntry entry)
{
    v_networkHashValue result = {0xa0, 0x22, 0x8d, 0x07};

    const char *partitionName;
    const char *topicName;
    const char *currentPtr;

    partitionName = v_partitionName(v_groupPartition(entry->group));
    topicName = v_topicName(v_groupTopic(entry->group));
    currentPtr = partitionName;

    while (*currentPtr != '\0') {
        /* gcc2.96 gave internal compile errrors (with optimisation enabled)
         * when compiling the NW_ROT_CHAR macro twice in same command :
         * these assignments are deliberatly split over 2 lines as workaround.
         */

        result.h1 = NW_ROT_CHAR(result.h1, 1);
        result.h1 += NW_ROT_CHAR(*currentPtr, 4);

        result.h2 = NW_ROT_CHAR(result.h2, 2);
        result.h2 += NW_ROT_CHAR(*currentPtr, 7);

        result.h3 = NW_ROT_CHAR(result.h3, 3);
        result.h3 += NW_ROT_CHAR(*currentPtr, 1);

        result.h4 = NW_ROT_CHAR(result.h4, 4);
        result.h4 += NW_ROT_CHAR(*currentPtr, 5);

        currentPtr = &(currentPtr[1]);
    }

    currentPtr = topicName;
    while (*currentPtr != '\0') {
        result.h1 = NW_ROT_CHAR(result.h1, 4);
        result.h1 += NW_ROT_CHAR(*currentPtr, 7);

        result.h2 = NW_ROT_CHAR(result.h2, 3);
        result.h2 += NW_ROT_CHAR(*currentPtr, 1);

        result.h3 = NW_ROT_CHAR(result.h3, 2);
        result.h3 += NW_ROT_CHAR(*currentPtr, 5);

        result.h4 = NW_ROT_CHAR(result.h4, 1);
        result.h4 += NW_ROT_CHAR(*currentPtr, 4);

        currentPtr = &(currentPtr[1]);
    }
    return result;
}