diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-05-16 17:00:30 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-05-16 17:00:30 +0000 |
commit | d2f4cf2b57f6db7d788173ead9b8826deb3338f2 (patch) | |
tree | 91f066d681fda7c176d34356e22c53c27d61ed88 /src/peerstore | |
parent | 3c9e8b1b0f7f83f27fefb02bd67b481c67cad0c8 (diff) | |
download | gnunet-d2f4cf2b57f6db7d788173ead9b8826deb3338f2.tar.gz gnunet-d2f4cf2b57f6db7d788173ead9b8826deb3338f2.zip |
minor fixes
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/peerstore_api.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 323ba45d0..5a2455014 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -122,35 +122,59 @@ struct GNUNET_PEERSTORE_StoreContext | |||
122 | */ | 122 | */ |
123 | void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg); | 123 | void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg); |
124 | 124 | ||
125 | static void | ||
126 | reconnect (struct GNUNET_PEERSTORE_Handle *h); | ||
127 | |||
128 | /** | ||
129 | * MQ message handlers | ||
130 | */ | ||
131 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { | ||
132 | {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK, sizeof(struct GNUNET_MessageHeader)}, | ||
133 | {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL, sizeof(struct GNUNET_MessageHeader)}, | ||
134 | GNUNET_MQ_HANDLERS_END | ||
135 | }; | ||
136 | |||
125 | /******************************************************************************/ | 137 | /******************************************************************************/ |
126 | /******************* CONNECTION FUNCTIONS *********************/ | 138 | /******************* CONNECTION FUNCTIONS *********************/ |
127 | /******************************************************************************/ | 139 | /******************************************************************************/ |
128 | 140 | ||
141 | static void | ||
142 | handle_client_error (void *cls, enum GNUNET_MQ_Error error) | ||
143 | { | ||
144 | struct GNUNET_PEERSTORE_Handle *h = cls; | ||
145 | |||
146 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Received an error notification from MQ of type: %d\n", error); | ||
147 | reconnect(h); | ||
148 | } | ||
149 | |||
129 | /** | 150 | /** |
130 | * Close the existing connection to PEERSTORE and reconnect. | 151 | * Close the existing connection to PEERSTORE and reconnect. |
131 | * | 152 | * |
132 | * @param h handle to the service | 153 | * @param h handle to the service |
133 | */ | 154 | */ |
134 | static void | 155 | static void |
135 | reconnect (struct GNUNET_PEERSTORE_Handle *h) //FIXME: MQ friendly | 156 | reconnect (struct GNUNET_PEERSTORE_Handle *h) |
136 | { | 157 | { |
137 | 158 | ||
138 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); | 159 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); |
160 | if (NULL != h->mq) | ||
161 | { | ||
162 | GNUNET_MQ_destroy(h->mq); | ||
163 | h->mq = NULL; | ||
164 | } | ||
139 | if (NULL != h->client) | 165 | if (NULL != h->client) |
140 | { | 166 | { |
141 | GNUNET_CLIENT_disconnect (h->client); | 167 | GNUNET_CLIENT_disconnect (h->client); |
142 | h->client = NULL; | 168 | h->client = NULL; |
143 | } | 169 | } |
144 | h->client = GNUNET_CLIENT_connect ("peerstore", h->cfg); | 170 | h->client = GNUNET_CLIENT_connect ("peerstore", h->cfg); |
171 | h->mq = GNUNET_MQ_queue_for_connection_client(h->client, | ||
172 | mq_handlers, | ||
173 | &handle_client_error, | ||
174 | h); | ||
145 | 175 | ||
146 | } | 176 | } |
147 | 177 | ||
148 | static void | ||
149 | handle_client_error (void *cls, enum GNUNET_MQ_Error error) //FIXME: implement | ||
150 | { | ||
151 | //struct GNUNET_PEERSTORE_Handle *h = cls; | ||
152 | } | ||
153 | |||
154 | /** | 178 | /** |
155 | * Connect to the PEERSTORE service. | 179 | * Connect to the PEERSTORE service. |
156 | * | 180 | * |
@@ -160,11 +184,6 @@ struct GNUNET_PEERSTORE_Handle * | |||
160 | GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 184 | GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
161 | { | 185 | { |
162 | struct GNUNET_PEERSTORE_Handle *h; | 186 | struct GNUNET_PEERSTORE_Handle *h; |
163 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { | ||
164 | {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK, sizeof(struct GNUNET_MessageHeader)}, | ||
165 | {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL, sizeof(struct GNUNET_MessageHeader)}, | ||
166 | GNUNET_MQ_HANDLERS_END | ||
167 | }; | ||
168 | 187 | ||
169 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); | 188 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); |
170 | h->client = GNUNET_CLIENT_connect ("peerstore", cfg); | 189 | h->client = GNUNET_CLIENT_connect ("peerstore", cfg); |
@@ -221,7 +240,7 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h) | |||
221 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | 240 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' |
222 | * @param msg message received, NULL on timeout or fatal error | 241 | * @param msg message received, NULL on timeout or fatal error |
223 | */ | 242 | */ |
224 | void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg) //FIXME: MQ friendly | 243 | void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg) |
225 | { | 244 | { |
226 | struct GNUNET_PEERSTORE_Handle *h = cls; | 245 | struct GNUNET_PEERSTORE_Handle *h = cls; |
227 | struct GNUNET_PEERSTORE_StoreContext *sc; | 246 | struct GNUNET_PEERSTORE_StoreContext *sc; |
@@ -276,7 +295,7 @@ void store_request_sent (void *cls) | |||
276 | * @param sc Store request context | 295 | * @param sc Store request context |
277 | */ | 296 | */ |
278 | void | 297 | void |
279 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) //FIXME: MQ friendly | 298 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) |
280 | { | 299 | { |
281 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
282 | "Canceling store request.\n"); | 301 | "Canceling store request.\n"); |