aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-05-12 10:10:41 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-05-12 10:10:41 +0000
commitd9cc0e96edf3637d292bf09671b216bf396faa36 (patch)
treebbbb0d642f73e817e5551f8c7f9de0a80343382c /src/peerstore
parent54b5026b7bf917816bef12620f94715ae1dd6f78 (diff)
downloadgnunet-d9cc0e96edf3637d292bf09671b216bf396faa36.tar.gz
gnunet-d9cc0e96edf3637d292bf09671b216bf396faa36.zip
PEERSTORE api fix
Diffstat (limited to 'src/peerstore')
-rw-r--r--src/peerstore/gnunet-peerstore.c14
-rw-r--r--src/peerstore/gnunet-service-peerstore.c12
-rw-r--r--src/peerstore/peerstore.h4
-rw-r--r--src/peerstore/peerstore_api.c10
4 files changed, 29 insertions, 11 deletions
diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c
index 750cc5636..9b26cf36c 100644
--- a/src/peerstore/gnunet-peerstore.c
+++ b/src/peerstore/gnunet-peerstore.c
@@ -58,7 +58,9 @@ shutdown_task (void *cls,
58 58
59void test_cont(void *cls, const char *emsg) 59void test_cont(void *cls, const char *emsg)
60{ 60{
61 printf("Received a response\n"); 61 char *req = cls;
62
63 printf("Received a response to request: %s\n", req);
62 if(NULL != emsg) 64 if(NULL != emsg)
63 { 65 {
64 printf("Response: %s\n", emsg); 66 printf("Response: %s\n", emsg);
@@ -97,7 +99,15 @@ run (void *cls,
97 5, 99 5,
98 GNUNET_TIME_UNIT_FOREVER_REL, 100 GNUNET_TIME_UNIT_FOREVER_REL,
99 &test_cont, 101 &test_cont,
100 NULL); 102 "Req1");
103 GNUNET_PEERSTORE_store(peerstore_handle,
104 &pid,
105 "subsub",
106 "value",
107 5,
108 GNUNET_TIME_UNIT_FOREVER_REL,
109 &test_cont,
110 "Req2");
101 } 111 }
102 112
103 ret = 0; 113 ret = 0;
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c
index f56860971..35eee01b1 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -102,13 +102,17 @@ void handle_store (void *cls,
102 //TODO: do the actual storage 102 //TODO: do the actual storage
103 //create a fake response for testing 103 //create a fake response for testing
104 char *response = "This is a response"; 104 char *response = "This is a response";
105 uint16_t resp_size = strlen(response);
105 tc = GNUNET_SERVER_transmit_context_create (client); 106 tc = GNUNET_SERVER_transmit_context_create (client);
106 sresm = malloc(sizeof(struct StoreResponseMessage) + strlen(response)); 107 msg_size = sizeof(struct StoreResponseMessage) + resp_size;
108 sresm = malloc(msg_size);
109 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending a response to client of size: %u, response size: %u\n", msg_size, resp_size);
107 sresm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT); 110 sresm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT);
108 sresm->header.size = htons(sizeof(struct StoreResponseMessage) + strlen(response)); 111 sresm->header.size = htons(msg_size);
109 sresm->success = htons(GNUNET_NO); 112 sresm->success = htons(GNUNET_NO);
110 sresm->emsg_size = htons(strlen(response)); 113 sresm->emsg_size = htons(resp_size);
111 memcpy(&sresm[1], response, strlen(response)); 114 char *msg_ptr = (char *)&sresm[1];
115 memcpy(msg_ptr, response, resp_size);
112 GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)sresm); 116 GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)sresm);
113 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 117 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
114} 118}
diff --git a/src/peerstore/peerstore.h b/src/peerstore/peerstore.h
index 255afc82c..33d31870c 100644
--- a/src/peerstore/peerstore.h
+++ b/src/peerstore/peerstore.h
@@ -76,12 +76,12 @@ struct StoreResponseMessage
76 /** 76 /**
77 * Was the store operation successful (#GNUNET_YES / #GNUNET_NO) 77 * Was the store operation successful (#GNUNET_YES / #GNUNET_NO)
78 */ 78 */
79 uint16_t success; 79 uint16_t success GNUNET_PACKED;
80 80
81 /** 81 /**
82 * Size of the error message (0 if no error) 82 * Size of the error message (0 if no error)
83 */ 83 */
84 size_t emsg_size; 84 size_t emsg_size GNUNET_PACKED;
85}; 85};
86 86
87GNUNET_NETWORK_STRUCT_END 87GNUNET_NETWORK_STRUCT_END
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index f31a3b848..2ab7a7d34 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -204,6 +204,7 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204{ 204{
205 struct GNUNET_PEERSTORE_Handle *h = cls; 205 struct GNUNET_PEERSTORE_Handle *h = cls;
206 206
207 LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnect task executed\n");
207 h->r_task = GNUNET_SCHEDULER_NO_TASK; 208 h->r_task = GNUNET_SCHEDULER_NO_TASK;
208 reconnect (h); 209 reconnect (h);
209} 210}
@@ -225,6 +226,7 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
225 h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); 226 h = GNUNET_new (struct GNUNET_PEERSTORE_Handle);
226 h->client = client; 227 h->client = client;
227 h->cfg = cfg; 228 h->cfg = cfg;
229 LOG(GNUNET_ERROR_TYPE_DEBUG, "New connection created\n");
228 return h; 230 return h;
229} 231}
230 232
@@ -242,6 +244,7 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
242 h->client = NULL; 244 h->client = NULL;
243 } 245 }
244 GNUNET_free (h); 246 GNUNET_free (h);
247 LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnected, BYE!\n");
245} 248}
246 249
247/** 250/**
@@ -252,6 +255,7 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
252static void 255static void
253reconnect (struct GNUNET_PEERSTORE_Handle *h) 256reconnect (struct GNUNET_PEERSTORE_Handle *h)
254{ 257{
258 LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n");
255 if (GNUNET_SCHEDULER_NO_TASK != h->r_task) 259 if (GNUNET_SCHEDULER_NO_TASK != h->r_task)
256 { 260 {
257 GNUNET_SCHEDULER_cancel (h->r_task); 261 GNUNET_SCHEDULER_cancel (h->r_task);
@@ -403,6 +407,7 @@ peerstore_handler (void *cls, const struct GNUNET_MessageHeader *msg)
403 trigger_transmit (h); 407 trigger_transmit (h);
404 if (NULL != h->sc_head) 408 if (NULL != h->sc_head)
405 { 409 {
410 LOG(GNUNET_ERROR_TYPE_DEBUG, "Another store request awaiting response, triggering receive for it\n");
406 h->in_receive = GNUNET_YES; 411 h->in_receive = GNUNET_YES;
407 GNUNET_CLIENT_receive (h->client, 412 GNUNET_CLIENT_receive (h->client,
408 &peerstore_handler, 413 &peerstore_handler,
@@ -411,15 +416,14 @@ peerstore_handler (void *cls, const struct GNUNET_MessageHeader *msg)
411 } 416 }
412 if(NULL != cont) 417 if(NULL != cont)
413 { 418 {
414 srm = (struct StoreResponseMessage *)&msg[1]; 419 LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling continuation of store request\n");
420 srm = (struct StoreResponseMessage *)msg;
415 emsg = NULL; 421 emsg = NULL;
416 if(GNUNET_NO == ntohs(srm->success)) 422 if(GNUNET_NO == ntohs(srm->success))
417 { 423 {
418 LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling user callback with message: %s\n", emsg);
419 emsg = GNUNET_malloc(ntohs(srm->emsg_size)); 424 emsg = GNUNET_malloc(ntohs(srm->emsg_size));
420 memcpy(emsg, &srm[1], ntohs(srm->emsg_size)); 425 memcpy(emsg, &srm[1], ntohs(srm->emsg_size));
421 } 426 }
422 LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling user callback without a message\n");
423 cont(cont_cls, emsg); 427 cont(cont_cls, emsg);
424 } 428 }
425 break; 429 break;