aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2015-07-31 11:18:36 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2015-07-31 11:18:36 +0000
commit0ae9cfdf1957653a915d41bffea9d1f4f8b3de2b (patch)
tree43b91d6e54bc0beea7b776e3bbcfb12ea835fd22 /src/rps
parent957a3ee819dd1f168ec0103f92764845ed109b78 (diff)
downloadgnunet-0ae9cfdf1957653a915d41bffea9d1f4f8b3de2b.tar.gz
gnunet-0ae9cfdf1957653a915d41bffea9d1f4f8b3de2b.zip
reconnect upon broken server connection
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/rps_api.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index b5a1ccb44..854ea25cf 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -40,7 +40,7 @@ struct GNUNET_RPS_Handle
40 /** 40 /**
41 * The handle to the client configuration. 41 * The handle to the client configuration.
42 */ 42 */
43 const struct GNUNET_CONFIGURATION_Handle *cfg; 43 struct GNUNET_CONFIGURATION_Handle *cfg;
44 44
45 /** 45 /**
46 * The connection to the client. 46 * The connection to the client.
@@ -144,6 +144,12 @@ handle_reply (void *cls,
144 rh->ready_cb((rh)->ready_cb_cls, ntohl (msg->num_peers), peers); 144 rh->ready_cb((rh)->ready_cb_cls, ntohl (msg->num_peers), peers);
145} 145}
146 146
147/**
148 * Reconnect to the service
149 */
150static void
151reconnect (struct GNUNET_RPS_Handle *h);
152
147 153
148/** 154/**
149 * Error handler for mq. 155 * Error handler for mq.
@@ -157,13 +163,37 @@ handle_reply (void *cls,
157 static void 163 static void
158mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 164mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
159{ 165{
166 struct GNUNET_RPS_Handle *h = cls;
160 //TODO LOG 167 //TODO LOG
161 LOG (GNUNET_ERROR_TYPE_WARNING, "Some problem with the message queue. error: %i\n\ 168 LOG (GNUNET_ERROR_TYPE_WARNING, "Some problem with the message queue. error: %i\n\
162 1: READ,\n\ 169 1: READ,\n\
163 2: WRITE,\n\ 170 2: WRITE,\n\
164 4: TIMEOUT\n", 171 4: TIMEOUT\n",
165 error); 172 error);
173 reconnect (h);
174}
175
176/**
177 * Reconnect to the service
178 */
179static void
180reconnect (struct GNUNET_RPS_Handle *h)
181{
182 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
183 {&handle_reply, GNUNET_MESSAGE_TYPE_RPS_CS_REPLY, 0},
184 GNUNET_MQ_HANDLERS_END
185 };
166 186
187 if (NULL != h->mq)
188 GNUNET_MQ_destroy (h->mq);
189 if (NULL != h->conn)
190 GNUNET_CLIENT_disconnect (h->conn);
191 h->conn = GNUNET_CLIENT_connect ("rps", h->cfg);
192 GNUNET_assert (NULL != h->conn);
193 h->mq = GNUNET_MQ_queue_for_connection_client(h->conn,
194 mq_handlers,
195 mq_error_handler, // TODO implement
196 h);
167} 197}
168 198
169/** 199/**
@@ -177,21 +207,10 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
177{ 207{
178 struct GNUNET_RPS_Handle *h; 208 struct GNUNET_RPS_Handle *h;
179 //struct GNUNET_RPS_Request_Handle *rh; 209 //struct GNUNET_RPS_Request_Handle *rh;
180 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
181 {&handle_reply, GNUNET_MESSAGE_TYPE_RPS_CS_REPLY, 0},
182 GNUNET_MQ_HANDLERS_END
183 };
184 210
185 h = GNUNET_new(struct GNUNET_RPS_Handle); 211 h = GNUNET_new(struct GNUNET_RPS_Handle);
186 //h->cfg = GNUNET_new(struct GNUNET_CONFIGURATION_Handle); 212 h->cfg = GNUNET_CONFIGURATION_dup (cfg);
187 //*h->cfg = *cfg; 213 reconnect (h);
188 h->cfg = cfg; // FIXME |^
189 h->conn = GNUNET_CLIENT_connect("rps", cfg);
190 h->mq = GNUNET_MQ_queue_for_connection_client(h->conn,
191 mq_handlers,
192 mq_error_handler, // TODO implement
193 h);
194
195 return h; 214 return h;
196} 215}
197 216
@@ -413,6 +432,9 @@ GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
413{ 432{
414 if (NULL != h->conn) 433 if (NULL != h->conn)
415 GNUNET_CLIENT_disconnect (h->conn); 434 GNUNET_CLIENT_disconnect (h->conn);
435 GNUNET_CONFIGURATION_destroy (h->cfg);
436 GNUNET_MQ_destroy (h->mq);
437 GNUNET_free (h);
416} 438}
417 439
418 440