Exemplo n.º 1
0
unsigned int htoi(const char s[])
{
    unsigned int answer = 0;
    int i = 0;
    int valid = 1;
    int hexit;
    
    if(s[i] == '0')
    {
        ++i;
        if(s[i] == 'x' || s[i] == 'X')
        {
            ++i;
        }
    }
    
    while(valid && s[i] != '\0')
    {
        answer = answer * 16;
        if(s[i] >= '0' && s[i] <= '9')
        {
            answer = answer + (s[i] - '0');
        }
        else
        {
            hexit = hexalpha_to_int(s[i]);
            if(hexit == 0)
            {
                valid = 0;
            }
            else
            {
                answer = answer + hexit;
            }
        }
        
        ++i;
    }
    
    if(!valid)
    {
        answer = 0;
    }
    
    return answer;
}
Exemplo n.º 2
0
static unsigned int htoi(const char s[])
{
	unsigned int answer = 0;
	int i = 0;
	int hexit;

	while(s[i] != '\0') {
		if(s[i] >= '0' && s[i] <= '9') {
			answer = answer * 16;
			answer = answer + (s[i] - '0');
		} else {
			hexit = hexalpha_to_int(s[i]);
			if(hexit == 0) {
				break;
			} else {
				answer = answer * 16;
				answer = answer + hexit;
			}
		}
		++i;
	}
	return answer;
}
Exemplo n.º 3
0
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);
}