Revision 18d83f26

View differences:

som/TopologyManager/ncast.c
21 21
#include "msg_types.h"
22 22

  
23 23
#define DEFAULT_CACHE_SIZE 10
24
#define DEFAULT_MAX_TIMESTAMP 5
24 25

  
25 26
static uint64_t currtime;
26 27
static int cache_size;
......
56 57
int topInit(struct nodeID *myID, void *metadata, int metadata_size, const char *config)
57 58
{
58 59
  struct tag *cfg_tags;
59
  int res;
60
  int res, max_timestamp;
60 61

  
61 62
  cfg_tags = config_parse(config);
62 63
  res = config_value_int(cfg_tags, "cache_size", &cache_size);
63 64
  if (!res) {
64 65
    cache_size = DEFAULT_CACHE_SIZE;
65 66
  }
67
  res = config_value_int(cfg_tags, "max_timestamp", &max_timestamp);
68
  if (!res) {
69
    max_timestamp = DEFAULT_MAX_TIMESTAMP;
70
  }
66 71
  free(cfg_tags);
67 72
  
68
  local_cache = cache_init(cache_size, metadata_size);
73
  local_cache = cache_init(cache_size, metadata_size, max_timestamp);
69 74
  if (local_cache == NULL) {
70 75
    return -1;
71 76
  }
som/TopologyManager/tman.c
49 49
	const uint8_t *mdata;
50 50

  
51 51
        mdata = get_metadata(c,&msize);
52
	res = cache_init(cache_size,msize);
52
	res = cache_init(cache_size, msize, 0);
53 53
        if (res == NULL) {
54 54
          return res;
55 55
        }
......
78 78
  topo_proto_init(myID, metadata, metadata_size);
79 79
  mymeta = metadata;
80 80
  
81
  local_cache = cache_init(cache_size, metadata_size);
81
  local_cache = cache_init(cache_size, metadata_size, 0);
82 82
  if (local_cache == NULL) {
83 83
    return -1;
84 84
  }
......
221 221
		struct peer_cache *ncache;
222 222
		int j;
223 223

  
224
		if (size) ncache = cache_init(size,metadata_size);
224
		if (size) ncache = cache_init(size, metadata_size, 0);
225 225
		else {return 1;}
226 226
		for (j=0;j<size;j++)
227 227
			cache_add_ranked(ncache, peers[j],(const uint8_t *)metadata + j * metadata_size, metadata_size, rankFunct, mymeta);
som/TopologyManager/topo_proto.c
117 117
int topo_proto_init(struct nodeID *s, void *meta, int meta_size)
118 118
{
119 119
  if (!myEntry) {
120
	myEntry = cache_init(1, meta_size);
120
	myEntry = cache_init(1, meta_size, 0);
121 121
	cache_add(myEntry, s, meta, meta_size);
122 122
  }
123 123
  return 0;
som/TopologyManager/topocache.c
15 15
#include "topocache.h"
16 16
#include "int_coding.h"
17 17

  
18
#define MAX_TIMESTAMP 5
19 18
struct cache_entry {
20 19
  struct nodeID *id;
21 20
  uint32_t timestamp;
......
26 25
  int cache_size;
27 26
  int current_size;
28 27
  int metadata_size;
29
  uint8_t *metadata; 
28
  uint8_t *metadata;
29
  int max_timestamp;
30 30
};
31 31

  
32 32
struct nodeID *nodeid(const struct peer_cache *c, int i)
......
127 127
  int i;
128 128
  
129 129
  for (i = 0; i < c->current_size; i++) {
130
    if (c->entries[i].timestamp == MAX_TIMESTAMP) {
130
    if (c->max_timestamp && (c->entries[i].timestamp == c->max_timestamp)) {
131 131
      int j = i;
132 132

  
133 133
      while(j < c->current_size && c->entries[j].id) {
......
153 153
  }
154 154
}
155 155

  
156
struct peer_cache *cache_init(int n, int metadata_size)
156
struct peer_cache *cache_init(int n, int metadata_size, int max_timestamp)
157 157
{
158 158
  struct peer_cache *res;
159 159

  
......
161 161
  if (res == NULL) {
162 162
    return NULL;
163 163
  }
164
  res->max_timestamp = max_timestamp;
164 165
  res->cache_size = n;
165 166
  res->current_size = 0;
166 167
  res->entries = malloc(sizeof(struct cache_entry) * n);
......
241 242
  cache_size = int_rcpy(buff);
242 243
  metadata_size = int_rcpy(buff + 4);
243 244
  p = buff + 8;
244
  res = cache_init(cache_size, metadata_size);
245
  res = cache_init(cache_size, metadata_size, 0);
245 246
  meta = res->metadata;
246 247
  while (p - buff < size) {
247 248
    int len;
......
294 295
  struct peer_cache *new_cache;
295 296
  uint8_t *meta;
296 297

  
297
  new_cache = cache_init(newsize, c1->metadata_size);
298
  new_cache = cache_init(newsize, c1->metadata_size, c1->max_timestamp);
298 299
  if (new_cache == NULL) {
299 300
    return NULL;
300 301
  }
som/TopologyManager/topocache.h
2 2
struct cache_entry;
3 3
typedef int (*ranking_function)(const void *target, const void *p1, const void *p2);	// FIXME!
4 4

  
5
struct peer_cache *cache_init(int n, int metadata_size);
5
struct peer_cache *cache_init(int n, int metadata_size, int max_timestamp);
6 6
void cache_free(struct peer_cache *c);
7 7
void cache_update(struct peer_cache *c);
8 8
void cache_update_tout(struct peer_cache *c);

Also available in: Unified diff