Revision 18d83f26 som/TopologyManager/topocache.c

View differences:

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
  }

Also available in: Unified diff