Revision b9e7dd7b

View differences:

include/cloud_helper.h
30 30

  
31 31
/**
32 32
 * @brief Initialize all needed internal parameters.
33
 * Initialize the parameters for the cloud facilities and create a context representing the cloud.
33
 * Initialize the parameters for the cloud facilities and create a context
34
 * representing the cloud.
34 35
 * Only one instance of net_helper is allowed for a specific nodeID.
35 36
 * @param[in] local NodeID associated with this instance of cloud_helper.
36 37
 * @param[in] config Cloud specific configuration options.
37 38
 */
38
struct cloud_helper_context* cloud_helper_init(struct nodeID *local, const char *config);
39
struct cloud_helper_context* cloud_helper_init(struct nodeID *local,
40
                                               const char *config);
39 41

  
40 42
/**
41
 * @brief Identifies the cloud_helper instance associated to the specified nodeID
42
 * Returns the instance of cloud_helper that was initialized with the specified nodeID.
43
 * @brief Identifies the cloud_helper instance associated to the specified
44
 * nodeID
45
 * Returns the instance of cloud_helper that was initialized with the
46
 * specified nodeID.
43 47
 */
44
struct cloud_helper_context* get_cloud_helper_for(struct nodeID *local);
48
struct cloud_helper_context* get_cloud_helper_for(const struct nodeID *local);
45 49

  
46 50
/**
47 51
 * @brief Get the value for the specified key from the cloud.
48
 * This function send a request to the cloud for the value associated to the specified key.
49
 * Use the wait4cloud to listen for the answer and revc_from_cloud to read the response.
50
 * @param[in] context The contex representing the desired cloud_helper instance.
52
 * This function send a request to the cloud for the value associated to the
53
 * specified key. Use the wait4cloud to listen for the answer and
54
 * revc_from_cloud to read the response.
55
 * @param[in] context The contex representing the desired cloud_helper
56
 *                    instance.
51 57
 * @param[in] key Key to retrieve.
52
 * @param[in] header_ptr A pointer to the header which will be added to the retrieved data. May be NULL
58
 * @param[in] header_ptr A pointer to the header which will be added to the
59
 *                       retrieved data. May be NULL
53 60
 * @param[in] header_size The length of the header.
61
 * @param[in] free_header A positive value result in buffer_ptr being freed
62
 *                        on request completion
54 63
 * @return 0 if the request was successfully sent, 1 Otherwise
55 64
 */
56
int get_from_cloud(struct cloud_helper_context *context, char *key, uint8_t *header_ptr, int header_size);
65
int get_from_cloud(struct cloud_helper_context *context, const char *key,
66
                   uint8_t *header_ptr, int header_size, int free_header);
57 67

  
58 68
/**
59 69
 * @brief Returns the timestamp associated to the last GET operation.
60 70
 * Returns the timestamp associated to the last GET operation or NULL.
61
 * @param[in] context The contex representing the desired cloud_helper instance.
71
 * @param[in] context The contex representing the desired cloud_helper
72
 *                    instance.
62 73
 * @return timestamp ot NULL
63 74
 */
64 75
time_t timestamp_cloud(struct cloud_helper_context *context);
......
66 77
/**
67 78
 * @brief Put on the cloud the value for a specified key.
68 79
 * This function transparently handles the sending routines.
69
 * @param[in] context The contex representing the desired cloud_helper instance.
80
 * @param[in] context The contex representing the desired cloud_helper
81
 *                    instance.
70 82
 * @param[in] key Key to retrieve.
71
 * @param[in] buffer_ptr A pointer to the buffer in which to store the retrieved data.
83
 * @param[in] buffer_ptr A pointer to the buffer in which to store the
84
 *                       retrieved data.
72 85
 * @param[in] buffer_size The size of the data buffer
86
 * @param[in] free_buffer A positive value result in buffer_ptr being freed
87
 *                        on request completion
73 88
 * @return 0 on success, 1 on failure
74 89
 */
75
int put_on_cloud(struct cloud_helper_context *context, char *key, uint8_t *buffer_ptr, int buffer_size);
90
int put_on_cloud(struct cloud_helper_context *context, const char *key,
91
                 uint8_t *buffer_ptr, int buffer_size, int free_buffer);
