diff options
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/peerstore_api.c | 28 |
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 | */ | ||
86 | static void | ||
87 | reconnect (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 | */ |
126 | void store_response_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | 150 | void 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) + |