aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-07-13 01:13:53 +0200
committerJulius Bünger <buenger@mytum.de>2018-07-13 01:16:01 +0200
commit330bb7242aed7c426cfdbb589155db5bb3fa83dc (patch)
treeefac24b2ecbad6b6ab5fc9f2faf1b35ea6304794 /src
parentf5164502be55aa48ea4c3b44167e19ac15ba53af (diff)
downloadgnunet-330bb7242aed7c426cfdbb589155db5bb3fa83dc.tar.gz
gnunet-330bb7242aed7c426cfdbb589155db5bb3fa83dc.zip
restructure rps service: start keeping track of channels
Diffstat (limited to 'src')
-rw-r--r--src/rps/gnunet-service-rps.c55
1 files changed, 47 insertions, 8 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index aef6a72de..c60ab5e63 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -265,6 +265,34 @@ struct PeersIteratorCls
265}; 265};
266 266
267/** 267/**
268 * @brief Context for a channel
269 */
270struct ChannelCtx
271{
272 /**
273 * @brief Meant to be used in a DLL
274 */
275 struct ChannelCtx *next;
276 struct ChannelCtx *prev;
277
278 /**
279 * @brief The channel itself
280 */
281 struct GNUNET_CADET_Channel *channel;
282
283 /**
284 * @brief The peer context associated with the channel
285 */
286 struct PeerContext *peer_ctx;
287};
288
289/**
290 * @brief The DLL of channel contexts
291 */
292static struct ChannelCtx *channel_ctx_head;
293static struct ChannelCtx *channel_ctx_tail;
294
295/**
268 * @brief Hashmap of valid peers. 296 * @brief Hashmap of valid peers.
269 */ 297 */
270static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; 298static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers;
@@ -1521,6 +1549,7 @@ Peers_handle_inbound_channel (void *cls,
1521{ 1549{
1522 struct PeerContext *peer_ctx; 1550 struct PeerContext *peer_ctx;
1523 struct GNUNET_PeerIdentity *ctx_peer; 1551 struct GNUNET_PeerIdentity *ctx_peer;
1552 struct ChannelCtx *channel_ctx;
1524 1553
1525 LOG (GNUNET_ERROR_TYPE_DEBUG, 1554 LOG (GNUNET_ERROR_TYPE_DEBUG,
1526 "New channel was established to us (Peer %s).\n", 1555 "New channel was established to us (Peer %s).\n",
@@ -1531,6 +1560,10 @@ Peers_handle_inbound_channel (void *cls,
1531 set_peer_live (peer_ctx); 1560 set_peer_live (peer_ctx);
1532 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); 1561 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity);
1533 *ctx_peer = *initiator; 1562 *ctx_peer = *initiator;
1563 channel_ctx = GNUNET_new (struct ChannelCtx);
1564 channel_ctx->peer_ctx = peer_ctx;
1565 channel_ctx->channel = channel;
1566 GNUNET_CONTAINER_DLL_insert (channel_ctx_head, channel_ctx_tail, channel_ctx);
1534 /* We only accept one incoming channel per peer */ 1567 /* We only accept one incoming channel per peer */
1535 if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) 1568 if (GNUNET_YES == Peers_check_peer_send_intention (initiator))
1536 { 1569 {
@@ -1543,10 +1576,10 @@ Peers_handle_inbound_channel (void *cls,
1543 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); 1576 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
1544 peer_ctx->recv_channel = channel; 1577 peer_ctx->recv_channel = channel;
1545 /* return the channel context */ 1578 /* return the channel context */
1546 return ctx_peer; 1579 return channel_ctx;
1547 } 1580 }
1548 peer_ctx->recv_channel = channel; 1581 peer_ctx->recv_channel = channel;
1549 return ctx_peer; 1582 return channel_ctx;
1550} 1583}
1551 1584
1552 1585
@@ -1658,7 +1691,8 @@ void
1658Peers_cleanup_destroyed_channel (void *cls, 1691Peers_cleanup_destroyed_channel (void *cls,
1659 const struct GNUNET_CADET_Channel *channel) 1692 const struct GNUNET_CADET_Channel *channel)
1660{ 1693{
1661 struct GNUNET_PeerIdentity *peer = cls; 1694 struct ChannelCtx *channel_ctx = cls;
1695 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
1662 struct PeerContext *peer_ctx; 1696 struct PeerContext *peer_ctx;
1663 uint32_t *channel_flag; 1697 uint32_t *channel_flag;
1664 1698
@@ -2670,7 +2704,8 @@ static void
2670cleanup_destroyed_channel (void *cls, 2704cleanup_destroyed_channel (void *cls,
2671 const struct GNUNET_CADET_Channel *channel) 2705 const struct GNUNET_CADET_Channel *channel)
2672{ 2706{
2673 struct GNUNET_PeerIdentity *peer = cls; 2707 struct ChannelCtx *channel_ctx = cls; // FIXME: free this context!
2708 struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
2674 uint32_t *channel_flag; 2709 uint32_t *channel_flag;
2675 struct PeerContext *peer_ctx; 2710 struct PeerContext *peer_ctx;
2676 2711
@@ -3163,7 +3198,8 @@ static void
3163handle_peer_check (void *cls, 3198handle_peer_check (void *cls,
3164 const struct GNUNET_MessageHeader *msg) 3199 const struct GNUNET_MessageHeader *msg)
3165{ 3200{
3166 const struct GNUNET_PeerIdentity *peer = cls; 3201 const struct ChannelCtx *channel_ctx = cls;
3202 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3167 LOG (GNUNET_ERROR_TYPE_DEBUG, 3203 LOG (GNUNET_ERROR_TYPE_DEBUG,
3168 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); 3204 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer));
3169 3205
@@ -3183,7 +3219,8 @@ static void
3183handle_peer_push (void *cls, 3219handle_peer_push (void *cls,
3184 const struct GNUNET_MessageHeader *msg) 3220 const struct GNUNET_MessageHeader *msg)
3185{ 3221{
3186 const struct GNUNET_PeerIdentity *peer = cls; 3222 const struct ChannelCtx *channel_ctx = cls;
3223 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3187 3224
3188 // (check the proof of work (?)) 3225 // (check the proof of work (?))
3189 3226
@@ -3244,7 +3281,8 @@ static void
3244handle_peer_pull_request (void *cls, 3281handle_peer_pull_request (void *cls,
3245 const struct GNUNET_MessageHeader *msg) 3282 const struct GNUNET_MessageHeader *msg)
3246{ 3283{
3247 struct GNUNET_PeerIdentity *peer = cls; 3284 const struct ChannelCtx *channel_ctx = cls;
3285 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3248 const struct GNUNET_PeerIdentity *view_array; 3286 const struct GNUNET_PeerIdentity *view_array;
3249 3287
3250 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); 3288 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer));
@@ -3324,8 +3362,9 @@ static void
3324handle_peer_pull_reply (void *cls, 3362handle_peer_pull_reply (void *cls,
3325 const struct GNUNET_RPS_P2P_PullReplyMessage *msg) 3363 const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
3326{ 3364{
3365 const struct ChannelCtx *channel_ctx = cls;
3366 const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id;
3327 const struct GNUNET_PeerIdentity *peers; 3367 const struct GNUNET_PeerIdentity *peers;
3328 struct GNUNET_PeerIdentity *sender = cls;
3329 uint32_t i; 3368 uint32_t i;
3330#ifdef ENABLE_MALICIOUS 3369#ifdef ENABLE_MALICIOUS
3331 struct AttackedPeer *tmp_att_peer; 3370 struct AttackedPeer *tmp_att_peer;