76 92

  
77 93
/**
78 94
 * @brief Returns the nodeID identifing the cloud for the specified variant.
79 95
 * This function transparently handles the identification of the cloud
80 96
 * node. Thanks to the variant parameter is possible to recover
81
 * nodeIDs which differ wrt to nodeid_equal, but are equal wrt to is_cloud_node.
82
 * @param[in] context The contex representing the desired cloud_helper instance.
97
 * nodeIDs which differ wrt to nodeid_equal, but are equal wrt to
98
 * is_cloud_node.
99
 * @param[in] context The contex representing the desired cloud_helper
100
 *                    instance.
83 101
 * @param[in] variant The variant number for this nodeID.
84 102
 * @return nodeID identifying the cloud.
85 103
 */
86
struct nodeID* get_cloud_node(struct cloud_helper_context *context, uint8_t variant);
104
struct nodeID* get_cloud_node(struct cloud_helper_context *context,
105
                              uint8_t variant);
87 106

  
88 107
/**
89 108
 * @brief Check if the specified node references the cloud
90 109
 * This function transparently handles the comparation of cloud nodes.
91
 * @param[in] context The contex representing the desired cloud_helper instance.
110
 * @param[in] context The contex representing the desired cloud_helper
111
 *                    instance.
92 112
 * @param[in] node The supposed cloud node
93 113
 * @return 1 if cloud node, 0 otherwise
94 114
 */
95
int is_cloud_node(struct cloud_helper_context *context, struct nodeID* node);
115
int is_cloud_node(struct cloud_helper_context *context,
116
                  struct nodeID* node);
96 117

  
97 118
/**
98 119
 * @brief Check for cloud responses.
99
 * Check if the some cloud GET operation has concluded. It sets a timeout to return at most after a given time.
100
 * @param[in] context The contex representing the desired cloud_helper instance.
120
 * Check if the some cloud GET operation has concluded. It sets a timeout to
121
 * return at most after a given time.
122
 * @param[in] context The contex representing the desired cloud_helper
123
 *                    instance.
101 124
 * @param[in] tout A pointer to a timer to be used to set the waiting timeout.
102
 * @return 1 if the GET operation was succesful, -1 if the GET operation failed (unkwnown key), 0 otherwise.
125
 * @return 1 if the GET operation was succesful, -1 if the GET operation
126
 *         failed (unkwnown key), 0 otherwise.
103 127
 */
104 128
int wait4cloud(struct cloud_helper_context *context, struct timeval *tout);
105 129

  
src/CloudSupport/cloud_helper.c
19 19
};
20 20

  
21 21
static int ctx_counter = 0;
22
static struct nodeID* node_ids[CLOUD_HELPER_MAX_INSTANCES];
22
static const struct nodeID* node_ids[CLOUD_HELPER_MAX_INSTANCES];
23 23
static struct cloud_helper_context* cloud_ctxs[CLOUD_HELPER_MAX_INSTANCES];
24 24

  
25
static int add_context(struct nodeID *local, struct cloud_helper_context *ctx)
25
static int add_context(const struct nodeID *local,
26
                       struct cloud_helper_context *ctx)
26 27
{
27 28
  int i;
28 29
  if (ctx_counter >= CLOUD_HELPER_MAX_INSTANCES) return 1;
......
37 38
  return 1;
38 39
}
39 40

  
40
struct cloud_helper_context* cloud_helper_init(struct nodeID *local, const char *config)
41
struct cloud_helper_context* cloud_helper_init(struct nodeID *local,
42
                                               const char *config)
