Revision f3ab0d6d src/TopologyManager/topo_proto.c

View differences:

src/TopologyManager/topo_proto.c
15 15

  
16 16
#define MAX_MSG_SIZE 1500
17 17

  
18
static struct peer_cache *myEntry;
18
struct topo_context{
19
 struct peer_cache *myEntry;
20
};
19 21

  
20
static int topo_payload_fill(uint8_t *payload, int size, struct peer_cache *c, struct nodeID *snot, int max_peers, int include_me)
22
static int topo_payload_fill(struct topo_context *context, uint8_t *payload, int size, struct peer_cache *c, struct nodeID *snot, int max_peers, int include_me)
21 23
{
22 24
  int i;
23 25
  uint8_t *p = payload;
......
25 27
  if (!max_peers) max_peers = MAX_MSG_SIZE; // just to be sure to dump the whole cache...
26 28
  p += cache_header_dump(p, c, include_me);
27 29
  if (include_me) {
28
    p += entry_dump(p, myEntry, 0, size - (p - payload));
30
    p += entry_dump(p, context->myEntry, 0, size - (p - payload));
29 31
    max_peers--;
30 32
  }
31 33
  for (i = 0; nodeid(c, i) && max_peers; i++) {
......
44 46
  return p - payload;
45 47
}
46 48

  
47
int topo_reply(const struct peer_cache *c, struct peer_cache *local_cache, int protocol, int type, int max_peers, int include_me)
49
int topo_reply(struct topo_context *context, const struct peer_cache *c, struct peer_cache *local_cache, int protocol, int type, int max_peers, int include_me)
48 50
{
49 51
  uint8_t pkt[MAX_MSG_SIZE];
50 52
  struct topo_header *h = (struct topo_header *)pkt;
......
61 63
  dst = nodeid(c, 0);
62 64
  h->protocol = protocol;
63 65
  h->type = type;
64
  len = topo_payload_fill(pkt + sizeof(struct topo_header), MAX_MSG_SIZE - sizeof(struct topo_header), local_cache, dst, max_peers, include_me);
66
  len = topo_payload_fill(context, pkt + sizeof(struct topo_header), MAX_MSG_SIZE - sizeof(struct topo_header), local_cache, dst, max_peers, include_me);
65 67

  
66
  res = len > 0 ? send_to_peer(nodeid(myEntry, 0), dst, pkt, sizeof(struct topo_header) + len) : len;
68
  res = len > 0 ? send_to_peer(nodeid(context->myEntry, 0), dst, pkt, sizeof(struct topo_header) + len) : len;
67 69

  
68 70
  return res;
69 71
}
70 72

  
71
int topo_query_peer(struct peer_cache *local_cache, struct nodeID *dst, int protocol, int type, int max_peers)
73
int topo_query_peer(struct topo_context *context, struct peer_cache *local_cache, struct nodeID *dst, int protocol, int type, int max_peers)
72 74
{
73 75
  uint8_t pkt[MAX_MSG_SIZE];
74 76
  struct topo_header *h = (struct topo_header *)pkt;
......
76 78

  
77 79
  h->protocol = protocol;
78 80
  h->type = type;
79
  len = topo_payload_fill(pkt + sizeof(struct topo_header), MAX_MSG_SIZE - sizeof(struct topo_header), local_cache, dst, max_peers, 1);
80
  return len > 0  ? send_to_peer(nodeid(myEntry, 0), dst, pkt, sizeof(struct topo_header) + len) : len;
81
  len = topo_payload_fill(context, pkt + sizeof(struct topo_header), MAX_MSG_SIZE - sizeof(struct topo_header), local_cache, dst, max_peers, 1);
82
  return len > 0  ? send_to_peer(nodeid(context->myEntry, 0), dst, pkt, sizeof(struct topo_header) + len) : len;
81 83
}
82 84

  
83
int topo_proto_metadata_update(void *meta, int meta_size)
85
int topo_proto_metadata_update(struct topo_context *context, void *meta, int meta_size)
84 86
{
85
  if (cache_metadata_update(myEntry, nodeid(myEntry, 0), meta, meta_size) > 0) {
87
  if (cache_metadata_update(context->myEntry, nodeid(context->myEntry, 0), meta, meta_size) > 0) {
86 88
    return 1;
87 89
  }
88 90

  
89 91
  return -1;
90 92
}
91 93

  
92
int topo_proto_init(struct nodeID *s, void *meta, int meta_size)
94
struct topo_context* topo_proto_init(struct nodeID *s, void *meta, int meta_size)
93 95
{
94
  if (!myEntry) {
95
    myEntry = cache_init(1, meta_size, 0);
96
    cache_add(myEntry, s, meta, meta_size);
97
  }
96
  struct topo_context* con;
97

  
98
  con = malloc(sizeof(struct topo_context));
99
  if (!con) return NULL;
100

  
101
  con->myEntry = cache_init(1, meta_size, 0);
102
  cache_add(con->myEntry, s, meta, meta_size);
98 103

  
99
  return 0;
104
  return con;
100 105
}

Also available in: Unified diff