Revision cbe3b83c

View differences:

src/Cache/topo_proto.c
13 13
#include "proto.h"
14 14
#include "topo_proto.h"
15 15

  
16
#define MAX_MSG_SIZE 1500
17

  
18 16
struct topo_context{
19 17
 struct peer_cache *myEntry;
18
 uint8_t *pkt;
19
 int pkt_size;
20 20
};
21 21

  
22 22
static int topo_payload_fill(struct topo_context *context, uint8_t *payload, int size, const struct peer_cache *c, const struct nodeID *snot, int max_peers, int include_me)
......
24 24
  int i;
25 25
  uint8_t *p = payload;
26 26

  
27
  if (!max_peers) max_peers = MAX_MSG_SIZE; // just to be sure to dump the whole cache...
27
  if (!max_peers) max_peers = 1000; // just to be sure to dump the whole cache...
28 28
  p += cache_header_dump(p, c, include_me);
29 29
  if (include_me) {
30 30
    p += entry_dump(p, context->myEntry, 0, size - (p - payload));
......
48 48

  
49 49
int topo_reply(struct topo_context *context, const struct peer_cache *c, const struct peer_cache *local_cache, int protocol, int type, int max_peers, int include_me)
50 50
{
51
  uint8_t pkt[MAX_MSG_SIZE];
52
  struct topo_header *h = (struct topo_header *)pkt;
51
  struct topo_header *h = (struct topo_header *)context->pkt;
53 52
  int len, res;
54 53
  struct nodeID *dst;
55 54

  
......
63 62
  dst = nodeid(c, 0);
64 63
  h->protocol = protocol;
65 64
  h->type = type;
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
  len = topo_payload_fill(context, context->pkt + sizeof(struct topo_header), context->pkt_size - sizeof(struct topo_header), local_cache, dst, max_peers, include_me);
67 66

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

  
70 69
  return res;
71 70
}
72 71

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

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

  
85 83
int topo_proto_metadata_update(struct topo_context *context, const void *meta, int meta_size)
......
97 95

  
98 96
  con = malloc(sizeof(struct topo_context));
99 97
  if (!con) return NULL;
98
  con->pkt_size = 60 * 1024;
99
  con->pkt = malloc(con->pkt_size);
100
  if (!con->pkt) {
101
    free(con);
102

  
103
    return NULL;
104
  }
100 105

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

Also available in: Unified diff