aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-20 14:54:49 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-20 14:54:49 +0000
commit4c630a158187a48ba585167b0ede49bd524d6f8d (patch)
treece1c39ef45e87f31ebb56d38c7d0e9038811e85b /src/transport/transport_api.c
parentf71fb2816cee37e823abcaa9d79c149ba90ff4cd (diff)
downloadgnunet-4c630a158187a48ba585167b0ede49bd524d6f8d.tar.gz
gnunet-4c630a158187a48ba585167b0ede49bd524d6f8d.zip
-use separate message types for TRY_CONNECT and TRY_DISCONNECT
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r--src/transport/transport_api.c215
1 files changed, 158 insertions, 57 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 3c57a83a0..4e8d2c8ea 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -65,13 +65,13 @@ struct GNUNET_TRANSPORT_TransmitHandle
65 struct Neighbour *neighbour; 65 struct Neighbour *neighbour;
66 66
67 /** 67 /**
68 * Function to call when notify_size bytes are available 68 * Function to call when @e notify_size bytes are available
69 * for transmission. 69 * for transmission.
70 */ 70 */
71 GNUNET_TRANSPORT_TransmitReadyNotify notify; 71 GNUNET_TRANSPORT_TransmitReadyNotify notify;
72 72
73 /** 73 /**
74 * Closure for notify. 74 * Closure for @e notify.
75 */ 75 */
76 void *notify_cls; 76 void *notify_cls;
77 77
@@ -95,7 +95,7 @@ struct GNUNET_TRANSPORT_TransmitHandle
95 95
96 96
97/** 97/**
98 * Entry in hash table of all of our current neighbours. 98 * Entry in hash table of all of our current (connected) neighbours.
99 */ 99 */
100struct Neighbour 100struct Neighbour
101{ 101{
@@ -120,11 +120,11 @@ struct Neighbour
120 struct GNUNET_BANDWIDTH_Tracker out_tracker; 120 struct GNUNET_BANDWIDTH_Tracker out_tracker;
121 121
122 /** 122 /**
123 * Entry in our readyness heap (which is sorted by 'next_ready' 123 * Entry in our readyness heap (which is sorted by @e next_ready
124 * value). NULL if there is no pending transmission request for 124 * value). NULL if there is no pending transmission request for
125 * this neighbour or if we're waiting for 'is_ready' to become 125 * this neighbour or if we're waiting for @e is_ready to become
126 * true AFTER the 'out_tracker' suggested that this peer's quota 126 * true AFTER the @e out_tracker suggested that this peer's quota
127 * has been satisfied (so once 'is_ready' goes to GNUNET_YES, 127 * has been satisfied (so once @e is_ready goes to #GNUNET_YES,
128 * we should immediately go back into the heap). 128 * we should immediately go back into the heap).
129 */ 129 */
130 struct GNUNET_CONTAINER_HeapNode *hn; 130 struct GNUNET_CONTAINER_HeapNode *hn;
@@ -180,8 +180,9 @@ struct GNUNET_TRANSPORT_GetHelloHandle
180 180
181}; 181};
182 182
183
183/** 184/**
184 * Linked list for all try-connect requests 185 * Entry in linked list for a try-connect request.
185 */ 186 */
186struct GNUNET_TRANSPORT_TryConnectHandle 187struct GNUNET_TRANSPORT_TryConnectHandle
187{ 188{
@@ -196,22 +197,22 @@ struct GNUNET_TRANSPORT_TryConnectHandle
196 struct GNUNET_TRANSPORT_TryConnectHandle *next; 197 struct GNUNET_TRANSPORT_TryConnectHandle *next;
197 198
198 /** 199 /**
199 * 200 * Peer we should try to connect to.
200 */ 201 */
201 struct GNUNET_PeerIdentity pid; 202 struct GNUNET_PeerIdentity pid;
202 203
203 /** 204 /**
204 * 205 * Transport service handle this request is part of.
205 */ 206 */
206 struct GNUNET_TRANSPORT_Handle *th; 207 struct GNUNET_TRANSPORT_Handle *th;
207 208
208 /** 209 /**
209 * 210 * Message transmission request to communicate to service.
210 */ 211 */
211 struct GNUNET_TRANSPORT_TransmitHandle *tth; 212 struct GNUNET_TRANSPORT_TransmitHandle *tth;
212 213
213 /** 214 /**
214 * 215 * Function to call upon completion (of request transmission).
215 */ 216 */
216 GNUNET_TRANSPORT_TryConnectCallback cb; 217 GNUNET_TRANSPORT_TryConnectCallback cb;
217 218
@@ -220,16 +221,54 @@ struct GNUNET_TRANSPORT_TryConnectHandle
220 */ 221 */
221 void *cb_cls; 222 void *cb_cls;
222 223
224};
225
226
227/**
228 * Entry in linked list for all try-disconnect requests
229 */
230struct GNUNET_TRANSPORT_TryDisconnectHandle
231{
232 /**
233 * For the DLL.
234 */
235 struct GNUNET_TRANSPORT_TryDisconnectHandle *prev;
236
223 /** 237 /**
224 * 238 * For the DLL.
239 */
240 struct GNUNET_TRANSPORT_TryDisconnectHandle *next;
241
242 /**
243 * Peer we should try to connect to.
225 */ 244 */
226 int connect; 245 struct GNUNET_PeerIdentity pid;
246
247 /**
248 * Transport service handle this request is part of.
249 */
250 struct GNUNET_TRANSPORT_Handle *th;
251
252 /**
253 * Message transmission request to communicate to service.
254 */
255 struct GNUNET_TRANSPORT_TransmitHandle *tth;
256
257 /**
258 * Function to call upon completion (of request transmission).
259 */
260 GNUNET_TRANSPORT_TryDisconnectCallback cb;
261
262 /**
263 * Closure for @e cb.
264 */
265 void *cb_cls;
227 266
228}; 267};
229 268
230 269
231/** 270/**
232 * Linked list for all try-connect requests 271 * Entry in linked list for all offer-HELLO requests.
233 */ 272 */
234struct GNUNET_TRANSPORT_OfferHelloHandle 273struct GNUNET_TRANSPORT_OfferHelloHandle
235{ 274{
@@ -244,17 +283,17 @@ struct GNUNET_TRANSPORT_OfferHelloHandle
244 struct GNUNET_TRANSPORT_OfferHelloHandle *next; 283 struct GNUNET_TRANSPORT_OfferHelloHandle *next;
245 284
246 /** 285 /**
247 * 286 * Transport service handle we use for transmission.
248 */ 287 */
249 struct GNUNET_TRANSPORT_Handle *th; 288 struct GNUNET_TRANSPORT_Handle *th;
250 289
251 /** 290 /**
252 * 291 * Transmission handle for this request.
253 */ 292 */
254 struct GNUNET_TRANSPORT_TransmitHandle *tth; 293 struct GNUNET_TRANSPORT_TransmitHandle *tth;
255 294
256 /** 295 /**
257 * 296 * Function to call once we are done.
258 */ 297 */
259 GNUNET_SCHEDULER_Task cont; 298 GNUNET_SCHEDULER_Task cont;
260 299
@@ -264,7 +303,7 @@ struct GNUNET_TRANSPORT_OfferHelloHandle
264 void *cls; 303 void *cls;
265 304
266 /** 305 /**
267 * 306 * The HELLO message to be transmitted.
268 */ 307 */
269 struct GNUNET_MessageHeader *msg; 308 struct GNUNET_MessageHeader *msg;
270}; 309};
@@ -349,6 +388,16 @@ struct GNUNET_TRANSPORT_Handle
349 struct GNUNET_TRANSPORT_TryConnectHandle *tc_tail; 388 struct GNUNET_TRANSPORT_TryConnectHandle *tc_tail;
350 389
351 /** 390 /**
391 * Linked list of pending try disconnect requests head
392 */
393 struct GNUNET_TRANSPORT_TryDisconnectHandle *td_head;
394
395 /**
396 * Linked list of pending try connect requests tail
397 */
398 struct GNUNET_TRANSPORT_TryDisconnectHandle *td_tail;
399
400 /**
352 * Linked list of pending offer HELLO requests head 401 * Linked list of pending offer HELLO requests head
353 */ 402 */
354 struct GNUNET_TRANSPORT_OfferHelloHandle *oh_head; 403 struct GNUNET_TRANSPORT_OfferHelloHandle *oh_head;
@@ -1163,29 +1212,33 @@ cancel_control_transmit (struct GNUNET_TRANSPORT_Handle *th,
1163 1212
1164 1213
1165/** 1214/**
1166 * Send REQUEST_CONNECT message to the service. 1215 * Send #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT message to the
1216 * service.
1167 * 1217 *
1168 * @param cls the `struct GNUNET_PeerIdentity` 1218 * @param cls the `struct GNUNET_TRANSPORT_TryConnectHandle`
1169 * @param size number of bytes available in @a buf 1219 * @param size number of bytes available in @a buf
1170 * @param buf where to copy the message 1220 * @param buf where to copy the message
1171 * @return number of bytes copied to @a buf 1221 * @return number of bytes copied to @a buf
1172 */ 1222 */
1173static size_t 1223static size_t
1174send_try_connect (void *cls, size_t size, void *buf) 1224send_try_connect (void *cls,
1225 size_t size,
1226 void *buf)
1175{ 1227{
1176 struct GNUNET_TRANSPORT_TryConnectHandle *tch = cls; 1228 struct GNUNET_TRANSPORT_TryConnectHandle *tch = cls;
1177 struct TransportRequestConnectMessage msg; 1229 struct TransportRequestConnectMessage msg;
1178 1230
1231 tch->tth = NULL;
1179 if (NULL == buf) 1232 if (NULL == buf)
1180 { 1233 {
1181 if (NULL != tch->cb)
1182 tch->cb (tch->cb_cls, GNUNET_SYSERR);
1183 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch);
1184 LOG (GNUNET_ERROR_TYPE_DEBUG, 1234 LOG (GNUNET_ERROR_TYPE_DEBUG,
1185 "Discarding `%s' request to `%4s' due to error in transport service connection.\n", 1235 "Discarding `%s' request to `%4s' due to error in transport service connection.\n",
1186 "REQUEST_CONNECT", 1236 "REQUEST_CONNECT",
1187 GNUNET_i2s (&tch->pid)); 1237 GNUNET_i2s (&tch->pid));
1188 GNUNET_free (tch); 1238 if (NULL != tch->cb)
1239 tch->cb (tch->cb_cls,
1240 GNUNET_SYSERR);
1241 GNUNET_TRANSPORT_try_connect_cancel (tch);
1189 return 0; 1242 return 0;
1190 } 1243 }
1191 LOG (GNUNET_ERROR_TYPE_DEBUG, 1244 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1195,13 +1248,12 @@ send_try_connect (void *cls, size_t size, void *buf)
1195 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); 1248 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1196 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); 1249 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
1197 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT); 1250 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT);
1198 msg.connect = htonl (tch->connect); 1251 msg.reserved = htonl (0);
1199 msg.peer = tch->pid; 1252 msg.peer = tch->pid;
1200 memcpy (buf, &msg, sizeof (msg)); 1253 memcpy (buf, &msg, sizeof (msg));
1201 if (NULL != tch->cb) 1254 if (NULL != tch->cb)
1202 tch->cb (tch->cb_cls, GNUNET_OK); 1255 tch->cb (tch->cb_cls, GNUNET_OK);
1203 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch); 1256 GNUNET_TRANSPORT_try_connect_cancel (tch);
1204 GNUNET_free (tch);
1205 return sizeof (struct TransportRequestConnectMessage); 1257 return sizeof (struct TransportRequestConnectMessage);
1206} 1258}
1207 1259
@@ -1233,7 +1285,6 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1233 tch->pid = *(target); 1285 tch->pid = *(target);
1234 tch->cb = cb; 1286 tch->cb = cb;
1235 tch->cb_cls = cb_cls; 1287 tch->cb_cls = cb_cls;
1236 tch->connect = GNUNET_YES;
1237 tch->tth = schedule_control_transmit (handle, 1288 tch->tth = schedule_control_transmit (handle,
1238 sizeof (struct TransportRequestConnectMessage), 1289 sizeof (struct TransportRequestConnectMessage),
1239 &send_try_connect, tch); 1290 &send_try_connect, tch);
@@ -1254,16 +1305,65 @@ void
1254GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch) 1305GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch)
1255{ 1306{
1256 struct GNUNET_TRANSPORT_Handle *th; 1307 struct GNUNET_TRANSPORT_Handle *th;
1257 GNUNET_assert (GNUNET_YES == tch->connect);
1258 1308
1259 th = tch->th; 1309 th = tch->th;
1260 cancel_control_transmit (th, tch->tth); 1310 if (NULL != tch->tth)
1261 GNUNET_CONTAINER_DLL_remove (th->tc_head, th->tc_tail, tch); 1311 cancel_control_transmit (th, tch->tth);
1312 GNUNET_CONTAINER_DLL_remove (th->tc_head,
1313 th->tc_tail,
1314 tch);
1262 GNUNET_free (tch); 1315 GNUNET_free (tch);
1263} 1316}
1264 1317
1265 1318
1266/** 1319/**
1320 * Send #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT message to the
1321 * service.
1322 *
1323 * @param cls the `struct GNUNET_TRANSPORT_TryDisconnectHandle`
1324 * @param size number of bytes available in @a buf
1325 * @param buf where to copy the message
1326 * @return number of bytes copied to @a buf
1327 */
1328static size_t
1329send_try_disconnect (void *cls,
1330 size_t size,
1331 void *buf)
1332{
1333 struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh = cls;
1334 struct TransportRequestConnectMessage msg;
1335
1336 tdh->th = NULL;
1337 if (NULL == buf)
1338 {
1339 LOG (GNUNET_ERROR_TYPE_DEBUG,
1340 "Discarding `%s' request to `%4s' due to error in transport service connection.\n",
1341 "REQUEST_DISCONNECT",
1342 GNUNET_i2s (&tdh->pid));
1343 if (NULL != tdh->cb)
1344 tdh->cb (tdh->cb_cls,
1345 GNUNET_SYSERR);
1346 GNUNET_TRANSPORT_try_disconnect_cancel (tdh);
1347 return 0;
1348 }
1349 LOG (GNUNET_ERROR_TYPE_DEBUG,
1350 "Transmitting `%s' request with respect to `%4s'.\n",
1351 "REQUEST_DISCONNECT",
1352 GNUNET_i2s (&tdh->pid));
1353 GNUNET_assert (size >= sizeof (struct TransportRequestDisconnectMessage));
1354 msg.header.size = htons (sizeof (struct TransportRequestDisconnectMessage));
1355 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT);
1356 msg.reserved = htonl (0);
1357 msg.peer = tdh->pid;
1358 memcpy (buf, &msg, sizeof (msg));
1359 if (NULL != tdh->cb)
1360 tdh->cb (tdh->cb_cls, GNUNET_OK);
1361 GNUNET_TRANSPORT_try_disconnect_cancel (tdh);
1362 return sizeof (struct TransportRequestDisconnectMessage);
1363}
1364
1365
1366/**
1267 * Ask the transport service to shutdown a connection to 1367 * Ask the transport service to shutdown a connection to
1268 * the given peer. 1368 * the given peer.
1269 * 1369 *
@@ -1272,32 +1372,31 @@ GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *t
1272 * @param cb callback to be called when request was transmitted to transport 1372 * @param cb callback to be called when request was transmitted to transport
1273 * service 1373 * service
1274 * @param cb_cls closure for the callback @a cb 1374 * @param cb_cls closure for the callback @a cb
1275 * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or 1375 * @return a `struct GNUNET_TRANSPORT_TryDisconnectHandle` handle or
1276 * NULL on failure (cb will not be called) 1376 * NULL on failure (cb will not be called)
1277 */ 1377 */
1278struct GNUNET_TRANSPORT_TryConnectHandle * 1378struct GNUNET_TRANSPORT_TryDisconnectHandle *
1279GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle, 1379GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle,
1280 const struct GNUNET_PeerIdentity *target, 1380 const struct GNUNET_PeerIdentity *target,
1281 GNUNET_TRANSPORT_TryConnectCallback cb, 1381 GNUNET_TRANSPORT_TryDisconnectCallback cb,
1282 void *cb_cls) 1382 void *cb_cls)
1283{ 1383{
1284 struct GNUNET_TRANSPORT_TryConnectHandle *tch; 1384 struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh;
1285 1385
1286 if (NULL == handle->client) 1386 if (NULL == handle->client)
1287 return NULL; 1387 return NULL;
1288 tch = GNUNET_new (struct GNUNET_TRANSPORT_TryConnectHandle); 1388 tdh = GNUNET_new (struct GNUNET_TRANSPORT_TryDisconnectHandle);
1289 tch->th = handle; 1389 tdh->th = handle;
1290 tch->pid = *(target); 1390 tdh->pid = *(target);
1291 tch->cb = cb; 1391 tdh->cb = cb;
1292 tch->cb_cls = cb_cls; 1392 tdh->cb_cls = cb_cls;
1293 tch->connect = GNUNET_NO; 1393 tdh->tth = schedule_control_transmit (handle,
1294 tch->tth = schedule_control_transmit (handle, 1394 sizeof (struct TransportRequestDisconnectMessage),
1295 sizeof (struct TransportRequestConnectMessage), 1395 &send_try_disconnect, tdh);
1296 &send_try_connect, tch); 1396 GNUNET_CONTAINER_DLL_insert (handle->td_head,
1297 GNUNET_CONTAINER_DLL_insert (handle->tc_head, 1397 handle->td_tail,
1298 handle->tc_tail, 1398 tdh);
1299 tch); 1399 return tdh;
1300 return tch;
1301} 1400}
1302 1401
1303 1402
@@ -1305,18 +1404,20 @@ GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle,
1305 * Cancel the request to transport to try a disconnect 1404 * Cancel the request to transport to try a disconnect
1306 * Callback will not be called 1405 * Callback will not be called
1307 * 1406 *
1308 * @param tch the handle to cancel 1407 * @param tdh the handle to cancel
1309 */ 1408 */
1310void 1409void
1311GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch) 1410GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh)
1312{ 1411{
1313 struct GNUNET_TRANSPORT_Handle *th; 1412 struct GNUNET_TRANSPORT_Handle *th;
1314 1413
1315 GNUNET_assert (GNUNET_NO == tch->connect); 1414 th = tdh->th;
1316 th = tch->th; 1415 if (NULL != tdh->tth)
1317 cancel_control_transmit (th, tch->tth); 1416 cancel_control_transmit (th, tdh->tth);
1318 GNUNET_CONTAINER_DLL_remove (th->tc_head, th->tc_tail, tch); 1417 GNUNET_CONTAINER_DLL_remove (th->td_head,
1319 GNUNET_free (tch); 1418 th->td_tail,
1419 tdh);
1420 GNUNET_free (tdh);
1320} 1421}
1321 1422
1322 1423