aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/gnunet-service-rps_peers.c')
-rw-r--r--src/rps/gnunet-service-rps_peers.c96
1 files changed, 76 insertions, 20 deletions
diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c
index e0b278bd0..58aa84ccf 100644
--- a/src/rps/gnunet-service-rps_peers.c
+++ b/src/rps/gnunet-service-rps_peers.c
@@ -251,6 +251,17 @@ static const struct GNUNET_PeerIdentity *own_identity;
251 */ 251 */
252static struct GNUNET_CADET_Handle *cadet_handle; 252static struct GNUNET_CADET_Handle *cadet_handle;
253 253
254/**
255 * @brief Disconnect handler
256 */
257static GNUNET_CADET_DisconnectEventHandler cleanup_destroyed_channel;
258
259/**
260 * @brief cadet handlers
261 */
262static const struct GNUNET_MQ_MessageHandler *cadet_handlers;
263
264
254 265
255/** 266/**
256 * @brief Get the #PeerContext associated with a peer 267 * @brief Get the #PeerContext associated with a peer
@@ -523,10 +534,13 @@ get_channel (const struct GNUNET_PeerIdentity *peer)
523 &port); 534 &port);
524 peer_ctx->send_channel = 535 peer_ctx->send_channel =
525 GNUNET_CADET_channel_create (cadet_handle, 536 GNUNET_CADET_channel_create (cadet_handle,
526 peer_ctx->send_channel_flags, /* context */ 537 (struct GNUNET_PeerIdentity *) peer, /* context */
527 peer, 538 peer,
528 &port, 539 &port,
529 GNUNET_CADET_OPTION_RELIABLE); 540 GNUNET_CADET_OPTION_RELIABLE,
541 NULL, /* WindowSize handler */
542 cleanup_destroyed_channel, /* Disconnect handler */
543 cadet_handlers);
530 } 544 }
531 GNUNET_assert (NULL != peer_ctx->send_channel); 545 GNUNET_assert (NULL != peer_ctx->send_channel);
532 return peer_ctx->send_channel; 546 return peer_ctx->send_channel;
@@ -552,7 +566,7 @@ get_mq (const struct GNUNET_PeerIdentity *peer)
552 if (NULL == peer_ctx->mq) 566 if (NULL == peer_ctx->mq)
553 { 567 {
554 (void) get_channel (peer); 568 (void) get_channel (peer);
555 peer_ctx->mq = GNUNET_CADET_mq_create (peer_ctx->send_channel); 569 peer_ctx->mq = GNUNET_CADET_get_mq (peer_ctx->send_channel);
556 } 570 }
557 return peer_ctx->mq; 571 return peer_ctx->mq;
558} 572}
@@ -649,9 +663,7 @@ remove_pending_message (struct PendingMessage *pending_msg)
649 GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head, 663 GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head,
650 peer_ctx->pending_messages_tail, 664 peer_ctx->pending_messages_tail,
651 pending_msg); 665 pending_msg);
652 /* FIXME We are not able to cancel messages as #GNUNET_CADET_mq_create () does 666 GNUNET_MQ_send_cancel (peer_ctx->pending_messages_head->ev);
653 * not set a #GNUNET_MQ_CancelImpl */
654 /* GNUNET_MQ_send_cancel (peer_ctx->pending_messages_head->ev); */
655 GNUNET_free (pending_msg); 667 GNUNET_free (pending_msg);
656} 668}
657 669
@@ -932,15 +944,21 @@ restore_valid_peers ()
932 * 944 *
933 * @param fn_valid_peers filename of the file used to store valid peer ids 945 * @param fn_valid_peers filename of the file used to store valid peer ids
934 * @param cadet_h cadet handle 946 * @param cadet_h cadet handle
947 * @param disconnect_handler Disconnect handler
948 * @param c_handlers cadet handlers
935 * @param own_id own peer identity 949 * @param own_id own peer identity
936 */ 950 */
937void 951void
938Peers_initialise (char* fn_valid_peers, 952Peers_initialise (char* fn_valid_peers,
939 struct GNUNET_CADET_Handle *cadet_h, 953 struct GNUNET_CADET_Handle *cadet_h,
954 GNUNET_CADET_DisconnectEventHandler disconnect_handler,
955 const struct GNUNET_MQ_MessageHandler *c_handlers,
940 const struct GNUNET_PeerIdentity *own_id) 956 const struct GNUNET_PeerIdentity *own_id)
941{ 957{
942 filename_valid_peers = GNUNET_strdup (fn_valid_peers); 958 filename_valid_peers = GNUNET_strdup (fn_valid_peers);
943 cadet_handle = cadet_h; 959 cadet_handle = cadet_h;
960 cleanup_destroyed_channel = disconnect_handler;
961 cadet_handlers = c_handlers;
944 own_identity = own_id; 962 own_identity = own_id;
945 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); 963 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
946 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); 964 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
@@ -1279,6 +1297,34 @@ Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags
1279 return check_channel_flag_set (channel_flags, flags); 1297 return check_channel_flag_set (channel_flags, flags);
1280} 1298}
1281 1299
1300/**
1301 * @brief Get the flags for the channel in @a role for @a peer.
1302 *
1303 * @param peer Peer to get the channel flags for.
1304 * @param role Role of channel to get flags for
1305 *
1306 * @return The flags.
1307 */
1308uint32_t *
1309Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
1310 enum Peers_ChannelRole role)
1311{
1312 const struct PeerContext *peer_ctx;
1313
1314 peer_ctx = get_peer_ctx (peer);
1315 if (Peers_CHANNEL_ROLE_SENDING == role)
1316 {
1317 return peer_ctx->send_channel_flags;
1318 }
1319 else if (Peers_CHANNEL_ROLE_RECEIVING == role)
1320 {
1321 return peer_ctx->recv_channel_flags;
1322 }
1323 else
1324 {
1325 GNUNET_assert (0);
1326 }
1327}
1282 1328
1283/** 1329/**
1284 * @brief Check whether we have information about the given peer. 1330 * @brief Check whether we have information about the given peer.
@@ -1358,8 +1404,6 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1358 * @param cls The closure 1404 * @param cls The closure
1359 * @param channel The channel the peer wants to establish 1405 * @param channel The channel the peer wants to establish
1360 * @param initiator The peer's peer ID 1406 * @param initiator The peer's peer ID
1361 * @param port The port the channel is being established over
1362 * @param options Further options
1363 * 1407 *
1364 * @return initial channel context for the channel 1408 * @return initial channel context for the channel
1365 * (can be NULL -- that's not an error) 1409 * (can be NULL -- that's not an error)
@@ -1367,9 +1411,7 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1367void * 1411void *
1368Peers_handle_inbound_channel (void *cls, 1412Peers_handle_inbound_channel (void *cls,
1369 struct GNUNET_CADET_Channel *channel, 1413 struct GNUNET_CADET_Channel *channel,
1370 const struct GNUNET_PeerIdentity *initiator, 1414 const struct GNUNET_PeerIdentity *initiator)
1371 const struct GNUNET_HashCode *port,
1372 enum GNUNET_CADET_ChannelOption options)
1373{ 1415{
1374 struct PeerContext *peer_ctx; 1416 struct PeerContext *peer_ctx;
1375 1417
@@ -1387,10 +1429,10 @@ Peers_handle_inbound_channel (void *cls,
1387 Peers_CHANNEL_ESTABLISHED_TWICE); 1429 Peers_CHANNEL_ESTABLISHED_TWICE);
1388 GNUNET_CADET_channel_destroy (channel); 1430 GNUNET_CADET_channel_destroy (channel);
1389 /* return the channel context */ 1431 /* return the channel context */
1390 return peer_ctx->recv_channel_flags; 1432 return &peer_ctx->peer_id;
1391 } 1433 }
1392 peer_ctx->recv_channel = channel; 1434 peer_ctx->recv_channel = channel;
1393 return peer_ctx->recv_channel_flags; 1435 return &peer_ctx->peer_id;
1394} 1436}
1395 1437
1396 1438
@@ -1500,16 +1542,11 @@ Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1500 */ 1542 */
1501void 1543void
1502Peers_cleanup_destroyed_channel (void *cls, 1544Peers_cleanup_destroyed_channel (void *cls,
1503 const struct GNUNET_CADET_Channel *channel, 1545 const struct GNUNET_CADET_Channel *channel)
1504 void *channel_ctx)
1505{ 1546{
1506 struct GNUNET_PeerIdentity *peer; 1547 struct GNUNET_PeerIdentity *peer = cls;
1507 struct PeerContext *peer_ctx; 1548 struct PeerContext *peer_ctx;
1508 1549
1509 peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (
1510 (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER);
1511 // FIXME wait for cadet to change this function
1512
1513 if (GNUNET_NO == Peers_check_peer_known (peer)) 1550 if (GNUNET_NO == Peers_check_peer_known (peer))
1514 {/* We don't want to implicitly create a context that we're about to kill */ 1551 {/* We don't want to implicitly create a context that we're about to kill */
1515 LOG (GNUNET_ERROR_TYPE_DEBUG, 1552 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1635,4 +1672,23 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
1635 return GNUNET_NO; 1672 return GNUNET_NO;
1636} 1673}
1637 1674
1675/**
1676 * @brief Get the recv_channel of @a peer.
1677 * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming
1678 * messages.
1679 *
1680 * @param peer The peer to get the recv_channel from.
1681 *
1682 * @return The recv_channel.
1683 */
1684struct GNUNET_CADET_Channel *
1685Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer)
1686{
1687 struct PeerContext *peer_ctx;
1688
1689 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1690 peer_ctx = get_peer_ctx (peer);
1691 return peer_ctx->recv_channel;
1692}
1693
1638/* end of gnunet-service-rps_peers.c */ 1694/* end of gnunet-service-rps_peers.c */