diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-23 01:05:11 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-23 01:05:11 +0000 |
commit | 551d39765954e420daa93c87263a25802e8f9ef0 (patch) | |
tree | 9278c9270a61747757f5b4eeec6989564e934d85 | |
parent | 434337b0f0c80a86c88daee571291b7f6d194563 (diff) | |
download | gnunet-551d39765954e420daa93c87263a25802e8f9ef0.tar.gz gnunet-551d39765954e420daa93c87263a25802e8f9ef0.zip |
mostly taking care about max size we are allowed to send
-rw-r--r-- | src/rps/gnunet-service-rps.c | 40 | ||||
-rw-r--r-- | src/rps/rps_api.c | 2 |
2 files changed, 37 insertions, 5 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 6bad9cd2f..937eee17f 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -714,7 +714,7 @@ resize_wrapper () | |||
714 | else | 714 | else |
715 | bigger_size = sampler_size_est_need; | 715 | bigger_size = sampler_size_est_need; |
716 | 716 | ||
717 | // TODO respect the request rate, min, max | 717 | // TODO respect the min, max |
718 | if (sampler_size > bigger_size*4) | 718 | if (sampler_size > bigger_size*4) |
719 | { /* Shrinking */ | 719 | { /* Shrinking */ |
720 | RPS_sampler_resize (sampler_size/2); | 720 | RPS_sampler_resize (sampler_size/2); |
@@ -813,10 +813,16 @@ void client_respond (void *cls, | |||
813 | struct GNUNET_MQ_Envelope *ev; | 813 | struct GNUNET_MQ_Envelope *ev; |
814 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; | 814 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; |
815 | struct GNUNET_SERVER_Client *client; | 815 | struct GNUNET_SERVER_Client *client; |
816 | uint32_t size_needed; | ||
816 | struct client_ctx *cli_ctx; | 817 | struct client_ctx *cli_ctx; |
817 | 818 | ||
818 | client = (struct GNUNET_SERVER_Client *) cls; | 819 | client = (struct GNUNET_SERVER_Client *) cls; |
819 | 820 | ||
821 | size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) + | ||
822 | num_peers * sizeof (struct GNUNET_PeerIdentity); | ||
823 | |||
824 | GNUNET_assert (GNUNET_SERVER_MAX_MESSAGE_SIZE >= size_needed); | ||
825 | |||
820 | ev = GNUNET_MQ_msg_extra (out_msg, | 826 | ev = GNUNET_MQ_msg_extra (out_msg, |
821 | num_peers * sizeof (struct GNUNET_PeerIdentity), | 827 | num_peers * sizeof (struct GNUNET_PeerIdentity), |
822 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY); | 828 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY); |
@@ -852,11 +858,20 @@ handle_client_request (void *cls, | |||
852 | { | 858 | { |
853 | struct GNUNET_RPS_CS_RequestMessage *msg; | 859 | struct GNUNET_RPS_CS_RequestMessage *msg; |
854 | uint32_t num_peers; | 860 | uint32_t num_peers; |
861 | uint32_t size_needed; | ||
855 | uint32_t i; | 862 | uint32_t i; |
856 | 863 | ||
857 | msg = (struct GNUNET_RPS_CS_RequestMessage *) message; | 864 | msg = (struct GNUNET_RPS_CS_RequestMessage *) message; |
858 | 865 | ||
859 | num_peers = ntohl (msg->num_peers); | 866 | num_peers = ntohl (msg->num_peers); |
867 | size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) + | ||
868 | num_peers * sizeof (struct GNUNET_PeerIdentity); | ||
869 | |||
870 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed) | ||
871 | { | ||
872 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
873 | return; | ||
874 | } | ||
860 | 875 | ||
861 | for (i = 0 ; i < num_peers ; i++) | 876 | for (i = 0 ; i < num_peers ; i++) |
862 | est_request_rate(); | 877 | est_request_rate(); |
@@ -961,6 +976,7 @@ handle_peer_pull_request (void *cls, | |||
961 | const struct GNUNET_MessageHeader *msg) | 976 | const struct GNUNET_MessageHeader *msg) |
962 | { | 977 | { |
963 | struct GNUNET_PeerIdentity *peer; | 978 | struct GNUNET_PeerIdentity *peer; |
979 | uint32_t send_size; | ||
964 | struct GNUNET_MQ_Handle *mq; | 980 | struct GNUNET_MQ_Handle *mq; |
965 | struct GNUNET_MQ_Envelope *ev; | 981 | struct GNUNET_MQ_Envelope *ev; |
966 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; | 982 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; |
@@ -969,19 +985,33 @@ handle_peer_pull_request (void *cls, | |||
969 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, | 985 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, |
970 | GNUNET_CADET_OPTION_PEER); | 986 | GNUNET_CADET_OPTION_PEER); |
971 | // FIXME wait for cadet to change this function | 987 | // FIXME wait for cadet to change this function |
988 | |||
989 | /* Compute actual size */ | ||
990 | send_size = sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) + | ||
991 | gossip_list_size * sizeof (struct GNUNET_PeerIdentity); | ||
992 | |||
993 | if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) | ||
994 | /* Compute number of peers to send | ||
995 | * If too long, simply truncate */ | ||
996 | send_size = (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - | ||
997 | sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | ||
998 | sizeof (struct GNUNET_PeerIdentity); | ||
999 | else | ||
1000 | send_size = gossip_list_size; | ||
1001 | |||
972 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1002 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
973 | "PULL REQUEST from peer %s received, going to send %u peers\n", | 1003 | "PULL REQUEST from peer %s received, going to send %u peers\n", |
974 | GNUNET_i2s (peer), gossip_list_size); | 1004 | GNUNET_i2s (peer), send_size); |
975 | 1005 | ||
976 | mq = get_mq (peer_map, peer); | 1006 | mq = get_mq (peer_map, peer); |
977 | 1007 | ||
978 | ev = GNUNET_MQ_msg_extra (out_msg, | 1008 | ev = GNUNET_MQ_msg_extra (out_msg, |
979 | gossip_list_size * sizeof (struct GNUNET_PeerIdentity), | 1009 | send_size * sizeof (struct GNUNET_PeerIdentity), |
980 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); | 1010 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); |
981 | //out_msg->num_peers = htonl (gossip_list_size); | 1011 | //out_msg->num_peers = htonl (gossip_list_size); |
982 | out_msg->num_peers = htonl (gossip_list_size); | 1012 | out_msg->num_peers = htonl (send_size); |
983 | memcpy (&out_msg[1], gossip_list, | 1013 | memcpy (&out_msg[1], gossip_list, |
984 | gossip_list_size * sizeof (struct GNUNET_PeerIdentity)); | 1014 | send_size * sizeof (struct GNUNET_PeerIdentity)); |
985 | 1015 | ||
986 | GNUNET_MQ_send (mq, ev); | 1016 | GNUNET_MQ_send (mq, ev); |
987 | 1017 | ||
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 2d9cc460a..13f488351 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -231,6 +231,8 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint64_t n, | |||
231 | struct GNUNET_MQ_Envelope *ev; | 231 | struct GNUNET_MQ_Envelope *ev; |
232 | struct GNUNET_RPS_CS_SeedMessage *msg; | 232 | struct GNUNET_RPS_CS_SeedMessage *msg; |
233 | 233 | ||
234 | // FIXME was not able to find MAX size we are allowed to send | ||
235 | |||
234 | ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity), | 236 | ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity), |
235 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED); | 237 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED); |
236 | msg->num_peers = GNUNET_htonll (n); | 238 | msg->num_peers = GNUNET_htonll (n); |