41 43
{
42 44
  struct cloud_helper_context *ctx;
43 45
  struct tag *cfg_tags;
......
70 72
 return ctx;
71 73
}
72 74

  
73
struct cloud_helper_context* get_cloud_helper_for(struct nodeID *local){
75
struct cloud_helper_context* get_cloud_helper_for(const struct nodeID *local){
74 76
  int i;
75 77
  for (i=0; i<ctx_counter; i++)
76 78
    if (node_ids[i] == local) return cloud_ctxs[i];
......
78 80
  return NULL;
79 81
}
80 82

  
81
int get_from_cloud(struct cloud_helper_context *context, char *key, uint8_t *header_ptr, int header_size)
83
int get_from_cloud(struct cloud_helper_context *context, const char *key,
84
                   uint8_t *header_ptr, int header_size, int free_header)
82 85
{
83
  return context->ch->get_from_cloud(context->ch_context, key, header_ptr, header_size);
86
  return context->ch->get_from_cloud(context->ch_context, key, header_ptr,
87
                                     header_size, free_header);
84 88
}
85 89

  
86
int put_on_cloud(struct cloud_helper_context *context, char *key, uint8_t *buffer_ptr, int buffer_size)
90
int put_on_cloud(struct cloud_helper_context *context, const char *key,
91
                 uint8_t *buffer_ptr, int buffer_size, int free_buffer)
87 92
{
88
  return context->ch->put_on_cloud(context->ch_context, key, buffer_ptr, buffer_size);
93
  return context->ch->put_on_cloud(context->ch_context, key, buffer_ptr,
94
                                   buffer_size, free_buffer);
89 95
}
90 96

  
91
struct nodeID* get_cloud_node(struct cloud_helper_context *context, uint8_t variant)
97
struct nodeID* get_cloud_node(struct cloud_helper_context *context,
98
                              uint8_t variant)
92 99
{
93 100
  return context->ch->get_cloud_node(context->ch_context, variant);
94 101
}
......
108 115
  return context->ch->wait4cloud(context->ch_context, tout);
109 116
}
110 117

  
111
int recv_from_cloud(struct cloud_helper_context *context, uint8_t *buffer_ptr, int buffer_size)
118
int recv_from_cloud(struct cloud_helper_context *context, uint8_t *buffer_ptr,
119
                    int buffer_size)
112 120
{
113
  return context->ch->recv_from_cloud(context->ch_context, buffer_ptr, buffer_size);
121
  return context->ch->recv_from_cloud(context->ch_context, buffer_ptr,
122
                                      buffer_size);
114 123
}
src/CloudSupport/cloud_helper_delegate.c
14 14

  
15 15
struct delegate_iface {
16 16
  void* (*cloud_helper_init)(struct nodeID *local, const char *config);
17
  int (*get_from_cloud)(void *context, char *key, uint8_t *header_ptr, int header_size);
18
  int (*put_on_cloud)(void *context, char *key, uint8_t *buffer_ptr, int buffer_size);
17

  
18
  int (*get_from_cloud)(void *context, const char *key, uint8_t *header_ptr,
19
                        int header_size, int free_header);
20

  
21
  int (*put_on_cloud)(void *context, const char *key, uint8_t *buffer_ptr,
22
                      int buffer_size, int free_buffer);
23

  
19 24
  struct nodeID* (*get_cloud_node)(void *context, uint8_t variant);
25

  
20 26
  time_t (*timestamp_cloud)(void *context);
27

  
21 28
  int (*is_cloud_node)(void *context, struct nodeID* node);
29

  
22 30
  int (*wait4cloud)(void *context, struct timeval *tout);
31

  
23 32
  int (*recv_from_cloud)(void *context, uint8_t *buffer_ptr, int buffer_size);
24 33
};
25 34

  
......
28 37
  void *delegate_context;
29 38
};
30 39

  
31
static struct cloud_helper_impl_context* delegate_cloud_init(struct nodeID *local, const char *config)
40
static struct cloud_helper_impl_context*
41
delegate_cloud_init(struct nodeID *local, const char *config)
32 42
{
33 43
  struct cloud_helper_impl_context *ctx;
34 44
  struct tag *cfg_tags;
......
60 70
  return ctx;
61 71
}
62 72

  
63
static int delegate_cloud_get_from_cloud(struct cloud_helper_impl_context *context, char *key, uint8_t *header_ptr, int header_size)
73
static int
74
delegate_cloud_get_from_cloud(struct cloud_helper_impl_context *context,
75
                              const char *key, uint8_t *header_ptr,
76
                              int header_size, int free_header)
64 77
{
65
  return context->delegate->get_from_cloud(context->delegate_context, key, header_ptr, header_size);
78
  return context->delegate->get_from_cloud(context->delegate_context, key,
79
                                           header_ptr, header_size,
80
                                           free_header);
66 81
}
67 82

  
68
static int delegate_cloud_put_on_cloud(struct cloud_helper_impl_context *context, char *key, uint8_t *buffer_ptr, int buffer_size)
83
static int
84
delegate_cloud_put_on_cloud(struct cloud_helper_impl_context *context,
85
                            const char *key, uint8_t *buffer_ptr,
86
                            int buffer_size, int free_buffer)
69 87
{
70
  return context->delegate->put_on_cloud(context->delegate_context, key, buffer_ptr, buffer_size);
88
  return context->delegate->put_on_cloud(context->delegate_context, key,
89
                                         buffer_ptr, buffer_size, free_buffer);
71 90
}
72

  
73
static struct nodeID* delegate_cloud_get_cloud_node(struct cloud_helper_impl_context *context, uint8_t variant)
91
static struct nodeID*
92
delegate_cloud_get_cloud_node(struct cloud_helper_impl_context *context,
93
                              uint8_t variant)
