Adding a node returns a pointer to the new node.
This should help to edit aspects of it, such as whether or not it is a directory and such.
This commit is contained in:
@ -19,6 +19,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief Simple address structure providing IP/DNS and port information.
|
||||
*/
|
||||
struct address {
|
||||
char *address; ///< IP/DNS string.
|
||||
unsigned short port; ///< Port of address.
|
||||
};
|
||||
|
||||
struct node {
|
||||
// The address of the node
|
||||
struct address address;
|
||||
// Whether or not it is a directory node/server
|
||||
int directory;
|
||||
// Useful variables for passing on connections of new nodes
|
||||
unsigned int connections;
|
||||
unsigned int max_connections;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize the node list.
|
||||
* @details This function allocates memory and prepares the nodes list, you
|
||||
@ -56,21 +74,30 @@ unsigned int NeoComm_get_node_max();
|
||||
unsigned int NeoComm_get_node_count();
|
||||
|
||||
/**
|
||||
* @brief Add a new node to the list with an address (normally IP) and port.
|
||||
* @brief Add a new node where only address is given (all other variables
|
||||
* are set to 0).
|
||||
*
|
||||
* @param addr Address of the new node (normally an IP, but also DNS).
|
||||
* @param port Port number for new node.
|
||||
* @param addr Address of the new node.
|
||||
*
|
||||
* @return If the node list is full it will return 0, else 1.
|
||||
* @return If the list is full then it will return NULL, else it will return
|
||||
* a pointer to the new (or old, if already existing) node.
|
||||
*/
|
||||
int NeoComm_add_node(char *addr, unsigned short port);
|
||||
struct node *NeoComm_add_node(struct address addr);
|
||||
|
||||
/**
|
||||
* @brief Remove a node from the list.
|
||||
*
|
||||
* @param addr The address of the node.
|
||||
* @param port The public port of the node.
|
||||
*
|
||||
* @return If the node was not found it returns 0, else it returns 1.
|
||||
*/
|
||||
int NeoComm_remove_node(char *addr, unsigned short port);
|
||||
int NeoComm_remove_node(struct address addr);
|
||||
|
||||
/**
|
||||
* @brief Get a pointer to the node with a given address.
|
||||
*
|
||||
* @param addr The address of the node.
|
||||
*
|
||||
* @return A modifiable pointer to the node or NULL if not found.
|
||||
*/
|
||||
struct node *NeoComm_get_node(struct address addr);
|
||||
|
Reference in New Issue
Block a user