diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-03-21 14:54:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-03-21 14:54:33 +0000 |
commit | a1746a2857e3d63f9e12f46ba310446443668ccf (patch) | |
tree | 248898b087b116bf4fe46a7a2cf5a15bfa7a52d3 /src/peerinfo/peerinfo_api_notify.c | |
parent | bd225ceaec51e7071e5b8c04921a2a8b8aa3de25 (diff) | |
download | gnunet-a1746a2857e3d63f9e12f46ba310446443668ccf.tar.gz gnunet-a1746a2857e3d63f9e12f46ba310446443668ccf.zip |
make peerinfo notify api more robust to serious disconnects
Diffstat (limited to 'src/peerinfo/peerinfo_api_notify.c')
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index ab0d13f66..eb6e29ce5 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.c | |||
@@ -62,6 +62,11 @@ struct GNUNET_PEERINFO_NotifyContext | |||
62 | */ | 62 | */ |
63 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 63 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
64 | 64 | ||
65 | /** | ||
66 | * Tasked used for delayed re-connection attempt. | ||
67 | */ | ||
68 | GNUNET_SCHEDULER_TaskIdentifier task; | ||
69 | |||
65 | }; | 70 | }; |
66 | 71 | ||
67 | 72 | ||
@@ -86,6 +91,32 @@ receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); | |||
86 | 91 | ||
87 | 92 | ||
88 | /** | 93 | /** |
94 | * Task to re-try connecting to peerinfo. | ||
95 | * | ||
96 | * @param cls the 'struct GNUNET_PEERINFO_NotifyContext' | ||
97 | * @param tc scheduler context | ||
98 | */ | ||
99 | static void | ||
100 | reconnect (void *cls, | ||
101 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
102 | { | ||
103 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | ||
104 | |||
105 | nc->task = GNUNET_SCHEDULER_NO_TASK; | ||
106 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); | ||
107 | if (NULL == nc->client) | ||
108 | { | ||
109 | /* ugh */ | ||
110 | nc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
111 | &reconnect, | ||
112 | nc); | ||
113 | return; | ||
114 | } | ||
115 | request_notifications (nc); | ||
116 | } | ||
117 | |||
118 | |||
119 | /** | ||
89 | * Receive a peerinfo information message, process it and | 120 | * Receive a peerinfo information message, process it and |
90 | * go for more. | 121 | * go for more. |
91 | * | 122 | * |
@@ -105,8 +136,7 @@ process_notification (void *cls, | |||
105 | if (msg == NULL) | 136 | if (msg == NULL) |
106 | { | 137 | { |
107 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | 138 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); |
108 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); | 139 | reconnect (nc, NULL); |
109 | request_notifications (nc); | ||
110 | return; | 140 | return; |
111 | } | 141 | } |
112 | ms = ntohs (msg->size); | 142 | ms = ntohs (msg->size); |
@@ -259,7 +289,10 @@ GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc) | |||
259 | GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init); | 289 | GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init); |
260 | nc->init = NULL; | 290 | nc->init = NULL; |
261 | } | 291 | } |
262 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | 292 | if (NULL != nc->client) |
293 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | ||
294 | if (GNUNET_SCHEDULER_NO_TASK != nc->task) | ||
295 | GNUNET_SCHEDULER_cancel (nc->task); | ||
263 | GNUNET_free (nc); | 296 | GNUNET_free (nc); |
264 | } | 297 | } |
265 | 298 | ||