74 94
{
75 95
  return context->delegate->get_cloud_node(context->delegate_context, variant);
76 96
}
77 97

  
78
static time_t delegate_timestamp_cloud(struct cloud_helper_impl_context *context)
98
static time_t
99
delegate_timestamp_cloud(struct cloud_helper_impl_context *context)
79 100
{
80 101
  return context->delegate->timestamp_cloud(context->delegate_context);
81 102
}
82 103

  
83
int delegate_is_cloud_node(struct cloud_helper_impl_context *context, struct nodeID* node)
104
int delegate_is_cloud_node(struct cloud_helper_impl_context *context,
105
                           struct nodeID* node)
84 106
{
85 107
  return context->delegate->is_cloud_node(context->delegate_context, node);
86 108
}
87 109

  
88
static int delegate_cloud_wait4cloud(struct cloud_helper_impl_context *context, struct timeval *tout)
110
static int delegate_cloud_wait4cloud(struct cloud_helper_impl_context *context,
111
                                     struct timeval *tout)
89 112
{
90 113
  return context->delegate->wait4cloud(context->delegate_context, tout);
91 114
}
92 115

  
93
static int delegate_cloud_recv_from_cloud(struct cloud_helper_impl_context *context, uint8_t *buffer_ptr, int buffer_size)
116
static int
117
delegate_cloud_recv_from_cloud(struct cloud_helper_impl_context *context,
118
                               uint8_t *buffer_ptr, int buffer_size)
94 119
{
95
  return context->delegate->recv_from_cloud(context->delegate_context, buffer_ptr, buffer_size);
120
  return context->delegate->recv_from_cloud(context->delegate_context,
121
                                            buffer_ptr, buffer_size);
96 122
}
97 123

  
98 124
struct cloud_helper_iface delegate = {
src/CloudSupport/cloud_helper_iface.h
7 7
struct cloud_helper_impl_context;
8 8

  
9 9
struct cloud_helper_iface {
10
  struct cloud_helper_impl_context* (*cloud_helper_init)(struct nodeID *local, const char *config);
11
  int (*get_from_cloud)(struct cloud_helper_impl_context *context, char *key, uint8_t *header_ptr, int header_size);
12
  int (*put_on_cloud)(struct cloud_helper_impl_context *context, char *key, uint8_t *buffer_ptr, int buffer_size);
13
  struct nodeID* (*get_cloud_node)(struct cloud_helper_impl_context *context, uint8_t variant);
10
  struct cloud_helper_impl_context*
11
  (*cloud_helper_init)(struct nodeID *local, const char *config);
12

  
13
  int (*get_from_cloud)(struct cloud_helper_impl_context *context,
14
                        const char *key, uint8_t *header_ptr, int header_size,
15
                        int free_header);
16

  
17
  int (*put_on_cloud)(struct cloud_helper_impl_context *context,
18
                      const char *key, uint8_t *buffer_ptr, int buffer_size,
19
                      int free_buffer);
20

  
21
  struct nodeID* (*get_cloud_node)(struct cloud_helper_impl_context *context,
22
                                   uint8_t variant);
23

  
14 24
  time_t (*timestamp_cloud)(struct cloud_helper_impl_context *context);
15
  int (*is_cloud_node)(struct cloud_helper_impl_context *context, struct nodeID* node);
16
  int (*wait4cloud)(struct cloud_helper_impl_context *context, struct timeval *tout);
17
  int (*recv_from_cloud)(struct cloud_helper_impl_context *context, uint8_t *buffer_ptr, int buffer_size);
25

  
26
  int (*is_cloud_node)(struct cloud_helper_impl_context *context,
27
                       struct nodeID* node);
28

  
29
  int (*wait4cloud)(struct cloud_helper_impl_context *context,
30
                    struct timeval *tout);
31

  
32
  int (*recv_from_cloud)(struct cloud_helper_impl_context *context,
33
                         uint8_t *buffer_ptr, int buffer_size);
18 34
};
19 35

  
20 36
#endif
src/CloudSupport/libs3_delegate_helper.c
36 36
 ***********************************************************************/
37 37
struct delegate_iface {
38 38
  void* (*cloud_helper_init)(struct nodeID *local, const char *config);
39
  int (*get_from_cloud)(void *context, char *key, uint8_t *header_ptr,
40
                        int header_size);
41
  int (*put_on_cloud)(void *context, char *key, uint8_t *buffer_ptr,
42
                      int buffer_size);
39
  int (*get_from_cloud)(void *context, const char *key, uint8_t *header_ptr,
40
                        int header_size, int free_header);
41
  int (*put_on_cloud)(void *context, const char *key, uint8_t *buffer_ptr,
42
                      int buffer_size, int free_buffer);
43 43
  struct nodeID* (*get_cloud_node)(void *context, uint8_t variant);
44 44
  time_t (*timestamp_cloud)(void *context);
45 45
  int (*is_cloud_node)(void *context, struct nodeID* node);
......
60 60
     For PUT this is the pointer to the actual data */
61 61
  uint8_t *data;
62 62
  int data_length;
63
  int free_data;
63 64
} libs3_request_t;
64 65

  
65 66
typedef struct libs3_get_response {
......
169 170
  S3Status status;
170 171
};
171 172

  
173
static void free_request(libs3_request_t *req)
174
{
175
  if (!req) return;
176

  
177
  free(req->key);
178
  if (req->free_data > 0) free(req->data);
179

  
180
  free(req);
181
}
172 182

  
173 183
static void add_request(struct libs3_cloud_context *ctx, libs3_request_t *req)
174 184
{
......
539 549
                "libs3_delegate_helper: failed to perform operation\n");
540 550
      }
