Revision 1583fd78 src/PeerSampler/ncast.c

View differences:

src/PeerSampler/ncast.c
29 29
struct peersampler_context{
30 30
  uint64_t currtime;
31 31
  int cache_size;
32
  int cache_size_threshold;
32 33
  struct peer_cache *local_cache;
33 34
  bool bootstrap;
34 35
  struct nodeID *bootstrap_node;
......
75 76
  return 0;
76 77
}
77 78

  
79
static void cache_size_threshold_init(struct peersampler_context* context)
80
{
81
  context->cache_size_threshold = (context->cache_size - 1 / 2);
82
}
83

  
78 84
/*
79 85
 * Exported Functions!
80 86
 */
......
116 122
    return NULL;
117 123
  }
118 124

  
125
  cache_size_threshold_init(context);
126

  
119 127
  context->tc = ncast_proto_init(myID, metadata, metadata_size);
120 128
  if (!context->tc){
121 129
    free(context->local_cache);
......
176 184
  }
177 185

  
178 186
  if (time_to_send(context)) {
187
    if (context->bootstrap_node &&
188
        (cache_entries(context->local_cache) <= context->cache_size_threshold) &&
189
        (cache_pos(context->local_cache, context->bootstrap_node) < 0)) {
190
      cache_add(context->local_cache, context->bootstrap_node, NULL, 0);
191
    }
179 192
    cache_update(context->local_cache);
180 193
    return ncast_query(context->tc, context->local_cache);
181 194
  }
......
206 219
static int ncast_grow_neighbourhood(struct peersampler_context *context, int n)
207 220
{
208 221
  context->cache_size += n;
222
  cache_size_threshold_init(context);
209 223

  
210 224
  return context->cache_size;
211 225
}
......
216 230
    return -1;
217 231
  }
218 232
  context->cache_size -= n;
233
  cache_size_threshold_init(context);
219 234

  
220 235
  return context->cache_size;
221 236
}

Also available in: Unified diff