Revision 5033613a

View differences:

include/cloud_helper.h
1
#ifndef CLOUD_HELPER_H
2
#define CLOUD_HELPER_H
3

  
4
#define CLOUD_HELPER_MAX_INSTANCES 10
5

  
6
#include <stdint.h>
7
#include <sys/time.h>
8

  
9
#include "net_helper.h"
10

  
11
/**
12
 * @file cloud_helper.h
13
 *
14
 * @brief Cloud communication facility interface.
15
 *
16
 * A clean interface throught which all the cloud communication procedure needed by SOM funcions
17
 * are handled.
18
 */
19

  
20
/**
21
 * Implementation dependant internal representation of the cloud clontext
22
 */
23
struct cloud_helper_contex;
24

  
25
/**
26
 * @brief Initialize all needed internal parameters.
27
 * Initialize the parameters for the cloud facilities and create a context representing the cloud.
28
 * Only one instance of net_helper is allowed for a specific nodeID.
29
 * @param[in] local NodeID associated with this instance of cloud_helper.
30
 * @param[in] config Cloud specific configuration options.
31
 */
32
struct cloud_helper_context* cloud_helper_init(struct nodeID *local, const char *config);
33

  
34
/**
35
 * @brief Identifies the cloud_helper instance associated to the specified nodeID
36
 * Returns the instance of cloud_helper that was initialized with the specified nodeID.
37
 */
38
struct cloud_helper_context* get_cloud_helper_for(struct nodeID *local);
39

  
40
/**
41
 * @brief Get the value for the specified key from the cloud.
42
 * This function send a request to the cloud for the value associated to the specified key.
43
 * Use the wait4cloud to listen for the answer and revc_from_cloud to read the response.
44
 * @param[in] context The contex representing the desired cloud_helper instance.
45
 * @param[in] key Key to retrieve.
46
 * @return 0 if the request was successfully sent, 1 0therwise
47
 */
48
int get_from_cloud(struct cloud_helper_context *context, char *key);
49

  
50
/**
51
 * @brief Put on the cloud the value for a specified key.
52
 * This function transparently handles the sending routines.
53
 * @param[in] context The contex representing the desired cloud_helper instance.
54
 * @param[in] key Key to retrieve.
55
 * @param[in] buffer_ptr A pointer to the buffer in which to store the retrieved data.
56
 * @param[in] buffer_size The size of the data buffer 
57
 * @return 0 on success, 1 on failure
58
 */
59
int put_on_cloud(struct cloud_helper_context *context, char *key, uint8_t *buffer_ptr, int buffer_size);
60

  
61
/**
62
 * @brief Returns the nodeID identifing the cloud
63
 * This function transparently handles the identification of the cloud node.
64
 * @param[in] context The contex representing the desired cloud_helper instance.
65
 * @return nodeID identifying the cloud.
66
 */
67
struct nodeID* get_cloud_node(struct cloud_helper_context *context);
68

  
69
/**
70
 * @brief Check for cloud responses.
71
 * Check if the some cloud GET operation has concluded. It sets a timeout to return at most after a given time.
72
 * @param[in] context The contex representing the desired cloud_helper instance.
73
 * @param[in] tout A pointer to a timer to be used to set the waiting timeout.
74
 * @return 1 if the GET operation was succesful, -1 if the GET operation failed (unkwnown key), 0 otherwise.
75
 */
76
int wait4cloud(struct cloud_helper_context *context, struct timeval *tout);
77

  
78

  
79
/**
80
 * @brief Receive data from the cloud.
81
 * This function transparently handles the receving routines.
82
 * @param[out] buffer_ptr A pointer to the buffer in which to store the retrieved data.
83
 * @param[out] buffer_size The size of the data buffer
84
 * @return The number of received bytes or -1 if some error occurred.
85
 */
