Revision e910cf6c src/Cache/cloudcast_proto.c

View differences:

src/Cache/cloudcast_proto.c
7 7
#include <stdint.h>
8 8
#include <stdlib.h>
9 9
#include <stdio.h>
10
#include <string.h>
10 11

  
11 12
#include "net_helper.h"
12 13
#include "topocache.h"
......
19 20
#define MAX_MSG_SIZE 1500
20 21

  
21 22
#define CLOUD_VIEW_KEY "view"
23
#define CLOUDCAST_MESSAGE_HEADER 10 /* PROTOCOL MSG_TYPE LAST_CLOUD_CONTACT */
24

  
25
uint8_t cloud_header[10] = { MSG_TYPE_TOPOLOGY, CLOUDCAST_CLOUD, 0llu};
22 26

  
23
struct topo_header cloud_header = {MSG_TYPE_TOPOLOGY, CLOUDCAST_CLOUD};
24 27
struct cloudcast_proto_context {
25 28
  struct peer_cache* myEntry;
26 29
  uint8_t def_cloudcache[128];
......
88 91
  return is_cloud_node(con->cloud_context, node);
89 92
}
90 93

  
91
int cloudcast_reply_peer(struct cloudcast_proto_context *context, const struct peer_cache *c, struct peer_cache *local_cache)
94
int cloudcast_reply_peer(struct cloudcast_proto_context *context, const struct peer_cache *c, struct peer_cache *local_cache, uint64_t last_cloud_contact_sec)
92 95
{
93
  return topo_reply(context->topo_context, c, local_cache, MSG_TYPE_TOPOLOGY, CLOUDCAST_REPLY, 0, 0);
96
  uint8_t *header = (uint8_t *) &last_cloud_contact_sec;
97
  int header_len = sizeof(uint64_t);
98
  return topo_reply_header(context->topo_context, c, local_cache, MSG_TYPE_TOPOLOGY, CLOUDCAST_REPLY, header, header_len, 0, 0);
94 99
}
95 100

  
96
int cloudcast_query_peer(struct cloudcast_proto_context *context, struct peer_cache *sent_cache, struct nodeID *dst)
101
int cloudcast_query_peer(struct cloudcast_proto_context *context, struct peer_cache *sent_cache, struct nodeID *dst, uint64_t last_cloud_contact_sec)
97 102
{
98
  return topo_query_peer(context->topo_context, sent_cache, dst, MSG_TYPE_TOPOLOGY, CLOUDCAST_QUERY, 0);
103
  uint8_t *header = (uint8_t *) &last_cloud_contact_sec;
104
  int header_len = sizeof(uint64_t);
105
  return topo_query_peer_header(context->topo_context, sent_cache, dst, MSG_TYPE_TOPOLOGY, CLOUDCAST_QUERY, header, header_len, 0);
99 106
}
100 107

  
101 108

  
......
104 111
  int i;
105 112
  uint8_t *p = payload;
106 113

  
107
  if (!max_peers) max_peers = MAX_MSG_SIZE; // just to be sure to dump the whole cache...
114
  if (!max_peers) max_peers = MAX_MSG_SIZE; // FIXME: we should use topo_proto for this
108 115
  p += cache_header_dump(p, c, include_me);
109 116
  if (include_me) {
110 117
    p += entry_dump(p, context->myEntry, 0, size - (p - payload));
......
129 136

  
130 137
int cloudcast_reply_cloud(struct cloudcast_proto_context *context, struct peer_cache *cloud_cache)
131 138
{
132
  uint8_t headerless_pkt[MAX_MSG_SIZE - sizeof(cloud_header)];
139
  uint8_t headerless_pkt[MAX_MSG_SIZE - CLOUDCAST_MESSAGE_HEADER];
133 140
  int len, res;
134 141

  
135
  len = cloudcast_payload_fill(context, headerless_pkt, MAX_MSG_SIZE - sizeof(cloud_header), cloud_cache, 0, 1);
142
  len = cloudcast_payload_fill(context, headerless_pkt, MAX_MSG_SIZE - CLOUDCAST_MESSAGE_HEADER, cloud_cache, 0, 1);
136 143

  
137 144
  if (len > 0)
138 145
    res = put_on_cloud(context->cloud_context, CLOUD_VIEW_KEY, headerless_pkt, len, 0);
......
144 151
int cloudcast_query_cloud(struct cloudcast_proto_context *context)
145 152
{
146 153
  return get_from_cloud_default(context->cloud_context, CLOUD_VIEW_KEY,
147
                                (uint8_t *)&cloud_header, sizeof(cloud_header),
154
                                cloud_header, CLOUDCAST_MESSAGE_HEADER,
148 155
                                0, context->def_cloudcache,
149 156
                                context->def_cloudcache_len, 0);
150 157
}

Also available in: Unified diff