Exemplo n.º 1
0
List* List_Initialize(List* list, void* value)
{
    Node* node = Node_Create(value);
    list->first = node;
    list->last = node;
    list->count = 1;
    return list;
}
Exemplo n.º 2
0
Node* Node_Insert(Node* beginNode, void* value)
{
    Node* endingNode = beginNode->next;
    Node* insertedNode = Node_Create(value);
    
    Node_Link(beginNode, insertedNode);
    Node_Link(insertedNode, endingNode);
    
    return beginNode;
}
Exemplo n.º 3
0
Arquivo: node.c Projeto: polysome/amok
Node *
Node_Copy(Node *source)
{
    Node *copy = Node_Create(&source->id);
    check_mem(copy);

    copy->addr = source->addr;
    copy->port = source->port;

    return copy;
error:
    return NULL;
}
Exemplo n.º 4
0
int SetCompactNodeInfo(Message *message, BNode *string)
{
    assert(message != NULL && "NULL Message pointer");
    assert((message->type == RFindNode || message->type == RGetPeers)
           && "Wrong message type");
    assert(string != NULL && "NULL BNode string pointer");
    assert(string->type == BString && "Not a BString");

    if (string->count % COMPACTNODE_BYTES != 0)
    {
        message->errors |= MERROR_INVALID_DATA;
        return 0;
    }

    RFindNodeData *data = &message->data.rfindnode;
    char *nodes = string->value.string;
    
    data->count = string->count / COMPACTNODE_BYTES;
    data->nodes = calloc(data->count, sizeof(Node *));
    check_mem(data->nodes);

    unsigned int i = 0;
    for (i = 0; i < data->count; i++, nodes += COMPACTNODE_BYTES)
    {
        data->nodes[i] = Node_Create((Hash *)nodes);
        check_mem(data->nodes[i]);
        data->nodes[i]->addr.s_addr = ntohl(*(uint32_t *)(nodes
                                                         + HASH_BYTES));
	data->nodes[i]->port = ntohs(*(uint16_t *)(nodes
                                                  + HASH_BYTES
                                                  + sizeof(uint32_t)));
    }

    return 0;
error:
    if (data->nodes != NULL)
    {
        Node_DestroyBlock(data->nodes, string->count);
        free(nodes);
        data->nodes = NULL;
    }

    data->count = 0;

    return -1;
}
Exemplo n.º 5
0
List* List_Append(List* list, void* value)
{
    if (list->count == 0)
    {
        list->count = 1;
        Node* node = Node_Create(value);
        list->first = node;
        list->last = node;
        return list;
    }
    else
    {
        Node* appended_node = Node_Append(list->last, value);
        list->count++;
        list->last = appended_node;
        return list;
    }
}
Exemplo n.º 6
0
Node* Node_Append(Node* originalNode, void* value)
{
    Node* newNode = Node_Create(value);
    Node_Link(originalNode, newNode);
    return newNode;
}