aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-05-13 22:20:01 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-05-13 22:20:01 +0000
commitc2335d65e672477399b9bf208de9914e1e4f341b (patch)
tree8fd795da759cc6495a445c94f38051aba95055f8 /src/peerstore
parentdb2ee15ca4302b0e7fa78e318833cd136265b746 (diff)
downloadgnunet-c2335d65e672477399b9bf208de9914e1e4f341b.tar.gz
gnunet-c2335d65e672477399b9bf208de9914e1e4f341b.zip
reconnect on error
Diffstat (limited to 'src/peerstore')
-rw-r--r--src/peerstore/peerstore_api.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index 4bc36bddc..fe6ff0fe3 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -58,6 +58,11 @@ struct GNUNET_PEERSTORE_StoreContext
58{ 58{
59 59
60 /** 60 /**
61 * Handle to the PEERSTORE service.
62 */
63 struct GNUNET_PEERSTORE_Handle *h;
64
65 /**
61 * Continuation called with service response 66 * Continuation called with service response
62 */ 67 */
63 GNUNET_PEERSTORE_Continuation cont; 68 GNUNET_PEERSTORE_Continuation cont;
@@ -74,6 +79,25 @@ struct GNUNET_PEERSTORE_StoreContext
74/******************************************************************************/ 79/******************************************************************************/
75 80
76/** 81/**
82 * Close the existing connection to PEERSTORE and reconnect.
83 *
84 * @param h handle to the service
85 */
86static void
87reconnect (struct GNUNET_PEERSTORE_Handle *h)
88{
89
90 LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n");
91 if (NULL != h->client)
92 {
93 GNUNET_CLIENT_disconnect (h->client);
94 h->client = NULL;
95 }
96 h->client = GNUNET_CLIENT_connect ("peerstore", h->cfg);
97
98}
99
100/**
77 * Connect to the PEERSTORE service. 101 * Connect to the PEERSTORE service.
78 * 102 *
79 * @return NULL on error 103 * @return NULL on error
@@ -120,7 +144,7 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
120/** 144/**
121 * When a response for store request is received 145 * When a response for store request is received
122 * 146 *
123 * @param cls unused 147 * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *'
124 * @param msg message received, NULL on timeout or fatal error 148 * @param msg message received, NULL on timeout or fatal error
125 */ 149 */
126void store_response_receiver (void *cls, const struct GNUNET_MessageHeader *msg) 150void store_response_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
@@ -133,6 +157,7 @@ void store_response_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
133 if(NULL == msg) 157 if(NULL == msg)
134 { 158 {
135 sc->cont(sc->cont_cls, GNUNET_SYSERR); 159 sc->cont(sc->cont_cls, GNUNET_SYSERR);
160 reconnect(sc->h);
136 return; 161 return;
137 } 162 }
138 msg_type = ntohs(msg->type); 163 msg_type = ntohs(msg->type);
@@ -196,6 +221,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
196 sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext); 221 sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext);
197 sc->cont = cont; 222 sc->cont = cont;
198 sc->cont_cls = cont_cls; 223 sc->cont_cls = cont_cls;
224 sc->h = h;
199 ss_size = strlen(sub_system) + 1; 225 ss_size = strlen(sub_system) + 1;
200 key_size = strlen(key) + 1; 226 key_size = strlen(key) + 1;
201 request_size = sizeof(struct StoreRequestMessage) + 227 request_size = sizeof(struct StoreRequestMessage) +