541 551

  
542
      /* TODO: to free or not to free? */
543
      if (req->data) free(req->data);
544
      free(req);
552
      free_request(req);
545 553
    }
546 554
  } while(req != NULL);
547 555

  
......
749 757
  return ctx;
750 758
}
751 759

  
752
int get_from_cloud(void *context, char *key, uint8_t *header_ptr,
753
                   int header_size)
760
int get_from_cloud(void *context, const char *key, uint8_t *header_ptr,
761
                   int header_size, int free_header)
754 762
{
755 763
  struct libs3_cloud_context *ctx;
756 764
  libs3_request_t *request;
......
764 772
  request->key = strdup(key);
765 773
  request->data = header_ptr;
766 774
  request->data_length = header_size;
775
  request->free_data = free_header;
767 776

  
768 777
  add_request(ctx, request);
769 778

  
770 779
  return 0;
771 780
}
772 781

  
773
  int put_on_cloud(void *context, char *key, uint8_t *buffer_ptr,
774
                      int buffer_size)
782
  int put_on_cloud(void *context, const char *key, uint8_t *buffer_ptr,
783
                   int buffer_size, int free_buffer)
775 784
  {
776 785
  struct libs3_cloud_context *ctx;
777 786
  libs3_request_t *request;
......
785 794
  request->key = strdup(key);
786 795
  request->data = buffer_ptr;
787 796
  request->data_length = buffer_size;
797
  request->free_data = free_buffer;
788 798

  
789
  if (ctx->blocking_put_request)
790
    return request_handler_process_put_request(ctx, request);
799
  if (ctx->blocking_put_request) {
800
    int res;
801
    res = request_handler_process_put_request(ctx, request);
802
    free_request(request);
803
    return res;
804
  }
791 805
  else
792 806
    add_request(ctx, request);
793 807

  
src/TopologyManager/cloudcast_proto.c
123 123
  len = cloudcast_payload_fill(context, headerless_pkt, MAX_MSG_SIZE - sizeof(cloud_header), cloud_cache, 0, 1);
124 124

  
125 125
  if (len > 0)
126
    res = put_on_cloud(context->cloud_context, CLOUD_VIEW_KEY, headerless_pkt, len);
126
    res = put_on_cloud(context->cloud_context, CLOUD_VIEW_KEY, headerless_pkt, len, 0);
127 127
  else
128 128
    res = 0;
129 129
  return res;
......
131 131

  
132 132
int cloudcast_query_cloud(struct cloudcast_proto_context *context)
133 133
{
134
  return get_from_cloud(context->cloud_context, CLOUD_VIEW_KEY, (uint8_t *)&cloud_header, sizeof(cloud_header));
134
  return get_from_cloud(context->cloud_context, CLOUD_VIEW_KEY, (uint8_t *)&cloud_header, sizeof(cloud_header), 0);
135 135
}
136 136

  
137 137
struct peer_cache * cloudcast_cloud_default_reply(struct peer_cache *template, struct nodeID *cloud_entry)

Also available in: Unified diff