Beispiel #1
0
/* Add item to the router table */
void
router_add(uint32_t ip, uint16_t port, int fd)
{
    uint64_t key = get_key(ip, port);

    hash_add(table, key, (void *)(long)fd);
    delay_table_send(key, fd);
}
Beispiel #2
0
/* add item to the router table */
void
router_add(int old, uint32_t clt_ip, uint16_t clt_port, uint32_t target_ip, 
        uint16_t target_port, int fd)
{
    int           i, max, existed, index, remainder;
    uint32_t      key;
    route_slot_t *slot;

    table->total_sessions++;

    key = get_route_key(old, clt_ip, clt_port, target_ip, target_port);

    index = (key & ROUTE_KEY_HIGH_MASK) >> ROUTE_KEY_SHIFT;
    remainder = key & ROUTE_KEY_LOW_MASK;

    table->cache[index].key = remainder; 
    table->cache[index].fd  = (uint16_t) fd; 

    slot = table->slots + index;

    existed = 0;
    max = ROUTE_ARRAY_SIZE;
    if (slot->num < ROUTE_ARRAY_SIZE) {
        max = slot->num;
    }

    for (i = 0; i < max; i++) {
        if (slot->items[i].key == remainder) {
            slot->items[i].fd = fd;
            slot->items[i].timestamp = tc_current_time_sec;
            existed = 1;
            break;
        }

#if 0
        if (slot->items[i].timestamp == 0) {
            tc_log_info(LOG_WARN, 0, "in add visit %d null timestamp,all:%d",
                    i + 1, max);
        }
#endif

    }

    if (!existed) {
        router_add_adjust(slot, remainder, fd);
    } else {
        router_update_adjust(slot, i);
    }

    delay_table_send(key, fd);

}
Beispiel #3
0
/* add item to the router table */
void
router_add(uint32_t ip, uint16_t port, int fd)
{
    uint64_t key = get_key(ip, port);

#if (INTERCEPT_THREAD)
    pthread_mutex_lock(&mutex);
#endif

    hash_add(table, key, (void *) (long) fd);
    delay_table_send(key, fd);

#if (INTERCEPT_THREAD)
    pthread_mutex_unlock(&mutex);
#endif
}