コード例 #1
0
ファイル: host.c プロジェクト: wtfbbqhax/Pcapstats
int
track_packet_host(Packet *p)
{
    struct ipaddr addr;
    addr = packet_srcaddr(p);

    HostData *host = host_get((HostKey *)&addr);
    if (host == NULL) {
        if ((host = calloc(1, sizeof *host)) == NULL) {
            warn("could not allocate host data");
            return -1;
        }
        if (host_insert((HostKey *)&addr, host) < 0)
            return -1;
        memset(host, 0, sizeof *host);
        host->address = packet_srcaddr(p);
        host->version = packet_version(p);
    }

    if (host != NULL) {
        host->tx_packets++;
        host->tx_octets += packet_paysize(p);
    }

    addr = packet_dstaddr(p);

    host = host_get((HostKey *)&addr);
    if (host == NULL) {
        if ((host = calloc(1, sizeof *host)) == NULL) {
            warn("could not allocate host data");
            return -1;
        }
        if (host_insert((HostKey *)&addr, host) < 0)
            return -1;
        memset(host, 0, sizeof *host);
        host->address = packet_dstaddr(p);
        host->version = packet_version(p);
    }

    if (host != NULL) {
        host->rx_packets++;
        host->rx_octets += packet_paysize(p);
    }

    tmq_timeout(timeout_queue);
    return 0;
}
コード例 #2
0
ファイル: gidit-daemon.c プロジェクト: zhaoz/gidit
static void gidit_init(char * bootstrap, int port){
	//Initialize Chimera nonsense
	//For testing purposes, the src and destination
	//will litsen on the same port
	ChimeraState * state = chimera_init(port);
	ChimeraHost * host = host_get(state, bootstrap, port);

	/*    Place upcalls here
	chimera_forward (state, test_fwd);
        chimera_deliver (state, test_del);
        chimera_update (state, test_update);
        chimera_setkey (state, keyinput);
        chimera_register (state, TEST_CHAT, 1);
	*/
	chimera_join(state,host);
}
コード例 #3
0
ファイル: route.c プロジェクト: JustinTulloss/yaps
/** find_closest_key:
 ** finds the closest node in the array of #hosts# to #key# and put that in min.
 */
ChimeraHost *find_closest_key (void *state, ChimeraHost ** hosts, Key key,
			       int size)
{

    int i, j;
    Key dif;
    Key mindif;
    ChimeraHost *min, *tmp;
    ChimeraState *chs = (ChimeraState *) state;

    if (size == 0)
	{
	    min = NULL;
	    return;
	}

    else
	{
	    min = hosts[0];
	    key_distance (chs->log, &mindif, &hosts[0]->key, &key);
	}

    for (i = 0; i < size; i++)
	{

	    if (hosts[i] != NULL)
		{
		    key_distance (chs->log, &dif, &hosts[i]->key, &key);

		    if (key_comp (&dif, &mindif) < 0)
			{
			    min = hosts[i];
			    key_assign (&mindif, dif);
			}
		}
	}
    tmp = host_get (chs, min->name, min->port);
    return (min);
}
コード例 #4
0
ファイル: route.c プロジェクト: JustinTulloss/yaps
void route_update (ChimeraState * state, ChimeraHost * host, int joined)
{
    int i, j, k, found, pick;
    ChimeraHost *tmp, *deleted = NULL, *added = NULL;
    RouteGlobal *routeglob = (RouteGlobal *) state->route;


    pthread_mutex_lock (&routeglob->lock);

    if (key_equal (routeglob->me->key, host->key))
	{
	    pthread_mutex_unlock (&routeglob->lock);
	    return;
	}

    i = key_index (state->log, routeglob->me->key, host->key);
    j = hexalpha_to_int (get_key_string (&host->key)[i]);


    /*join */
    if (joined)
	{
	    found = 0;
	    for (k = 0; k < MAX_ENTRY; k++)
		{
		    if (routeglob->table[i][j][k] == NULL)
			{
			    routeglob->table[i][j][k] =
				host_get (state, host->name, host->port);
			    leafset_update (state, host, joined, &deleted,
					    &added);
			    found = 1;
			    break;
			}
		    else if (routeglob->table[i][j][k] != NULL
			     && key_equal (routeglob->table[i][j][k]->key,
					   host->key))
			{
			    pthread_mutex_unlock (&routeglob->lock);
			    return;

			}
		}

	    /* the entry array is full we have to get rid of one */
	    /* replace the new node with the node with the highest latncy in the entry array */
	    if (!found)
		{
		    pick = 0;
		    for (k = 1; k < MAX_ENTRY; k++)
			{
			    if (routeglob->table[i][j][pick]->success_avg >
				routeglob->table[i][j][k]->success_avg)
				pick = k;
			}
		    host_release (state, routeglob->table[i][j][pick]);
		    routeglob->table[i][j][pick] =
			host_get (state, host->name, host->port);
		    leafset_update (state, host, joined, &deleted, &added);
		}
	}

    /*delete */
    else
	{
	    for (k = 0; k < MAX_ENTRY; k++)
		if (routeglob->table[i][j][k] != NULL
		    && key_equal (routeglob->table[i][j][k]->key, host->key))
		    {
			host_release (state, routeglob->table[i][j][k]);
			routeglob->table[i][j][k] = NULL;
			break;
		    }

	    leafset_update (state, host, joined, &deleted, &added);

	}

    if (deleted != NULL)
	{
	    leafset_range_update (routeglob, &(routeglob->Rrange),
				  &(routeglob->Lrange));
	    chimera_update_upcall (state, &(deleted->key), deleted, 0);
	}
    if (added != NULL)
	{
	    leafset_range_update (routeglob, &(routeglob->Rrange),
				  &(routeglob->Lrange));
	    chimera_update_upcall (state, &(added->key), added, 1);
	}
    pthread_mutex_unlock (&routeglob->lock);

    fflush (stderr);
}