Revision 6fd9945c

View differences:

include/tman.h
3 3

  
4 4
/** @file tman.h
5 5
 *
6
 * @brief Tman interface.
6
 * @brief Topology Manager interface.
7 7
 *
8
 * This is the Tman interface. Tman builds a given topology according to a user provided ranking
9
 * algorithm, by means of epidemic-style message exchanges with neighbor peers.
8
 * This is the Topology Manager interface.
10 9
 *
11 10
 */
12 11

  
13 12
/**
14 13
  @brief Compare neighbors features.
15 14

  
16
  The functions implementing this prototype are used to compare neighbors features against a given
15
  The functions implementing this prototype may be used to compare neighbors features against a given
17 16
  target neighbor, in order to obtain a rank, to be used to build a given topology.
18 17

  
19 18
  @param target pointer to data that describe the target against which the ranking has to be made.
......
24 23
typedef int (*tmanRankingFunction)(const void *target, const void *p1, const void *p2);
25 24

  
26 25
/**
27
  @brief Initialise Tman.
26
  @brief Initialise the Topology Manager.
28 27

  
29
  This function initializes tman protocol with all the mandatory parameters.
28
  This function initializes the Topology Manager protocol with all the mandatory parameters.
30 29

  
31 30
  @param myID the ID of this peer.
32 31
  @param metadata Pointer to data associated with the local peer.
33 32
  @param metadata_size Size (number of bytes) of the metadata associated with the local peer.
34
  @param rfun Ranking function to be used to order the peers in tman cache.
35
  @param gossip_peers Number of peers, among those in the cache, to be gossiped in a messaged exchange.
33
  @param rfun Ranking function that may be used to order the peers in tman cache.
34
  @param config Pointer to a configuration file that contains all relevant initialization data.
36 35
  @return 0 in case of success; -1 in case of error.
37 36
*/
38
int tmanInit(struct nodeID *myID, void *metadata, int metadata_size, tmanRankingFunction rfun, int gossip_peers); 
37
int tmanInit(struct nodeID *myID, void *metadata, int metadata_size, tmanRankingFunction rfun, const char *config); 
39 38

  
40 39

  
41 40
/**
......
51 50
int tmanAddNeighbour(struct nodeID *neighbour, void *metadata, int metadata_size);
52 51

  
53 52
/**
54
  @brief Pass a received packet to Tman.
53
  @brief Pass a received packet to Topology Manager.
55 54

  
56
  This function passes to Tman a packet that has
55
  This function passes to Topology Manager a packet that has
57 56
  been received from the network. The Topology Manager will parse
58 57
  such packet and run the protocol, adding or removing peers to the
59 58
  neighbourhood, and sending overlay management messages to other peers.
60 59
  @param buff a memory buffer containing the received message.
61 60
  @param len the size of such a memory buffer.
62
  @param peers Array of nodeID pointers to be added in tman cache.
61
  @param peers Array of nodeID pointers to be added in Topology Manager cache.
63 62
  @param size Number of elements in peers.
64 63
  @param metadata Pointer to the array of metadata belonging to the peers to be added.
65 64
  @param metadata_size Number of bytes of each metadata.
......
69 68

  
70 69

  
71 70
/**
72
  @brief Change the metadata in tman neighborhood.
71
  @brief Change the metadata in Topology Manager neighborhood.
73 72

  
74 73
  This function changes the metadata associated with the current node.
75 74

  
......
91 90
/**
92 91
  @brief Get the current neighborhood size.
93 92

  
94
  This function returns the current number of peers in the local tman neighborhood.
93
  This function returns the current number of peers in the local Topology Manager neighborhood.
95 94

  
96 95
  @return The current size of the neighborhood.
97 96
*/
......
99 98

  
100 99

  
101 100
/**
102
 * @brief Get the highest ranked tman peers.
101
 * @brief Get the best peers.
103 102
 *
104
 * This function allows the user to retrieve the highest ranked n peers from tman cache, along with
103
 * This function allows the user to retrieve the best n peers from Topology Manager cache, along with
105 104
 * their metadata. The number of peers actually returned may be different from what is asked, depending
106 105
 * on the current size of the cache.
107
 * Notice that if the user asks for a number of peers that exceeds the current cache size, a join with
108
 * the known peers set provided via tmanParseData will be triggered at the next
109
 * time tmanParseData is called. This will change (and make unstable,
110
 * at least for few subsequent iterations) the current known topology. Thus, it is advisable to do so only if
111
 * necessary (i.e. when the user really needs more peers to communicate with).
112 106
 *
113
 * @param n The number of peer tman is asked for.
107
 * @param n The number of peer the Topology Manager is asked for.
114 108
 * @param peers Array of nodeID pointers to be filled.
115 109
 * @param metadata Pointer to the array of metadata belonging to the peers to be given.
116 110
 * @return The number of elements in peers.
......
147 141
*/
148 142
int tmanShrinkNeighbourhood(int n);
149 143

  
144

  
145
/**
146
 * @brief Remove a neighbour.
147

  
148
  Delete a neighbour from the Topology Manager neighborhood.
149

  
150
  @param neighbour Pointer to the nodeID of the neighbor to be removed.
151
  @return 1 if removal was successful, -1 if it was not.
152
 */
