peerset.h File Reference

Structure containing a set of peers. More...

Go to the source code of this file.

Typedefs

typedef struct peerset PeerSet

Functions

struct peerset * peerset_init (const char *config)
 Allocate a peer set.
int peerset_add_peer (struct peerset *h, struct nodeID *id)
 Add a peer to the set.
void peerset_add_peers (struct peerset *h, struct nodeID **ids, int n)
 Add peers to the set.
int peerset_remove_peer (struct peerset *h, const struct nodeID *id)
 Remove a peer from the set.
struct peer * peerset_get_peer (const struct peerset *h, const struct nodeID *id)
 Get a peer if it is in the set.
int peerset_size (const struct peerset *h)
 Get the set size.
struct peer * peerset_get_peers (const struct peerset *h)
 Get a peer from a set.
int peerset_check (const struct peerset *h, const struct nodeID *id)
 Check if a peer is in a set.
void peerset_clear (struct peerset *h, int size)
 Clear a set.

Detailed Description

Structure containing a set of peers.

The Peer Set is an abstract data structure that can contain a set of peer structures. It handles peers by their nodeIDs. Peer structures are created and accessed based on their nodeID (i.e. unique address).


Typedef Documentation

typedef struct peerset PeerSet

Opaque data type representing a Peer Set


Function Documentation

int peerset_add_peer ( struct peerset *  h,
struct nodeID *  id 
)

Add a peer to the set.

Insert a peer to the set, creating the peer structure. If the peer is already in the set, nothing happens.

Parameters:
h a pointer to the set where the peer has to be added
id the ID of the peer to be inserted in the set
Returns:
> 0 if the peer is correctly inserted in the set, 0 if a peer with the same nodeID is already in the set, < 0 on error
void peerset_add_peers ( struct peerset *  h,
struct nodeID **  ids,
int  n 
)

Add peers to the set.

Comodity function to add several peers at the same time to the set. See peerset_add_peer

Parameters:
h a pointer to the set where the peer has to be added
ids the IDs of the peers to be inserted in the set
n length of the its array
int peerset_check ( const struct peerset *  h,
const struct nodeID *  id 
)

Check if a peer is in a set.

Parameters:
h a pointer to the set
id the nodeID we are searching for
Returns:
the position of the peer if it is present in the set, < 0 on error or if the peer is not in the set
void peerset_clear ( struct peerset *  h,
int  size 
)

Clear a set.

Remove all the peers from a set.

Parameters:
h a pointer to the set
size the expected number of peers that will be stored in the set; 0 if such a number is not known.
struct peer* peerset_get_peer ( const struct peerset *  h,
const struct nodeID *  id 
) [read]

Get a peer if it is in the set.

Parameters:
h a pointer to the set
id the nodeID we are searching for
Returns:
a pointer to the peer if it is present in the set, NULL if the peer is not in the set
struct peer* peerset_get_peers ( const struct peerset *  h  )  [read]

Get a peer from a set.

Return the peers of the set. The peer's priority is assumed to depend on i.

Parameters:
h a pointer to the set
Returns:
the list of peer structures
struct peerset* peerset_init ( const char *  config  )  [read]

Allocate a peer set.

Create an empty peer set, and return a pointer to it.

Parameters:
config a string containing tags which describe the peerset. For example, the "size" tag indicates the expected number of peers that will be stored in the set; 0 or not present if such a number is not known.
Returns:
the pointer to the new set on success, NULL on error
int peerset_remove_peer ( struct peerset *  h,
const struct nodeID *  id 
)

Remove a peer from the set.

Remove a peer from the set, distroying all associated data. If peer exists, pointers of peerset_get_peers move backwards.

Parameters:
h a pointer to the set where the peer has to be added
id the ID of the peer to be removed from the set
Returns:
> 0 if the peer is correctly removed from the set, < 0 on error
int peerset_size ( const struct peerset *  h  ) 

Get the set size.

Return the number of peers present in a set.

Parameters:
h a pointer to the set
Returns:
the number of peers in the set, or < 0 on error
Generated on Mon Jul 12 16:16:52 2010 for GRAPES by  doxygen 1.6.3