aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api2_monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api2_monitor.c')
-rw-r--r--src/transport/transport_api2_monitor.c72
1 files changed, 24 insertions, 48 deletions
diff --git a/src/transport/transport_api2_monitor.c b/src/transport/transport_api2_monitor.c
index 315001bad..97812ff89 100644
--- a/src/transport/transport_api2_monitor.c
+++ b/src/transport/transport_api2_monitor.c
@@ -64,7 +64,6 @@ struct GNUNET_TRANSPORT_MonitorContext
64 * Closure for @e cb. 64 * Closure for @e cb.
65 */ 65 */
66 void *cb_cls; 66 void *cb_cls;
67
68}; 67};
69 68
70 69
@@ -91,12 +90,10 @@ send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc)
91 90
92 if (NULL == mc->mq) 91 if (NULL == mc->mq)
93 return; 92 return;
94 env = GNUNET_MQ_msg (smm, 93 env = GNUNET_MQ_msg (smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START);
95 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START);
96 smm->one_shot = htonl ((uint32_t) mc->one_shot); 94 smm->one_shot = htonl ((uint32_t) mc->one_shot);
97 smm->peer = mc->peer; 95 smm->peer = mc->peer;
98 GNUNET_MQ_send (mc->mq, 96 GNUNET_MQ_send (mc->mq, env);
99 env);
100} 97}
101 98
102 99
@@ -122,14 +119,13 @@ disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
122 * @param error what error happened? 119 * @param error what error happened?
123 */ 120 */
124static void 121static void
125error_handler (void *cls, 122error_handler (void *cls, enum GNUNET_MQ_Error error)
126 enum GNUNET_MQ_Error error)
127{ 123{
128 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 124 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
129 125
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 126 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
131 "MQ failure %d, reconnecting to transport service.\n", 127 "MQ failure %d, reconnecting to transport service.\n",
132 error); 128 error);
133 disconnect (mc); 129 disconnect (mc);
134 /* TODO: maybe do this with exponential backoff/delay */ 130 /* TODO: maybe do this with exponential backoff/delay */
135 reconnect (mc); 131 reconnect (mc);
@@ -145,19 +141,10 @@ error_handler (void *cls,
145 * @return #GNUNET_OK if @a smt is well-formed 141 * @return #GNUNET_OK if @a smt is well-formed
146 */ 142 */
147static int 143static int
148check_monitor_data (void *cls, 144check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
149 const struct GNUNET_TRANSPORT_MonitorData *md)
150{ 145{
151 uint16_t len = ntohs (md->header.size) - sizeof (*md);
152 const char *addr = (const char *) &md[1];
153
154 (void) cls; 146 (void) cls;
155 if ( (0 == len) || 147 GNUNET_MQ_check_zero_termination (md);
156 ('\0' != addr[len-1]) )
157 {
158 GNUNET_break (0);
159 return GNUNET_SYSERR;
160 }
161 return GNUNET_OK; 148 return GNUNET_OK;
162} 149}
163 150
@@ -169,8 +156,7 @@ check_monitor_data (void *cls,
169 * @param md monitor data 156 * @param md monitor data
170 */ 157 */
171static void 158static void
172handle_monitor_data (void *cls, 159handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
173 const struct GNUNET_TRANSPORT_MonitorData *md)
174{ 160{
175 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 161 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
176 struct GNUNET_TRANSPORT_MonitorInformation mi; 162 struct GNUNET_TRANSPORT_MonitorInformation mi;
@@ -184,9 +170,7 @@ handle_monitor_data (void *cls,
184 mi.valid_until = GNUNET_TIME_absolute_ntoh (md->valid_until); 170 mi.valid_until = GNUNET_TIME_absolute_ntoh (md->valid_until);
185 mi.next_validation = GNUNET_TIME_absolute_ntoh (md->next_validation); 171 mi.next_validation = GNUNET_TIME_absolute_ntoh (md->next_validation);
186 mi.rtt = GNUNET_TIME_relative_ntoh (md->rtt); 172 mi.rtt = GNUNET_TIME_relative_ntoh (md->rtt);
187 mc->cb (mc->cb_cls, 173 mc->cb (mc->cb_cls, &md->peer, &mi);
188 &md->peer,
189 &mi);
190} 174}
191 175
192 176
@@ -197,8 +181,7 @@ handle_monitor_data (void *cls,
197 * @param me end message 181 * @param me end message
198 */ 182 */
199static void 183static void
200handle_monitor_end (void *cls, 184handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me)
201 const struct GNUNET_MessageHeader *me)
202{ 185{
203 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 186 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
204 187
@@ -209,9 +192,7 @@ handle_monitor_end (void *cls,
209 reconnect (mc); 192 reconnect (mc);
210 return; 193 return;
211 } 194 }
212 mc->cb (mc->cb_cls, 195 mc->cb (mc->cb_cls, NULL, NULL);
213 NULL,
214 NULL);
215 GNUNET_TRANSPORT_monitor_cancel (mc); 196 GNUNET_TRANSPORT_monitor_cancel (mc);
216} 197}
217 198
@@ -224,23 +205,19 @@ handle_monitor_end (void *cls,
224static void 205static void
225reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) 206reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
226{ 207{
227 struct GNUNET_MQ_MessageHandler handlers[] = { 208 struct GNUNET_MQ_MessageHandler handlers[] =
228 GNUNET_MQ_hd_var_size (monitor_data, 209 {GNUNET_MQ_hd_var_size (monitor_data,
229 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, 210 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA,
230 struct GNUNET_TRANSPORT_MonitorData, 211 struct GNUNET_TRANSPORT_MonitorData,
231 mc), 212 mc),
232 GNUNET_MQ_hd_fixed_size (monitor_end, 213 GNUNET_MQ_hd_fixed_size (monitor_end,
233 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, 214 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END,
234 struct GNUNET_MessageHeader, 215 struct GNUNET_MessageHeader,
235 mc), 216 mc),
236 GNUNET_MQ_handler_end() 217 GNUNET_MQ_handler_end ()};
237 }; 218
238 219 mc->mq =
239 mc->mq = GNUNET_CLIENT_connect (mc->cfg, 220 GNUNET_CLIENT_connect (mc->cfg, "transport", handlers, &error_handler, mc);
240 "transport",
241 handlers,
242 &error_handler,
243 mc);
244 if (NULL == mc->mq) 221 if (NULL == mc->mq)
245 return; 222 return;
246 send_start_monitor (mc); 223 send_start_monitor (mc);
@@ -299,7 +276,6 @@ GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
299} 276}
300 277
301 278
302
303/** 279/**
304 * Cancel request to monitor peers 280 * Cancel request to monitor peers
305 * 281 *