153
int tmanRemoveNeighbour(struct nodeID *neighbour);
154

  
150 155
#endif /* TMAN_H */
156

  
src/TopologyManager/Makefile
1 1
BASE = ../..
2 2

  
3
OBJS = peersampler.o ncast.o dummy.o topo_proto.o topocache.o blist_cache.o blist_proto.o tman.o
3
OBJS = topman.o peersampler.o ncast.o dummy.o topo_proto.o topocache.o blist_cache.o blist_proto.o tman.o
4 4

  
5 5
all: libtopman.a
6 6

  
src/TopologyManager/tman.c
16 16
#include "blist_proto.h"
17 17
#include "proto.h"
18 18
#include "grapes_msg_types.h"
19
#include "tman.h"
19
#include "topman_iface.h"
20 20

  
21 21
#define TMAN_INIT_PEERS 10 // max # of neighbors in local cache (should be >= than the next)
22 22
#define TMAN_MAX_PREFERRED_PEERS 10 // # of peers to choose a receiver among (should be <= than the previous)
......
40 40
static struct nodeID *restart_peer;
41 41
static uint8_t *zero;
42 42

  
43
static tmanRankingFunction userRankFunct;
43
static rankingFunction userRankFunct;
44 44

  
45 45
static int tmanRankFunct (const void *target, const void *p1, const void *p2) {
46 46

  
......
62 62
	return tv.tv_usec + tv.tv_sec * 1000000ull;
63 63
}
64 64

  
65
int tmanInit(struct nodeID *myID, void *metadata, int metadata_size, ranking_function rfun, int gossip_peers)
65
static int tmanInit(struct nodeID *myID, void *metadata, int metadata_size, rankingFunction rfun, const char *config)
66 66
{
67 67
	userRankFunct = rfun;
68 68
	blist_proto_init(myID, metadata, metadata_size);
......
74 74
	if (local_cache == NULL) {
75 75
		return -1;
76 76
	}
77
	if (gossip_peers) {
78
		max_gossiping_peers = gossip_peers;
79
	}
80
	max_preferred_peers = TMAN_MAX_PREFERRED_PEERS;
81 77
	active = -1;
82 78
	currtime = gettime();
83 79

  
84 80
	return 0;
85 81
}
86 82

  
87
int tmanGivePeers (int n, struct nodeID **peers, void *metadata)
83
static int tmanGivePeers (int n, struct nodeID **peers, void *metadata)
88 84
{
89 85
	int metadata_size;
90 86
	const uint8_t *mdata;
......
100 96
	return i;
101 97
}
102 98

  
103
int tmanGetNeighbourhoodSize(void)
99
static int tmanGetNeighbourhoodSize(void)
104 100
{
105 101
	int i;
106 102

  
......
119 115
	return 0;
120 116
}
121 117

  
122
int tmanAddNeighbour(struct nodeID *neighbour, void *metadata, int metadata_size)
118
static int tmanAddNeighbour(struct nodeID *neighbour, void *metadata, int metadata_size)
123 119
{
124 120
	if (!metadata_size) {
125 121
		blist_tman_query_peer(local_cache, neighbour, max_gossiping_peers);
......
134 130

  
135 131

  
136 132
// not self metadata, but neighbors'.
137
const void *tmanGetMetadata(int *metadata_size)
133
static const void *tmanGetMetadata(int *metadata_size)
138 134
{
139 135
	return blist_get_metadata(local_cache, metadata_size);
140 136
}
141 137

  
142 138

  
143
int tmanChangeMetadata(void *metadata, int metadata_size)
139
static int tmanChangeMetadata(void *metadata, int metadata_size)
144 140
{
145 141
	struct peer_cache *new = NULL;
146 142

  
......
161 157
}
162 158

  
163 159

  
164
int tmanParseData(const uint8_t *buff, int len, struct nodeID **peers, int size, const void *metadata, int metadata_size)
160
static int tmanParseData(const uint8_t *buff, int len, struct nodeID **peers, int size, const void *metadata, int metadata_size)
165 161
{
166 162
	int msize,s;
167 163
	const uint8_t *mdata;
......
296 292

  
297 293

  
298 294
// limit : at most it doubles the current cache size...
299
int tmanGrowNeighbourhood(int n)
295
static int tmanGrowNeighbourhood(int n)
300 296
{
301 297
	if (n<=0 || do_resize)
302 298
		return -1;
......
307 303
}
308 304

  
309 305

  
310
int tmanShrinkNeighbourhood(int n)
306
static int tmanShrinkNeighbourhood(int n)
311 307
{
312 308
	if (n<=0 || n>=cache_size || do_resize)
313 309
		return -1;
......
316 312
	return cache_size;
317 313
}
318 314

  
315

  
316
static int tmanRemoveNeighbour(struct nodeID *neighbour)
317
{
318
	return 0;
319
}
320

  
321

  
322
struct topman_iface tman = {
323
	.init = tmanInit,
324
	.changeMetadata = tmanChangeMetadata,
325
	.addNeighbour = tmanAddNeighbour,
326
	.parseData = tmanParseData,
327
	.givePeers = tmanGivePeers,
328
	.getMetadata = tmanGetMetadata,
329
	.growNeighbourhood = tmanGrowNeighbourhood,
330
	.shrinkNeighbourhood = tmanShrinkNeighbourhood,
331
	.removeNeighbour = tmanRemoveNeighbour,
332
	.getNeighbourhoodSize = tmanGetNeighbourhoodSize,
333
};
src/TopologyManager/topman.c
1
#include <sys/time.h>
2
#include <stdint.h>
3
#include <stdlib.h>
4

  
5
#include "net_helper.h"
6
#include "tman.h"
7
#include "topman_iface.h"
8

  
9
extern struct topman_iface tman;
10
static struct topman_iface *tm;
11

  
12

  
13
int tmanInit(struct nodeID *myID, void *metadata, int metadata_size, tmanRankingFunction rfun, const char *config)
14
{
15
	tm = &tman;
16
	return tm->init(myID, metadata, metadata_size, rfun, config);
17
}
18

  
19

  
20
int tmanAddNeighbour(struct nodeID *neighbour, void *metadata, int metadata_size)
21
{
22
	return tm->addNeighbour(neighbour, metadata, metadata_size);
23
}
24

  
25

  
26
int tmanParseData(const uint8_t *buff, int len, struct nodeID **peers, int size, const void *metadata, int metadata_size)
27
{
28
	return tm->parseData(buff, len, peers, size, metadata, metadata_size);
29
}
30

  
31

  
32
int tmanChangeMetadata(void *metadata, int metadata_size)
33
{
34
	return tm->changeMetadata(metadata, metadata_size);
35
}
36

  
37

  
38
const void *tmanGetMetadata(int *metadata_size)
39
{
40
	return tm->getMetadata(metadata_size);
41
}
42

  
43

  
44
int tmanGetNeighbourhoodSize(void)
45
{
46
	return tm->getNeighbourhoodSize();
47
}
48

  
49

  
50
int tmanGivePeers (int n, struct nodeID **peers, void *metadata)
51
{
52
	return tm->givePeers (n, peers, metadata);
53
}
54

  
55

  
56
int tmanGrowNeighbourhood(int n)
57
{
58
	return tm->growNeighbourhood(n);
59
}
60

  
61

  
62
int tmanShrinkNeighbourhood(int n)
63
{
64
	return tm->shrinkNeighbourhood(n);
65
}
66

  
67

  
68
int tmanRemoveNeighbour(struct nodeID *neighbour)
69
{
70
	return tm->removeNeighbour(neighbour);
71
}
src/TopologyManager/topman_iface.h
1
typedef int (*rankingFunction)(const void *target, const void *p1, const void *p2);	// FIXME!
2

  
3
struct topman_iface {
4
  int (*init)(struct nodeID *myID, void *metadata, int metadata_size, rankingFunction rfun, const char *config);
5
  int (*changeMetadata)(void *metadata, int metadata_size);
6
  int (*addNeighbour)(struct nodeID *neighbour, void *metadata, int metadata_size);
7
  int (*parseData)(const uint8_t *buff, int len, struct nodeID **peers, int size, const void *metadata, int metadata_size);
8
  int (*givePeers)(int n, struct nodeID **peers, void *metadata);
9
  const void *(*getMetadata)(int *metadata_size);
10
  int (*growNeighbourhood)(int n);
11
  int (*shrinkNeighbourhood)(int n);
12
  int (*removeNeighbour)(struct nodeID *neighbour);
13
  int (*getNeighbourhoodSize)(void);
14
};

Also available in: Unified diff