aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-03-21 14:54:33 +0000
committerChristian Grothoff <christian@grothoff.org>2011-03-21 14:54:33 +0000
commita1746a2857e3d63f9e12f46ba310446443668ccf (patch)
tree248898b087b116bf4fe46a7a2cf5a15bfa7a52d3 /src/peerinfo
parentbd225ceaec51e7071e5b8c04921a2a8b8aa3de25 (diff)
downloadgnunet-a1746a2857e3d63f9e12f46ba310446443668ccf.tar.gz
gnunet-a1746a2857e3d63f9e12f46ba310446443668ccf.zip
make peerinfo notify api more robust to serious disconnects
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/peerinfo_api_notify.c39
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 */
99static void
100reconnect (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