From e887c4f5ee3bc146ca003aedad709f73321c714b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 7 Oct 2011 11:26:17 +0000 Subject: [PATCH] hxing typemap --- src/core/gnunet-service-core_sessions.c | 17 ------- src/core/gnunet-service-core_typemap.c | 60 ++++++++++++++++++------- src/core/gnunet-service-core_typemap.h | 10 ++++- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c index 3f97532bd..e97954438 100644 --- a/src/core/gnunet-service-core_sessions.c +++ b/src/core/gnunet-service-core_sessions.c @@ -99,23 +99,6 @@ struct Session */ unsigned int ats_count; - /** - * Bit map indicating which of the 32 sequence numbers before the last - * were received (good for accepting out-of-order packets and - * estimating reliability of the connection) - */ - unsigned int last_packets_bitmap; - - /** - * last sequence number received on this connection (highest) - */ - uint32_t last_sequence_number_received; - - /** - * last sequence number transmitted - */ - uint32_t last_sequence_number_sent; - /** * Available bandwidth in for this peer (current target). */ diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c index 0ef9a6236..e52bc0a6e 100644 --- a/src/core/gnunet-service-core_typemap.c +++ b/src/core/gnunet-service-core_typemap.c @@ -41,11 +41,15 @@ struct GSC_TypeMap uint32_t bits[(UINT16_MAX + 1) / 32]; }; - /** * Bitmap of message types this peer is able to handle. */ -static uint32_t my_type_map[(UINT16_MAX + 1) / 32]; +static struct GSC_TypeMap my_type_map; + +/** + * Counters for message types this peer is able to handle. + */ +static uint8_t map_counters[UINT16_MAX + 1]; /** @@ -71,11 +75,11 @@ compute_type_map_message () hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); tmp = (char *) &hdr[1]; if ((Z_OK != - compress2 ((Bytef *) tmp, &dlen, (const Bytef *) my_type_map, + compress2 ((Bytef *) tmp, &dlen, (const Bytef *) &my_type_map, sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map))) { dlen = sizeof (my_type_map); - memcpy (tmp, my_type_map, sizeof (my_type_map)); + memcpy (tmp, &my_type_map, sizeof (my_type_map)); hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); } else @@ -95,7 +99,7 @@ broadcast_my_type_map () struct GNUNET_MessageHeader *hdr; hdr = compute_type_map_message (); - GSC_SESSIONS_broadcast (hdr);x + GSC_SESSIONS_broadcast (hdr); GNUNET_free (hdr); } @@ -108,10 +112,18 @@ GSC_TYPEMAP_add (const uint16_t *types, unsigned int tlen) { unsigned int i; + int changed; + changed = GNUNET_NO; for (i=0;i 0) + { + if (0 == map_counters[types[i]]++) + { + my_type_map.bits[types[i] / 32] |= (1 << (types[i] % 32)); + changed = GNUNET_YES; + } + } + if (GNUNET_YES == changed) broadcast_my_type_map (); } @@ -123,15 +135,20 @@ void GSC_TYPEMAP_remove (const uint16_t *types, unsigned int tlen) { - /* rebuild my_type_map */ - memset (my_type_map, 0, sizeof (my_type_map)); - for (pos = clients; NULL != pos; pos = pos->next) + unsigned int i; + int changed; + + changed = GNUNET_NO; + for (i=0;itcnt; i++) - my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32)); + if (0 == --map_counters[types[i]]) + { + my_type_map.bits[types[i] / 32] &= ~(1 << (types[i] % 32)); + changed = GNUNET_YES; + } } - broadcast_my_type_map (); + if (GNUNET_YES == changed) + broadcast_my_type_map (); } @@ -149,19 +166,32 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t *types, unsigned int tcnt) { - return GNUNET_YES; /* FIXME */ + unsigned int i; + + for (i=0;i