diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-16 23:24:48 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-16 23:24:48 +0100 |
commit | 376138d90fe4e97d8611a8b7dfb798e79aa427cb (patch) | |
tree | cd588dfc51dc1a544dc11aaf46614941208878e1 /src/set/gnunet-service-set.c | |
parent | a37bee0b9bf81c9a1de295cc8bb747218095942b (diff) | |
download | gnunet-376138d90fe4e97d8611a8b7dfb798e79aa427cb.tar.gz gnunet-376138d90fe4e97d8611a8b7dfb798e79aa427cb.zip |
first, very rough conversion of SET service to new cadet client API (fails tests, as before)
Diffstat (limited to 'src/set/gnunet-service-set.c')
-rw-r--r-- | src/set/gnunet-service-set.c | 368 |
1 files changed, 241 insertions, 127 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 4e2eb6a28..3f1086891 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -1174,18 +1174,14 @@ handle_incoming_disconnect (struct Operation *op) | |||
1174 | * | 1174 | * |
1175 | * @param cls closure | 1175 | * @param cls closure |
1176 | * @param channel new handle to the channel | 1176 | * @param channel new handle to the channel |
1177 | * @param initiator peer that started the channel | 1177 | * @param source peer that started the channel |
1178 | * @param port Port this channel is for. | ||
1179 | * @param options Unused. | ||
1180 | * @return initial channel context for the channel | 1178 | * @return initial channel context for the channel |
1181 | * returns NULL on error | 1179 | * returns NULL on error |
1182 | */ | 1180 | */ |
1183 | static void * | 1181 | static void * |
1184 | channel_new_cb (void *cls, | 1182 | channel_new_cb (void *cls, |
1185 | struct GNUNET_CADET_Channel *channel, | 1183 | struct GNUNET_CADET_Channel *channel, |
1186 | const struct GNUNET_PeerIdentity *initiator, | 1184 | const struct GNUNET_PeerIdentity *source) |
1187 | const struct GNUNET_HashCode *port, | ||
1188 | enum GNUNET_CADET_ChannelOption options) | ||
1189 | { | 1185 | { |
1190 | static const struct SetVT incoming_vt = { | 1186 | static const struct SetVT incoming_vt = { |
1191 | .msg_handler = &handle_incoming_msg, | 1187 | .msg_handler = &handle_incoming_msg, |
@@ -1199,7 +1195,7 @@ channel_new_cb (void *cls, | |||
1199 | incoming = GNUNET_new (struct Operation); | 1195 | incoming = GNUNET_new (struct Operation); |
1200 | incoming->listener = listener; | 1196 | incoming->listener = listener; |
1201 | incoming->is_incoming = GNUNET_YES; | 1197 | incoming->is_incoming = GNUNET_YES; |
1202 | incoming->peer = *initiator; | 1198 | incoming->peer = *source; |
1203 | incoming->channel = channel; | 1199 | incoming->channel = channel; |
1204 | incoming->mq = GNUNET_CADET_mq_create (incoming->channel); | 1200 | incoming->mq = GNUNET_CADET_mq_create (incoming->channel); |
1205 | incoming->vt = &incoming_vt; | 1201 | incoming->vt = &incoming_vt; |
@@ -1217,6 +1213,127 @@ channel_new_cb (void *cls, | |||
1217 | 1213 | ||
1218 | 1214 | ||
1219 | /** | 1215 | /** |
1216 | * Function called whenever a channel is destroyed. Should clean up | ||
1217 | * any associated state. It must NOT call | ||
1218 | * GNUNET_CADET_channel_destroy() on the channel. | ||
1219 | * | ||
1220 | * The peer_disconnect function is part of a a virtual table set initially either | ||
1221 | * when a peer creates a new channel with us, or once we create | ||
1222 | * a new channel ourselves (evaluate). | ||
1223 | * | ||
1224 | * Once we know the exact type of operation (union/intersection), the vt is | ||
1225 | * replaced with an operation specific instance (_GSS_[op]_vt). | ||
1226 | * | ||
1227 | * @param channel_ctx place where local state associated | ||
1228 | * with the channel is stored | ||
1229 | * @param channel connection to the other end (henceforth invalid) | ||
1230 | */ | ||
1231 | static void | ||
1232 | channel_end_cb (void *channel_ctx, | ||
1233 | const struct GNUNET_CADET_Channel *channel) | ||
1234 | { | ||
1235 | struct Operation *op = channel_ctx; | ||
1236 | |||
1237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1238 | "channel_end_cb called\n"); | ||
1239 | op->channel = NULL; | ||
1240 | op->keep++; | ||
1241 | /* the vt can be null if a client already requested canceling op. */ | ||
1242 | if (NULL != op->vt) | ||
1243 | { | ||
1244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1245 | "calling peer disconnect due to channel end\n"); | ||
1246 | op->vt->peer_disconnect (op); | ||
1247 | } | ||
1248 | op->keep--; | ||
1249 | if (0 == op->keep) | ||
1250 | { | ||
1251 | /* cadet will never call us with the context again! */ | ||
1252 | GNUNET_free (op); | ||
1253 | } | ||
1254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1255 | "channel_end_cb finished\n"); | ||
1256 | } | ||
1257 | |||
1258 | |||
1259 | /** | ||
1260 | * Function called whenever an MQ-channel's transmission window size changes. | ||
1261 | * | ||
1262 | * The first callback in an outgoing channel will be with a non-zero value | ||
1263 | * and will mean the channel is connected to the destination. | ||
1264 | * | ||
1265 | * For an incoming channel it will be called immediately after the | ||
1266 | * #GNUNET_CADET_ConnectEventHandler, also with a non-zero value. | ||
1267 | * | ||
1268 | * @param cls Channel closure. | ||
1269 | * @param channel Connection to the other end (henceforth invalid). | ||
1270 | * @param window_size New window size. If the is more messages than buffer size | ||
1271 | * this value will be negative.. | ||
1272 | */ | ||
1273 | static void | ||
1274 | channel_window_cb (void *cls, | ||
1275 | const struct GNUNET_CADET_Channel *channel, | ||
1276 | int window_size) | ||
1277 | { | ||
1278 | /* FIXME: not implemented, we could do flow control here... */ | ||
1279 | } | ||
1280 | |||
1281 | /** | ||
1282 | * FIXME: hack-job. Migrate to proper handler array use! | ||
1283 | * | ||
1284 | * @param cls local state associated with the channel. | ||
1285 | * @param message The actual message. | ||
1286 | */ | ||
1287 | static int | ||
1288 | check_p2p_message (void *cls, | ||
1289 | const struct GNUNET_MessageHeader *message) | ||
1290 | { | ||
1291 | return GNUNET_OK; | ||
1292 | } | ||
1293 | |||
1294 | |||
1295 | /** | ||
1296 | * FIXME: hack-job. Migrate to proper handler array use! | ||
1297 | * | ||
1298 | * Functions with this signature are called whenever a message is | ||
1299 | * received via a cadet channel. | ||
1300 | * | ||
1301 | * The msg_handler is a virtual table set in initially either when a peer | ||
1302 | * creates a new channel with us, or once we create a new channel | ||
1303 | * ourselves (evaluate). | ||
1304 | * | ||
1305 | * Once we know the exact type of operation (union/intersection), the vt is | ||
1306 | * replaced with an operation specific instance (_GSS_[op]_vt). | ||
1307 | * | ||
1308 | * @param cls local state associated with the channel. | ||
1309 | * @param message The actual message. | ||
1310 | */ | ||
1311 | static void | ||
1312 | handle_p2p_message (void *cls, | ||
1313 | const struct GNUNET_MessageHeader *message) | ||
1314 | { | ||
1315 | struct Operation *op = cls; | ||
1316 | int ret; | ||
1317 | |||
1318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1319 | "Dispatching cadet message (type: %u)\n", | ||
1320 | ntohs (message->type)); | ||
1321 | /* do this before the handler, as the handler might kill the channel */ | ||
1322 | GNUNET_CADET_receive_done (op->channel); | ||
1323 | if (NULL != op->vt) | ||
1324 | ret = op->vt->msg_handler (op, | ||
1325 | message); | ||
1326 | else | ||
1327 | ret = GNUNET_SYSERR; | ||
1328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1329 | "Handled cadet message (type: %u)\n", | ||
1330 | ntohs (message->type)); | ||
1331 | if (GNUNET_OK != ret) | ||
1332 | GNUNET_CADET_channel_destroy (op->channel); | ||
1333 | } | ||
1334 | |||
1335 | |||
1336 | /** | ||
1220 | * Called when a client wants to create a new listener. | 1337 | * Called when a client wants to create a new listener. |
1221 | * | 1338 | * |
1222 | * @param cls client that sent the message | 1339 | * @param cls client that sent the message |
@@ -1227,6 +1344,57 @@ handle_client_listen (void *cls, | |||
1227 | const struct GNUNET_SET_ListenMessage *msg) | 1344 | const struct GNUNET_SET_ListenMessage *msg) |
1228 | { | 1345 | { |
1229 | struct GNUNET_SERVICE_Client *client = cls; | 1346 | struct GNUNET_SERVICE_Client *client = cls; |
1347 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | ||
1348 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1349 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | ||
1350 | struct GNUNET_MessageHeader, | ||
1351 | NULL), | ||
1352 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1353 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, | ||
1354 | struct GNUNET_MessageHeader, | ||
1355 | NULL), | ||
1356 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1357 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, | ||
1358 | struct GNUNET_MessageHeader, | ||
1359 | NULL), | ||
1360 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1361 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, | ||
1362 | struct GNUNET_MessageHeader, | ||
1363 | NULL), | ||
1364 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1365 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, | ||
1366 | struct GNUNET_MessageHeader, | ||
1367 | NULL), | ||
1368 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1369 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, | ||
1370 | struct GNUNET_MessageHeader, | ||
1371 | NULL), | ||
1372 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1373 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, | ||
1374 | struct GNUNET_MessageHeader, | ||
1375 | NULL), | ||
1376 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1377 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, | ||
1378 | struct GNUNET_MessageHeader, | ||
1379 | NULL), | ||
1380 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1381 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, | ||
1382 | struct GNUNET_MessageHeader, | ||
1383 | NULL), | ||
1384 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1385 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, | ||
1386 | struct GNUNET_MessageHeader, | ||
1387 | NULL), | ||
1388 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1389 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, | ||
1390 | struct GNUNET_MessageHeader, | ||
1391 | NULL), | ||
1392 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1393 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, | ||
1394 | struct GNUNET_MessageHeader, | ||
1395 | NULL), | ||
1396 | GNUNET_MQ_handler_end () | ||
1397 | }; | ||
1230 | struct Listener *listener; | 1398 | struct Listener *listener; |
1231 | struct Operation *op; | 1399 | struct Operation *op; |
1232 | 1400 | ||
@@ -1245,15 +1413,17 @@ handle_client_listen (void *cls, | |||
1245 | GNUNET_CONTAINER_DLL_insert_tail (listeners_head, | 1413 | GNUNET_CONTAINER_DLL_insert_tail (listeners_head, |
1246 | listeners_tail, | 1414 | listeners_tail, |
1247 | listener); | 1415 | listener); |
1248 | listener->open_port = GNUNET_CADET_open_port (cadet, | ||
1249 | &msg->app_id, | ||
1250 | &channel_new_cb, | ||
1251 | listener); | ||
1252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1253 | "New listener created (op %u, port %s)\n", | 1417 | "New listener created (op %u, port %s)\n", |
1254 | listener->operation, | 1418 | listener->operation, |
1255 | GNUNET_h2s (&listener->app_id)); | 1419 | GNUNET_h2s (&listener->app_id)); |
1256 | 1420 | listener->open_port = GNUNET_CADET_open_porT (cadet, | |
1421 | &msg->app_id, | ||
1422 | &channel_new_cb, | ||
1423 | listener, | ||
1424 | &channel_window_cb, | ||
1425 | &channel_end_cb, | ||
1426 | cadet_handlers); | ||
1257 | /* check for existing incoming requests the listener might be interested in */ | 1427 | /* check for existing incoming requests the listener might be interested in */ |
1258 | for (op = incoming_head; NULL != op; op = op->next) | 1428 | for (op = incoming_head; NULL != op; op = op->next) |
1259 | { | 1429 | { |
@@ -1428,15 +1598,67 @@ handle_client_evaluate (void *cls, | |||
1428 | const struct GNUNET_SET_EvaluateMessage *msg) | 1598 | const struct GNUNET_SET_EvaluateMessage *msg) |
1429 | { | 1599 | { |
1430 | struct GNUNET_SERVICE_Client *client = cls; | 1600 | struct GNUNET_SERVICE_Client *client = cls; |
1601 | struct Operation *op = GNUNET_new (struct Operation); | ||
1602 | const struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | ||
1603 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1604 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | ||
1605 | struct GNUNET_MessageHeader, | ||
1606 | op), | ||
1607 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1608 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, | ||
1609 | struct GNUNET_MessageHeader, | ||
1610 | op), | ||
1611 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1612 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, | ||
1613 | struct GNUNET_MessageHeader, | ||
1614 | op), | ||
1615 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1616 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, | ||
1617 | struct GNUNET_MessageHeader, | ||
1618 | op), | ||
1619 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1620 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, | ||
1621 | struct GNUNET_MessageHeader, | ||
1622 | op), | ||
1623 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1624 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, | ||
1625 | struct GNUNET_MessageHeader, | ||
1626 | op), | ||
1627 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1628 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, | ||
1629 | struct GNUNET_MessageHeader, | ||
1630 | op), | ||
1631 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1632 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, | ||
1633 | struct GNUNET_MessageHeader, | ||
1634 | op), | ||
1635 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1636 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, | ||
1637 | struct GNUNET_MessageHeader, | ||
1638 | op), | ||
1639 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1640 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, | ||
1641 | struct GNUNET_MessageHeader, | ||
1642 | op), | ||
1643 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1644 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, | ||
1645 | struct GNUNET_MessageHeader, | ||
1646 | op), | ||
1647 | GNUNET_MQ_hd_var_size (p2p_message, | ||
1648 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, | ||
1649 | struct GNUNET_MessageHeader, | ||
1650 | op), | ||
1651 | GNUNET_MQ_handler_end () | ||
1652 | }; | ||
1431 | struct Set *set; | 1653 | struct Set *set; |
1432 | struct OperationSpecification *spec; | 1654 | struct OperationSpecification *spec; |
1433 | struct Operation *op; | ||
1434 | const struct GNUNET_MessageHeader *context; | 1655 | const struct GNUNET_MessageHeader *context; |
1435 | 1656 | ||
1436 | set = set_get (client); | 1657 | set = set_get (client); |
1437 | if (NULL == set) | 1658 | if (NULL == set) |
1438 | { | 1659 | { |
1439 | GNUNET_break (0); | 1660 | GNUNET_break (0); |
1661 | GNUNET_free (op); | ||
1440 | GNUNET_SERVICE_client_drop (client); | 1662 | GNUNET_SERVICE_client_drop (client); |
1441 | return; | 1663 | return; |
1442 | } | 1664 | } |
@@ -1450,7 +1672,6 @@ handle_client_evaluate (void *cls, | |||
1450 | spec->result_mode = ntohl (msg->result_mode); | 1672 | spec->result_mode = ntohl (msg->result_mode); |
1451 | spec->client_request_id = ntohl (msg->request_id); | 1673 | spec->client_request_id = ntohl (msg->request_id); |
1452 | context = GNUNET_MQ_extract_nested_mh (msg); | 1674 | context = GNUNET_MQ_extract_nested_mh (msg); |
1453 | op = GNUNET_new (struct Operation); | ||
1454 | op->spec = spec; | 1675 | op->spec = spec; |
1455 | 1676 | ||
1456 | // Advance generation values, so that | 1677 | // Advance generation values, so that |
@@ -1465,11 +1686,14 @@ handle_client_evaluate (void *cls, | |||
1465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1466 | "Creating new CADET channel to port %s\n", | 1687 | "Creating new CADET channel to port %s\n", |
1467 | GNUNET_h2s (&msg->app_id)); | 1688 | GNUNET_h2s (&msg->app_id)); |
1468 | op->channel = GNUNET_CADET_channel_create (cadet, | 1689 | op->channel = GNUNET_CADET_channel_creatE (cadet, |
1469 | op, | 1690 | op, |
1470 | &msg->target_peer, | 1691 | &msg->target_peer, |
1471 | &msg->app_id, | 1692 | &msg->app_id, |
1472 | GNUNET_CADET_OPTION_RELIABLE); | 1693 | GNUNET_CADET_OPTION_RELIABLE, |
1694 | &channel_window_cb, | ||
1695 | &channel_end_cb, | ||
1696 | cadet_handlers); | ||
1473 | op->mq = GNUNET_CADET_mq_create (op->channel); | 1697 | op->mq = GNUNET_CADET_mq_create (op->channel); |
1474 | set->vt->evaluate (op, | 1698 | set->vt->evaluate (op, |
1475 | context); | 1699 | context); |
@@ -1824,96 +2048,6 @@ shutdown_task (void *cls) | |||
1824 | 2048 | ||
1825 | 2049 | ||
1826 | /** | 2050 | /** |
1827 | * Function called whenever a channel is destroyed. Should clean up | ||
1828 | * any associated state. It must NOT call | ||
1829 | * GNUNET_CADET_channel_destroy() on the channel. | ||
1830 | * | ||
1831 | * The peer_disconnect function is part of a a virtual table set initially either | ||
1832 | * when a peer creates a new channel with us, or once we create | ||
1833 | * a new channel ourselves (evaluate). | ||
1834 | * | ||
1835 | * Once we know the exact type of operation (union/intersection), the vt is | ||
1836 | * replaced with an operation specific instance (_GSS_[op]_vt). | ||
1837 | * | ||
1838 | * @param cls closure (set from GNUNET_CADET_connect()) | ||
1839 | * @param channel connection to the other end (henceforth invalid) | ||
1840 | * @param channel_ctx place where local state associated | ||
1841 | * with the channel is stored | ||
1842 | */ | ||
1843 | static void | ||
1844 | channel_end_cb (void *cls, | ||
1845 | const struct GNUNET_CADET_Channel *channel, | ||
1846 | void *channel_ctx) | ||
1847 | { | ||
1848 | struct Operation *op = channel_ctx; | ||
1849 | |||
1850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1851 | "channel_end_cb called\n"); | ||
1852 | op->channel = NULL; | ||
1853 | op->keep++; | ||
1854 | /* the vt can be null if a client already requested canceling op. */ | ||
1855 | if (NULL != op->vt) | ||
1856 | { | ||
1857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1858 | "calling peer disconnect due to channel end\n"); | ||
1859 | op->vt->peer_disconnect (op); | ||
1860 | } | ||
1861 | op->keep--; | ||
1862 | if (0 == op->keep) | ||
1863 | { | ||
1864 | /* cadet will never call us with the context again! */ | ||
1865 | GNUNET_free (op); | ||
1866 | } | ||
1867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1868 | "channel_end_cb finished\n"); | ||
1869 | } | ||
1870 | |||
1871 | |||
1872 | /** | ||
1873 | * Functions with this signature are called whenever a message is | ||
1874 | * received via a cadet channel. | ||
1875 | * | ||
1876 | * The msg_handler is a virtual table set in initially either when a peer | ||
1877 | * creates a new channel with us, or once we create a new channel | ||
1878 | * ourselves (evaluate). | ||
1879 | * | ||
1880 | * Once we know the exact type of operation (union/intersection), the vt is | ||
1881 | * replaced with an operation specific instance (_GSS_[op]_vt). | ||
1882 | * | ||
1883 | * @param cls Closure (set from GNUNET_CADET_connect()). | ||
1884 | * @param channel Connection to the other end. | ||
1885 | * @param channel_ctx Place to store local state associated with the channel. | ||
1886 | * @param message The actual message. | ||
1887 | * @return #GNUNET_OK to keep the channel open, | ||
1888 | * #GNUNET_SYSERR to close it (signal serious error). | ||
1889 | */ | ||
1890 | static int | ||
1891 | dispatch_p2p_message (void *cls, | ||
1892 | struct GNUNET_CADET_Channel *channel, | ||
1893 | void **channel_ctx, | ||
1894 | const struct GNUNET_MessageHeader *message) | ||
1895 | { | ||
1896 | struct Operation *op = *channel_ctx; | ||
1897 | int ret; | ||
1898 | |||
1899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1900 | "Dispatching cadet message (type: %u)\n", | ||
1901 | ntohs (message->type)); | ||
1902 | /* do this before the handler, as the handler might kill the channel */ | ||
1903 | GNUNET_CADET_receive_done (channel); | ||
1904 | if (NULL != op->vt) | ||
1905 | ret = op->vt->msg_handler (op, | ||
1906 | message); | ||
1907 | else | ||
1908 | ret = GNUNET_SYSERR; | ||
1909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1910 | "Handled cadet message (type: %u)\n", | ||
1911 | ntohs (message->type)); | ||
1912 | return ret; | ||
1913 | } | ||
1914 | |||
1915 | |||
1916 | /** | ||
1917 | * Function called by the service's run | 2051 | * Function called by the service's run |
1918 | * method to run service-specific setup code. | 2052 | * method to run service-specific setup code. |
1919 | * | 2053 | * |
@@ -1926,31 +2060,11 @@ run (void *cls, | |||
1926 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 2060 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1927 | struct GNUNET_SERVICE_Handle *service) | 2061 | struct GNUNET_SERVICE_Handle *service) |
1928 | { | 2062 | { |
1929 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | ||
1930 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0}, | ||
1931 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 0}, | ||
1932 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 0}, | ||
1933 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 0}, | ||
1934 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 0}, | ||
1935 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 0}, | ||
1936 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS, 0}, | ||
1937 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 0}, | ||
1938 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 0}, | ||
1939 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 0}, | ||
1940 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 0}, | ||
1941 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 0}, | ||
1942 | { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 0}, | ||
1943 | {NULL, 0, 0} | ||
1944 | }; | ||
1945 | |||
1946 | configuration = cfg; | 2063 | configuration = cfg; |
1947 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 2064 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1948 | NULL); | 2065 | NULL); |
1949 | _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg); | 2066 | _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg); |
1950 | cadet = GNUNET_CADET_connect (cfg, | 2067 | cadet = GNUNET_CADET_connecT (cfg); |
1951 | NULL, | ||
1952 | &channel_end_cb, | ||
1953 | cadet_handlers); | ||
1954 | if (NULL == cadet) | 2068 | if (NULL == cadet) |
1955 | { | 2069 | { |
1956 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2070 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |