Revision 0e9bde83

View differences:

include/cloud_helper.h
50 50
int get_from_cloud(struct cloud_helper_context *context, char *key, uint8_t *header_ptr, int header_size);
51 51

  
52 52
/**
53
 * @brief Returns the timestamp associated to the last GET operation.
54
 * Returns the timestamp associated to the last GET operation or NULL.
55
 * @param[in] context The contex representing the desired cloud_helper instance.
56
 * @return timestamp ot NULL
57
 */
58
time_t timestamp_cloud(struct cloud_helper_context *context);
59

  
60
/**
53 61
 * @brief Put on the cloud the value for a specified key.
54 62
 * This function transparently handles the sending routines.
55 63
 * @param[in] context The contex representing the desired cloud_helper instance.
......
61 69
int put_on_cloud(struct cloud_helper_context *context, char *key, uint8_t *buffer_ptr, int buffer_size);
62 70

  
63 71
/**
64
 * @brief Returns the nodeID identifing the cloud
65
 * This function transparently handles the identification of the cloud node.
72
 * @brief Returns the nodeID identifing the cloud for the specified variant.
73
 * This function transparently handles the identification of the cloud
74
 * node. Thanks to the variant parameter is possible to recover
75
 * nodeIDs which differ wrt to nodeid_equal, but are equal wrt to is_cloud_node.
66 76
 * @param[in] context The contex representing the desired cloud_helper instance.
77
 * @param[in] variant The variant number for this nodeID.
67 78
 * @return nodeID identifying the cloud.
68 79
 */