86
int recv_from_cloud(struct cloud_helper_context *context, uint8_t *buffer_ptr, int buffer_size);
87

  
88
#endif
src/TopologyManager/Makefile
5 5
endif
6 6
CFGDIR ?= ..
7 7

  
8
OBJS = peersampler.o topman.o ncast.o ncast_proto.o dummy.o cyclon.o cyclon_proto.o topo_proto.o topocache.o blist_cache.o blist_proto.o tman.o dumbTopman.o
8
OBJS = peersampler.o topman.o ncast.o ncast_proto.o dummy.o cyclon.o cyclon_proto.o topo_proto.o topocache.o blist_cache.o blist_proto.o tman.o dumbTopman.o cloud_helper.o
9 9

  
10 10
all: libtopman.a
11 11

  
src/TopologyManager/cloud_helper.c
1
#include <stdlib.h>
2
#include <string.h>
3

  
4
#include "cloud_helper.h"
5
#include "cloud_helper_iface.h"
6
#include "config.h"
7

  
8
extern struct cloud_helper_iface delegate;
9

  
10
struct cloud_helper_context {
11
  struct cloud_helper_iface *ch;
12
  struct cloud_helper_impl_context *ch_context;
13
};
14

  
15
static int ctx_counter = 0;
16
static struct nodeID* node_ids[CLOUD_HELPER_MAX_INSTANCES];
17
static struct cloud_helper_context* cloud_ctxs[CLOUD_HELPER_MAX_INSTANCES];
18

  
19
static int add_context(struct nodeID *local, struct cloud_helper_context *ctx)
20
{
21
  int i;
22
  if (ctx_counter >= CLOUD_HELPER_MAX_INSTANCES) return 1;
23
  
24
  for (i=0; i<ctx_counter; i++)
25
    if (nodeid_equal(node_ids[i], local)) return 0;
26

  
27
  node_ids[ctx_counter] = local;
28
  cloud_ctxs[ctx_counter] = ctx;
29
  ctx_counter++;
30
  
31
  return 1;
32
}
33

  
34
struct cloud_helper_context* cloud_helper_init(struct nodeID *local, const char *config)
35
{
36
  struct cloud_helper_context *ctx;
37
  struct tag *cfg_tags;
38
  const char *provider;
39

  
40
  cfg_tags = config_parse(config);
41
  provider = config_value_str(cfg_tags, "provider");
42

  
43
  if (!provider) return NULL;
44

  
45
  ctx = malloc(sizeof(struct cloud_helper_context));
46
  if (!ctx) return NULL;
47
  if (strcmp(provider, "delegate") == 0){
48
    ctx->ch = &delegate;
49
  }
50
   
51
 ctx->ch_context = ctx->ch->cloud_helper_init(local, config);
52
 if(!ctx->ch_context){
53
   free(ctx);
54
   return NULL;
55
 }
56

  
57
 if (!add_context(local, ctx)){
58
   //TODO: a better deallocation process is needed
59
   free(ctx->ch_context);
60
   free(ctx);
61
   return NULL;
62
 }
63

  
64
 return ctx;
65
}
66

  
67
struct cloud_helper_context* get_cloud_helper_for(struct nodeID *local){
68
  int i;
69
  for (i=0; i<ctx_counter; i++)
70
    if (node_ids[i] == local) return cloud_ctxs[i];
71
  
72
  return NULL;
73
}
74

  
75
int get_from_cloud(struct cloud_helper_context *context, char *key)
76
{
77
  return context->ch->get_from_cloud(context->ch_context, key);
78
}
79

  
80
int put_on_cloud(struct cloud_helper_context *context, char *key, uint8_t *buffer_ptr, int buffer_size)
81
{
82
  return context->ch->put_on_cloud(context->ch_context, key, buffer_ptr, buffer_size);
83
}
84

  
85
struct nodeID* get_cloud_node(struct cloud_helper_context *context)
86
{
87
  return context->ch->get_cloud_node(context->ch_context);
88
}
89

  
90
int wait4cloud(struct cloud_helper_context *context, struct timeval *tout)
91
{
92
  return context->ch->wait4cloud(context->ch_context, tout);
93
}
94

  
95
int recv_from_cloud(struct cloud_helper_context *context, uint8_t *buffer_ptr, int buffer_size)
96
{
97
  return context->ch->recv_from_cloud(context->ch_context, buffer_ptr, buffer_size);
98
}
99

  
src/TopologyManager/cloud_helper_iface.h
1
#ifndef CLOUD_HELPER_IFACE
2
#define CLOUD_HELPER_IFACE
3

  
4
#include "net_helper.h"
5

  
6
struct cloud_helper_impl_context;
7

  
8
struct cloud_helper_iface {
9
  struct cloud_helper_impl_context* (*cloud_helper_init)(struct nodeID *local, const char *config);
10
  int (*get_from_cloud)(struct cloud_helper_impl_context *context, char *key);
11
  int (*put_on_cloud)(struct cloud_helper_impl_context *context, char *key, uint8_t *buffer_ptr, int buffer_size);
12
  struct nodeID* (*get_cloud_node)(struct cloud_helper_impl_context *context);
13
  int (*wait4cloud)(struct cloud_helper_impl_context *context, struct timeval *tout);
14
  int (*recv_from_cloud)(struct cloud_helper_impl_context *context, uint8_t *buffer_ptr, int buffer_size);
15
};
16

  
17
#endif

Also available in: Unified diff