Revision 28399cdc

View differences:

som/TopologyManager/topocache.c
287 287
  return 8;
288 288
}
289 289

  
290
int entry_dump(uint8_t *b, struct peer_cache *c, int i)
290
int entry_dump(uint8_t *b, struct peer_cache *c, int i, size_t max_write_size)
291 291
{
292 292
  int res;
293
  int size = 0;
293 294
 
294 295
  if (i && (i >= c->cache_size - 1)) {
295 296
    return 0;
296 297
  }
297 298
  int_cpy(b, c->entries[i].timestamp);
298
  res = 4;
299
  res += nodeid_dump(b + res, c->entries[i].id);
299
  size = +4;
300
  res = nodeid_dump(b + size, c->entries[i].id, max_write_size - size);
301
  if (res < 0 ) {
302
    fprintf (stderr,"cavolo1\n");
303
    return -1;
304
  }
305
  size += res;
300 306
  if (c->metadata_size) {
301
    memcpy(b + res, c->metadata + c->metadata_size * i, c->metadata_size);
302
    res += c->metadata_size;
307
    if (c->metadata_size > max_write_size - size) {
308
      fprintf (stderr,"cavolo2\n");
309
      return -1;
310
    }
311
    memcpy(b + size, c->metadata + c->metadata_size * i, c->metadata_size);
312
    size += c->metadata_size;
303 313
  }
304 314

  
305
  return res;
315
  return size;
306 316
}
307 317

  
308 318
struct peer_cache *merge_caches_ranked(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source, ranking_function rank, void *mymetadata)
som/TopologyManager/topocache.h
18 18

  
19 19
struct peer_cache *entries_undump(const uint8_t *buff, int size);
20 20
int cache_header_dump(uint8_t *b, const struct peer_cache *c);
21
int entry_dump(uint8_t *b, struct peer_cache *e, int i);
21
int entry_dump(uint8_t *b, struct peer_cache *e, int i, size_t max_write_size);
22 22

  
23 23
struct peer_cache *merge_caches_ranked(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source, ranking_function rank, void *mymeta);
24 24
struct peer_cache *merge_caches(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source);

Also available in: Unified diff