Tman interface. More...
Go to the source code of this file.
Typedefs | |
typedef int(* | tmanRankingFunction )(const void *target, const void *p1, const void *p2) |
Compare neighbors features. | |
Functions | |
int | tmanInit (struct nodeID *myID, void *metadata, int metadata_size, tmanRankingFunction rfun, int gossip_peers) |
Initialise Tman. | |
int | tmanAddNeighbour (struct nodeID *neighbour, void *metadata, int metadata_size) |
Insert a peer in the neighbourhood. | |
int | tmanParseData (const uint8_t *buff, int len, struct nodeID **peers, int size, const void *metadata, int metadata_size) |
Pass a received packet to Tman. | |
int | tmanChangeMetadata (struct nodeID *peer, void *metadata, int metadata_size) |
Change the metadata in tman neighborhood. | |
const void * | tmanGetMetadata (int *metadata_size) |
Get the metadata of the neighbors. | |
int | tmanGetNeighbourhoodSize (void) |
Get the current neighborhood size. | |
int | tmanGivePeers (int n, struct nodeID **peers, void *metadata) |
Get the highest ranked tman peers. | |
int | tmanGrowNeighbourhood (int n) |
Increase the neighbourhood size. | |
int | tmanShrinkNeighbourhood (int n) |
Decrease the neighbourhood size. |
Tman interface.
This is the Tman interface. Tman builds a given topology according to a user provided ranking algorithm, by means of epidemic-style message exchanges with neighbor peers.
typedef int(* tmanRankingFunction)(const void *target, const void *p1, const void *p2) |
Compare neighbors features.
The functions implementing this prototype are used to compare neighbors features against a given target neighbor, in order to obtain a rank, to be used to build a given topology.
target | pointer to data that describe the target against which the ranking has to be made. | |
p1 | pointer to data that describe the first neighbor. | |
p2 | pointer to data that describe the second neighbor. |
int tmanAddNeighbour | ( | struct nodeID * | neighbour, | |
void * | metadata, | |||
int | metadata_size | |||
) |
Insert a peer in the neighbourhood.
This function can be used to add a specified neighbour to the neighbourhood.
neighbour | the id of the peer to be added to the neighbourhood. | |
metadata | Pointer to the array of metadata belonging to the peers to be added. | |
metadata_size | Number of bytes of each metadata. |
int tmanChangeMetadata | ( | struct nodeID * | peer, | |
void * | metadata, | |||
int | metadata_size | |||
) |
Change the metadata in tman neighborhood.
This function changes the metadata associated with the current node.
metadata | Pointer to the metadata belonging to the peer. | |
metadata_size | Number of bytes of the metadata. |
const void* tmanGetMetadata | ( | int * | metadata_size | ) |
Get the metadata of the neighbors.
metadata_size | Address of the integer that will be set to the size of each metadata. |
int tmanGetNeighbourhoodSize | ( | void | ) |
Get the current neighborhood size.
This function returns the current number of peers in the local tman neighborhood.
int tmanGivePeers | ( | int | n, | |
struct nodeID ** | peers, | |||
void * | metadata | |||
) |
Get the highest ranked tman peers.
This function allows the user to retrieve the highest ranked n peers from tman cache, along with their metadata. The number of peers actually returned may be different from what is asked, depending on the current size of the cache. Notice that if the user asks for a number of peers that exceeds the current cache size, a join with the known peers set provided via tmanParseData will be triggered at the next time tmanParseData is called. This will change (and make unstable, at least for few subsequent iterations) the current known topology. Thus, it is advisable to do so only if necessary (i.e. when the user really needs more peers to communicate with).
n | The number of peer tman is asked for. | |
peers | Array of nodeID pointers to be filled. | |
metadata | Pointer to the array of metadata belonging to the peers to be given. |
int tmanGrowNeighbourhood | ( | int | n | ) |
Increase the neighbourhood size.
This function can be used to increase the number of neighbours (that is, the degree of the overlay graph) by a specified amount. The actual size change will be done the next time tmanParseData is called. As currently implemented, it doubles the current size at most. If the argument is negative or a resize has already been requested, but not performed yet, no change will occur and an error code is returned.
n | number of peers by which the neighbourhood size must be incremented. |
int tmanInit | ( | struct nodeID * | myID, | |
void * | metadata, | |||
int | metadata_size, | |||
tmanRankingFunction | rfun, | |||
int | gossip_peers | |||
) |
Initialise Tman.
This function initializes tman protocol with all the mandatory parameters.
myID | the ID of this peer. | |
metadata | Pointer to data associated with the local peer. | |
metadata_size | Size (number of bytes) of the metadata associated with the local peer. | |
rfun | Ranking function to be used to order the peers in tman cache. | |
gossip_peers | Number of peers, among those in the cache, to be gossiped in a messaged exchange. |
int tmanParseData | ( | const uint8_t * | buff, | |
int | len, | |||
struct nodeID ** | peers, | |||
int | size, | |||
const void * | metadata, | |||
int | metadata_size | |||
) |
Pass a received packet to Tman.
This function passes to Tman a packet that has been received from the network. The Topology Manager will parse such packet and run the protocol, adding or removing peers to the neighbourhood, and sending overlay management messages to other peers.
buff | a memory buffer containing the received message. | |
len | the size of such a memory buffer. | |
peers | Array of nodeID pointers to be added in tman cache. | |
size | Number of elements in peers. | |
metadata | Pointer to the array of metadata belonging to the peers to be added. | |
metadata_size | Number of bytes of each metadata. |
int tmanShrinkNeighbourhood | ( | int | n | ) |
Decrease the neighbourhood size.
This function can be used to reduce the number of neighbours (that is, the degree of the overlay graph) by a specified amount. The actual size change will be done the next time tmanParseData is called. If the argument is negative, or greater equal than the current cache size, or a resize has already been requested, but not performed yet, no change will occur and an error code is returned.
n | number of peers by which the neighbourhood size must be decreased. |