Statistics
| Branch: | Revision:

grapes / src / TopologyManager / ncast_proto.c @ 5033613a

History | View | Annotate | Download (1.54 KB)

1 477826d1 Luca Abeni
/*
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 c3d9eba1 Luca Abeni
#include "ncast_proto.h"
16 477826d1 Luca Abeni
#include "grapes_msg_types.h"
17
18 d83a94fa Andrea Zito
struct ncast_proto_context {
19 f3ab0d6d Andrea Zito
  struct topo_context *context;
20
};
21
22 d83a94fa Andrea Zito
struct ncast_proto_context* ncast_proto_init(struct nodeID *s, void *meta, int meta_size)
23
{
24 de42b756 Andrea Zito
25 f3ab0d6d Andrea Zito
  struct ncast_proto_context *con;
26
  con = malloc(sizeof(struct ncast_proto_context));
27
28
  if (!con) return NULL;
29
30
  con->context = topo_proto_init(s, meta, meta_size);
31
  if (!con->context){
32
    free(con);
33
    return NULL;
34
  }
35
36 d83a94fa Andrea Zito
  return con;
37 f3ab0d6d Andrea Zito
}
38
39
int ncast_reply(struct ncast_proto_context *context, const struct peer_cache *c, struct peer_cache *local_cache)
40 477826d1 Luca Abeni
{
41 f3ab0d6d Andrea Zito
  return topo_reply(context->context, c, local_cache, MSG_TYPE_TOPOLOGY, NCAST_REPLY, 0, 1);
42 477826d1 Luca Abeni
}
43
44 f3ab0d6d Andrea Zito
int ncast_query_peer(struct ncast_proto_context *context, struct peer_cache *local_cache, struct nodeID *dst)
45 477826d1 Luca Abeni
{
46 f3ab0d6d Andrea Zito
  return topo_query_peer(context->context, local_cache, dst, MSG_TYPE_TOPOLOGY, NCAST_QUERY, 0);
47 477826d1 Luca Abeni
}
48
49 f3ab0d6d Andrea Zito
int ncast_query(struct ncast_proto_context *context, struct peer_cache *local_cache)
50 477826d1 Luca Abeni
{
51
  struct nodeID *dst;
52
53
  dst = rand_peer(local_cache, NULL, 0);
54
  if (dst == NULL) {
55
    return 0;
56
  }
57 f3ab0d6d Andrea Zito
  return topo_query_peer(context->context, local_cache, dst, MSG_TYPE_TOPOLOGY, NCAST_QUERY, 0);
58
}
59
60
int ncast_proto_metadata_update(struct ncast_proto_context *context, void *meta, int meta_size){
61
  return topo_proto_metadata_update(context->context, meta, meta_size);
62 477826d1 Luca Abeni
}