Statistics
| Branch: | Revision:

grapes / src / TopologyManager / cyclon_proto.c @ f3ab0d6d

History | View | Annotate | Download (1.32 KB)

1
/*
2
 *  Copyright (c) 2010 Luca Abeni
3
 *
4
 *  This is free software; see lgpl-2.1.txt
5
 */
6

    
7
#include <stdint.h>
8
#include <stdlib.h>
9
#include <stdio.h>
10

    
11
#include "net_helper.h"
12
#include "topocache.h"
13
#include "proto.h"
14
#include "topo_proto.h"
15
#include "cyclon_proto.h"
16
#include "grapes_msg_types.h"
17

    
18
struct cyclon_proto_context{
19
  struct topo_context *context;
20
};
21

    
22
struct cyclon_proto_context* cyclon_proto_init(struct nodeID *s, void *meta, int meta_size){
23
  struct cyclon_proto_context *con;
24
  con = malloc(sizeof(struct cyclon_proto_context));
25

    
26
  if (!con) return NULL;
27

    
28
  con->context = topo_proto_init(s, meta, meta_size);
29
  if (!con->context){
30
    free(con);
31
    return NULL;
32
  }
33

    
34
  return con;
35
}    
36

    
37

    
38
int cyclon_reply(struct cyclon_proto_context *context, const struct peer_cache *c, struct peer_cache *local_cache)
39
{
40
  return topo_reply(context->context, c, local_cache, MSG_TYPE_TOPOLOGY, CYCLON_REPLY, 0, 0);
41
}
42

    
43
int cyclon_query(struct cyclon_proto_context *context, struct peer_cache *sent_cache, struct nodeID *dst)
44
{
45
  return topo_query_peer(context->context, sent_cache, dst, MSG_TYPE_TOPOLOGY, CYCLON_QUERY, 0);
46
}
47

    
48
int cyclon_proto_change_metadata(struct cyclon_proto_context *context, void *metadata, int metadata_size)
49
{
50
  if (topo_proto_metadata_update(context->context, metadata, metadata_size) <= 0) {
51
    return -1;
52
  }
53

    
54
  return 1;
55
}