diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-25 14:41:39 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-25 14:41:39 +0100 |
commit | 5754136c4ab97de7360b2d1d5120c32f2b3b7926 (patch) | |
tree | e383017145a00a0891d462cd3831da2b3233a532 /src/cadet/gnunet-service-cadet-new_channel.c | |
parent | 4195db9b1f8461e2dddb377ec7abd2e442f96b9d (diff) | |
download | gnunet-5754136c4ab97de7360b2d1d5120c32f2b3b7926.tar.gz gnunet-5754136c4ab97de7360b2d1d5120c32f2b3b7926.zip |
use new generic insertion sort logic
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_channel.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet-new_channel.c | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c index 0c6241817..b681dfedc 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.c +++ b/src/cadet/gnunet-service-cadet-new_channel.c | |||
@@ -842,10 +842,12 @@ send_ack_to_client (struct CadetChannel *ch, | |||
842 | ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest; | 842 | ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest; |
843 | ack->ccn = ccc->ccn; | 843 | ack->ccn = ccc->ccn; |
844 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 844 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
845 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X\n", | 845 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", |
846 | GSC_2s (ccc->c), | 846 | GSC_2s (ccc->c), |
847 | (GNUNET_YES == to_owner) ? "owner" : "dest", | 847 | (GNUNET_YES == to_owner) ? "owner" : "dest", |
848 | ntohl (ack->ccn.channel_of_client)); | 848 | ntohl (ack->ccn.channel_of_client), |
849 | ch->pending_messages, | ||
850 | ch->max_pending_messages); | ||
849 | GSC_send_to_client (ccc->c, | 851 | GSC_send_to_client (ccc->c, |
850 | env); | 852 | env); |
851 | } | 853 | } |
@@ -1047,23 +1049,35 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch) | |||
1047 | */ | 1049 | */ |
1048 | static int | 1050 | static int |
1049 | is_before (void *cls, | 1051 | is_before (void *cls, |
1050 | void *e1, | 1052 | struct CadetOutOfOrderMessage *m1, |
1051 | void *e2) | 1053 | struct CadetOutOfOrderMessage *m2) |
1052 | { | 1054 | { |
1053 | struct CadetOutOfOrderMessage *m1 = e1; | ||
1054 | struct CadetOutOfOrderMessage *m2 = e2; | ||
1055 | uint32_t v1 = ntohl (m1->mid.mid); | 1055 | uint32_t v1 = ntohl (m1->mid.mid); |
1056 | uint32_t v2 = ntohl (m2->mid.mid); | 1056 | uint32_t v2 = ntohl (m2->mid.mid); |
1057 | uint32_t delta; | 1057 | uint32_t delta; |
1058 | 1058 | ||
1059 | delta = v1 - v2; | 1059 | delta = v2 - v1; |
1060 | GNUNET_assert (0 != delta); | ||
1060 | if (delta > (uint32_t) INT_MAX) | 1061 | if (delta > (uint32_t) INT_MAX) |
1061 | { | 1062 | { |
1062 | /* in overflow range, we can safely assume we wrapped around */ | 1063 | /* in overflow range, we can safely assume we wrapped around */ |
1064 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1065 | "%u > %u => %p > %p\n", | ||
1066 | (unsigned int) v1, | ||
1067 | (unsigned int) v2, | ||
1068 | m1, | ||
1069 | m2); | ||
1063 | return GNUNET_NO; | 1070 | return GNUNET_NO; |
1064 | } | 1071 | } |
1065 | else | 1072 | else |
1066 | { | 1073 | { |
1074 | /* result is small, thus v2 > v1, thus e1 < e2 */ | ||
1075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1076 | "%u < %u => %p < %p\n", | ||
1077 | (unsigned int) v1, | ||
1078 | (unsigned int) v2, | ||
1079 | m1, | ||
1080 | m2); | ||
1067 | return GNUNET_YES; | 1081 | return GNUNET_YES; |
1068 | } | 1082 | } |
1069 | } | 1083 | } |
@@ -1129,6 +1143,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1129 | { | 1143 | { |
1130 | /* FIXME-SECURITY: if the element is WAY too far ahead, | 1144 | /* FIXME-SECURITY: if the element is WAY too far ahead, |
1131 | drop it (can't buffer too much!) */ | 1145 | drop it (can't buffer too much!) */ |
1146 | /* FIXME-SECURITY: if element is a BIT in the past and/or | ||
1147 | duplicate, just drop it! */ | ||
1132 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1148 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1133 | "Queuing %s payload of %u bytes on %s (mid %u, need %u first)\n", | 1149 | "Queuing %s payload of %u bytes on %s (mid %u, need %u first)\n", |
1134 | (GNUNET_YES == ccc->client_ready) | 1150 | (GNUNET_YES == ccc->client_ready) |
@@ -1142,40 +1158,13 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1142 | com = GNUNET_new (struct CadetOutOfOrderMessage); | 1158 | com = GNUNET_new (struct CadetOutOfOrderMessage); |
1143 | com->mid = msg->mid; | 1159 | com->mid = msg->mid; |
1144 | com->env = env; | 1160 | com->env = env; |
1145 | /* sort into list ordered by "is_before" */ | 1161 | |
1146 | if ( (NULL == ccc->head_recv) || | 1162 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetOutOfOrderMessage, |
1147 | (GNUNET_YES == is_before (ch, | 1163 | is_before, |
1148 | com, | 1164 | NULL, |
1149 | ccc->head_recv)) ) | 1165 | ccc->head_recv, |
1150 | { | 1166 | ccc->tail_recv, |
1151 | GNUNET_CONTAINER_DLL_insert (ccc->head_recv, | 1167 | com); |
1152 | ccc->tail_recv, | ||
1153 | com); | ||
1154 | } | ||
1155 | else | ||
1156 | { | ||
1157 | struct CadetOutOfOrderMessage *pos; | ||
1158 | |||
1159 | for (pos = ccc->head_recv; | ||
1160 | NULL != pos; | ||
1161 | pos = pos->next) | ||
1162 | { | ||
1163 | if (GNUNET_YES != | ||
1164 | is_before (NULL, | ||
1165 | pos, | ||
1166 | com)) | ||
1167 | break; | ||
1168 | } | ||
1169 | if (NULL == pos) | ||
1170 | GNUNET_CONTAINER_DLL_insert_tail (ccc->head_recv, | ||
1171 | ccc->tail_recv, | ||
1172 | com); | ||
1173 | else | ||
1174 | GNUNET_CONTAINER_DLL_insert_after (ccc->head_recv, | ||
1175 | ccc->tail_recv, | ||
1176 | com, | ||
1177 | pos->prev); | ||
1178 | } | ||
1179 | } | 1168 | } |
1180 | } | 1169 | } |
1181 | 1170 | ||
@@ -1509,7 +1498,15 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
1509 | } | 1498 | } |
1510 | if ( (com->mid.mid != ch->mid_recv.mid) && | 1499 | if ( (com->mid.mid != ch->mid_recv.mid) && |
1511 | (GNUNET_NO == ch->out_of_order) ) | 1500 | (GNUNET_NO == ch->out_of_order) ) |
1501 | { | ||
1502 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1503 | "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", | ||
1504 | GSC_2s (ccc->c), | ||
1505 | ntohl (ccc->ccn.channel_of_client), | ||
1506 | ntohl (com->mid.mid), | ||
1507 | ntohl (ch->mid_recv.mid)); | ||
1512 | return; /* missing next one in-order */ | 1508 | return; /* missing next one in-order */ |
1509 | } | ||
1513 | 1510 | ||
1514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1511 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1515 | "Got LOCAL ACK, passing payload message to %s-%X on %s\n", | 1512 | "Got LOCAL ACK, passing payload message to %s-%X on %s\n", |