69
struct nodeID* get_cloud_node(struct cloud_helper_context *context);
80
struct nodeID* get_cloud_node(struct cloud_helper_context *context, uint8_t variant);
70 81

  
71 82
/**
72 83
 * @brief Check if the specified node references the cloud
src/Tests/cloud_helper_delegate_file.c
6 6
#include <stdint.h>
7 7
#include <semaphore.h>
8 8
#include <pthread.h>
9
#include <time.h>
9 10

  
10 11
#include "net_helper.h"
11 12

  
......
13 14
  void* (*cloud_helper_init)(struct nodeID *local, const char *config);
14 15
  int (*get_from_cloud)(void *context, char *key, uint8_t *header_ptr, int header_size);
15 16
  int (*put_on_cloud)(void *context, char *key, uint8_t *buffer_ptr, int buffer_size);
16
  struct nodeID* (*get_cloud_node)(void *context);
17
  struct nodeID* (*get_cloud_node)(void *context, uint8_t variant);
18
  time_t (*timestamp_cloud)(void *context);
17 19
  int (*is_cloud_node)(void *context, struct nodeID* node);
18 20
  int (*wait4cloud)(void *context, struct timeval *tout);
19 21
  int (*recv_from_cloud)(void *context, uint8_t *buffer_ptr, int buffer_size);
......
27 29
struct file_cloud_context {
28 30
  const char *path;
29 31
  sem_t sem;
32
  time_t last_timestamp;
30 33
  uint8_t *out_buffer[10];
31 34
  struct mem_offset out_len[10];
32 35
  int out_cnt;
......
48 51
  char key[100];
49 52
  uint8_t value[100];
50 53
  int value_len;
54
  time_t timestamp;
51 55
};
52 56

  
53 57

  
......
85 89
      sem_wait(&ctx->cloud->sem);
86 90
      memcpy(buffer_ptr, e.value, e.value_len);
87 91
      len->end += e.value_len;      
88

  
92
      ctx->cloud->last_timestamp = e.timestamp;
89 93
      ctx->cloud->key_error = 0;
90 94
      sem_post(&ctx->cloud->sem);
91 95
      break;
......
122 126
    if (strcmp(e.key, ctx->key) == 0){
123 127
      memcpy(e.value, ctx->value, ctx->value_len);
124 128
      e.value_len = ctx->value_len;
129
      time(&e.timestamp);
125 130
      fseek(fd, -sizeof(e), SEEK_CUR);
126 131
      fwrite(&e, sizeof(e), 1, fd);
127 132
      found = 1;
......
132 137
    strcpy(e.key, ctx->key);
133 138
    memcpy(e.value, ctx->value, ctx->value_len);
134 139
    e.value_len = ctx->value_len;    
140
    time(&e.timestamp);
135 141
    fwrite(&e, sizeof(e), 1, fd);
136 142
  }
137 143
  fflush(fd);
......
224 230
  return 0;  
225 231
}
226 232

  
227
struct nodeID* file_cloud_get_cloud_node(void *context)
233
struct nodeID* file_cloud_get_cloud_node(void *context, uint8_t variant)
228 234
{
229 235
  struct file_cloud_context *ctx;
230 236
  ctx = (struct file_cloud_context *)context;
231
  return ctx->cloud_node_base;
237
  return create_node("0.0.0.0", variant);
238
}
239

  
240
time_t file_cloud_timestamp_cloud(void *context)
241
{
242
  struct file_cloud_context *ctx;
243
  ctx = (struct file_cloud_context *)context;
244

  
245
  return ctx->last_timestamp;
232 246
}
233 247

  
234 248
int file_cloud_is_cloud_node(void *context, struct nodeID* node)
......
301 315
  .get_from_cloud = &file_cloud_get_from_cloud,
302 316
  .put_on_cloud = &file_cloud_put_on_cloud,
303 317
  .get_cloud_node = &file_cloud_get_cloud_node,
318
  .timestamp_cloud = &file_cloud_timestamp_cloud,
304 319
  .is_cloud_node = &file_cloud_is_cloud_node,
305 320
  .wait4cloud = file_cloud_wait4cloud,
306 321
  .recv_from_cloud = file_cloud_recv_from_cloud
src/Tests/cloud_test.c
5 5
 *
6 6
 *  This is a small test program for the cloud interface
7 7
 *  To try the simple test: run it with
8
 *    ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -p key=value | -n | -e ip:port]
8
 *    ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -p key=value | -n variant | -e ip:port]
9 9
 *
10 10
 *    -g  GET key from cloud
11 11
 *    -p  PUT key=value on cloud
12
 *    -n  print the cloud node
12
 *    -n  print the cloud node for the specified variant
13 13
 *    -e  check if ip:port references the cloud
14 14
 *    -c  set the configuration of the cloud provider
15 15
 *
......
35 35

  
36 36
static const char *config;
37 37
static int operation;
38
static int variant;
38 39
static char *key;
39 40
static char *value;
40 41

  
......
46 47
  int o;
47 48
  char *temp;
48 49
      
49
  while ((o = getopt(argc, argv, "c:g:p:ne:")) != -1) {
50
  while ((o = getopt(argc, argv, "c:g:p:n:e:")) != -1) {
50 51
    switch(o) {
51 52
    case 'c':
52 53
      config = strdup(optarg);
......
69 70
        break;
70 71
    case 'n':
71 72
      operation = GET_CLOUD_NODE;
73
      variant = atoi(optarg);
72 74
      break;
73 75
    case 'e':
74 76
      operation = EQ_CLOUD_NODE;
......
154 156
      } else if (err == 0) {
155 157
	printf("Key not present on the cloud\n");
156 158
      } else {
159
        time_t timestamp;
157 160
	buffer[sizeof(buffer) - 1] = '\0';
158 161
	printf("%s\n", buffer);
162
        timestamp = timestamp_cloud(cloud);
163
        printf("Timestamp: %s\n", ctime(&timestamp));
159 164
      }
160 165
    } else if (err == 0){
161 166
      printf("No response from cloud\n");
......
168 173
    }
169 174
    break;
170 175
  case GET_CLOUD_NODE:
171
    printf("Cloud node: %s\n", node_addr(get_cloud_node(cloud)));
176
    printf("Cloud node: %s\n", node_addr(get_cloud_node(cloud, variant)));
172 177
    break;
173 178
  case EQ_CLOUD_NODE:
174 179
    t = create_node(key, atoi(value));
175
    printf("Node %s references cloud? %d\n", node_addr(get_cloud_node(cloud)),
180
    printf("Node %s references cloud? %d\n", node_addr(get_cloud_node(cloud, variant)),
176 181
	   is_cloud_node(cloud, t));
177 182
    break;
178 183
  }
src/TopologyManager/cloud_helper.c
82 82
  return context->ch->put_on_cloud(context->ch_context, key, buffer_ptr, buffer_size);
83 83
}
84 84

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

  
90
time_t timestamp_cloud(struct cloud_helper_context *context)
91
{
92
  return context->ch->timestamp_cloud(context->ch_context);
88 93
}
89 94

  
90 95
int is_cloud_node(struct cloud_helper_context *context, struct nodeID* node)
src/TopologyManager/cloud_helper_delegate.c
1 1
#include <stdlib.h>
2 2
#include <stdint.h>
3 3
#include <dlfcn.h>
4
#include <stdio.h>
4 5

  
5 6
#include "cloud_helper_iface.h"
6 7
#include "config.h"
......
9 10
  void* (*cloud_helper_init)(struct nodeID *local, const char *config);
10 11
  int (*get_from_cloud)(void *context, char *key, uint8_t *header_ptr, int header_size);
11 12
  int (*put_on_cloud)(void *context, char *key, uint8_t *buffer_ptr, int buffer_size);
12
  struct nodeID* (*get_cloud_node)(void *context);
13
  struct nodeID* (*get_cloud_node)(void *context, uint8_t variant);
14
  time_t (*timestamp_cloud)(void *context);
13 15
  int (*is_cloud_node)(void *context, struct nodeID* node);
14 16
  int (*wait4cloud)(void *context, struct timeval *tout);
15 17
  int (*recv_from_cloud)(void *context, uint8_t *buffer_ptr, int buffer_size);
......
62 64
  return context->delegate->put_on_cloud(context->delegate_context, key, buffer_ptr, buffer_size);
63 65
}
64 66

  
65
static struct nodeID* delegate_cloud_get_cloud_node(struct cloud_helper_impl_context *context)
67
static struct nodeID* delegate_cloud_get_cloud_node(struct cloud_helper_impl_context *context, uint8_t variant)
66 68
{
67
  return context->delegate->get_cloud_node(context->delegate_context);
69
  return context->delegate->get_cloud_node(context->delegate_context, variant);
70
}
71

  
72
static time_t delegate_timestamp_cloud(struct cloud_helper_impl_context *context)
73
{
74
  return context->delegate->timestamp_cloud(context->delegate_context);
68 75
}
69 76

  
70 77
int delegate_is_cloud_node(struct cloud_helper_impl_context *context, struct nodeID* node)
......
87 94
  .get_from_cloud = delegate_cloud_get_from_cloud,
88 95
  .put_on_cloud = delegate_cloud_put_on_cloud,
89 96
  .get_cloud_node = delegate_cloud_get_cloud_node,
97
  .timestamp_cloud = delegate_timestamp_cloud,
90 98
  .is_cloud_node = delegate_is_cloud_node,
91 99
  .wait4cloud = delegate_cloud_wait4cloud,
92 100
  .recv_from_cloud = delegate_cloud_recv_from_cloud,
src/TopologyManager/cloud_helper_iface.h
1 1
#ifndef CLOUD_HELPER_IFACE
2 2
#define CLOUD_HELPER_IFACE
3 3

  
4
#include <time.h>
4 5
#include "net_helper.h"
5 6

  
6 7
struct cloud_helper_impl_context;
......
9 10
  struct cloud_helper_impl_context* (*cloud_helper_init)(struct nodeID *local, const char *config);
10 11
  int (*get_from_cloud)(struct cloud_helper_impl_context *context, char *key, uint8_t *header_ptr, int header_size);
11 12
  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
  struct nodeID* (*get_cloud_node)(struct cloud_helper_impl_context *context, uint8_t variant);
14
  time_t (*timestamp_cloud)(struct cloud_helper_impl_context *context);
13 15
  int (*is_cloud_node)(struct cloud_helper_impl_context *context, struct nodeID* node);
14 16
  int (*wait4cloud)(struct cloud_helper_impl_context *context, struct timeval *tout);
15 17
  int (*recv_from_cloud)(struct cloud_helper_impl_context *context, uint8_t *buffer_ptr, int buffer_size);

Also available in: Unified diff