diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-07 11:26:17 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-07 11:26:17 +0000 |
commit | e887c4f5ee3bc146ca003aedad709f73321c714b (patch) | |
tree | 7dd58102ebea3269d880aeb3805cd940d603241d /src/core/gnunet-service-core_typemap.c | |
parent | 7d018d2383fc9352a43fc38aaa8477be9b04be1d (diff) | |
download | gnunet-e887c4f5ee3bc146ca003aedad709f73321c714b.tar.gz gnunet-e887c4f5ee3bc146ca003aedad709f73321c714b.zip |
hxing typemap
Diffstat (limited to 'src/core/gnunet-service-core_typemap.c')
-rw-r--r-- | src/core/gnunet-service-core_typemap.c | 60 |
1 files changed, 45 insertions, 15 deletions
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 | |||
41 | uint32_t bits[(UINT16_MAX + 1) / 32]; | 41 | uint32_t bits[(UINT16_MAX + 1) / 32]; |
42 | }; | 42 | }; |
43 | 43 | ||
44 | |||
45 | /** | 44 | /** |
46 | * Bitmap of message types this peer is able to handle. | 45 | * Bitmap of message types this peer is able to handle. |
47 | */ | 46 | */ |
48 | static uint32_t my_type_map[(UINT16_MAX + 1) / 32]; | 47 | static struct GSC_TypeMap my_type_map; |
48 | |||
49 | /** | ||
50 | * Counters for message types this peer is able to handle. | ||
51 | */ | ||
52 | static uint8_t map_counters[UINT16_MAX + 1]; | ||
49 | 53 | ||
50 | 54 | ||
51 | /** | 55 | /** |
@@ -71,11 +75,11 @@ compute_type_map_message () | |||
71 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); | 75 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); |
72 | tmp = (char *) &hdr[1]; | 76 | tmp = (char *) &hdr[1]; |
73 | if ((Z_OK != | 77 | if ((Z_OK != |
74 | compress2 ((Bytef *) tmp, &dlen, (const Bytef *) my_type_map, | 78 | compress2 ((Bytef *) tmp, &dlen, (const Bytef *) &my_type_map, |
75 | sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map))) | 79 | sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map))) |
76 | { | 80 | { |
77 | dlen = sizeof (my_type_map); | 81 | dlen = sizeof (my_type_map); |
78 | memcpy (tmp, my_type_map, sizeof (my_type_map)); | 82 | memcpy (tmp, &my_type_map, sizeof (my_type_map)); |
79 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); | 83 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); |
80 | } | 84 | } |
81 | else | 85 | else |
@@ -95,7 +99,7 @@ broadcast_my_type_map () | |||
95 | struct GNUNET_MessageHeader *hdr; | 99 | struct GNUNET_MessageHeader *hdr; |
96 | 100 | ||
97 | hdr = compute_type_map_message (); | 101 | hdr = compute_type_map_message (); |
98 | GSC_SESSIONS_broadcast (hdr);x | 102 | GSC_SESSIONS_broadcast (hdr); |
99 | GNUNET_free (hdr); | 103 | GNUNET_free (hdr); |
100 | } | 104 | } |
101 | 105 | ||
@@ -108,10 +112,18 @@ GSC_TYPEMAP_add (const uint16_t *types, | |||
108 | unsigned int tlen) | 112 | unsigned int tlen) |
109 | { | 113 | { |
110 | unsigned int i; | 114 | unsigned int i; |
115 | int changed; | ||
111 | 116 | ||
117 | changed = GNUNET_NO; | ||
112 | for (i=0;i<tlen;i++) | 118 | for (i=0;i<tlen;i++) |
113 | my_type_map[types[i] / 32] |= (1 << (types[i] % 32)); | 119 | { |
114 | if (tlen > 0) | 120 | if (0 == map_counters[types[i]]++) |
121 | { | ||
122 | my_type_map.bits[types[i] / 32] |= (1 << (types[i] % 32)); | ||
123 | changed = GNUNET_YES; | ||
124 | } | ||
125 | } | ||
126 | if (GNUNET_YES == changed) | ||
115 | broadcast_my_type_map (); | 127 | broadcast_my_type_map (); |
116 | } | 128 | } |
117 | 129 | ||
@@ -123,15 +135,20 @@ void | |||
123 | GSC_TYPEMAP_remove (const uint16_t *types, | 135 | GSC_TYPEMAP_remove (const uint16_t *types, |
124 | unsigned int tlen) | 136 | unsigned int tlen) |
125 | { | 137 | { |
126 | /* rebuild my_type_map */ | 138 | unsigned int i; |
127 | memset (my_type_map, 0, sizeof (my_type_map)); | 139 | int changed; |
128 | for (pos = clients; NULL != pos; pos = pos->next) | 140 | |
141 | changed = GNUNET_NO; | ||
142 | for (i=0;i<tlen;i++) | ||
129 | { | 143 | { |
130 | wtypes = (const uint16_t *) &pos[1]; | 144 | if (0 == --map_counters[types[i]]) |
131 | for (i = 0; i < pos->tcnt; i++) | 145 | { |
132 | my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32)); | 146 | my_type_map.bits[types[i] / 32] &= ~(1 << (types[i] % 32)); |
147 | changed = GNUNET_YES; | ||
148 | } | ||
133 | } | 149 | } |
134 | broadcast_my_type_map (); | 150 | if (GNUNET_YES == changed) |
151 | broadcast_my_type_map (); | ||
135 | } | 152 | } |
136 | 153 | ||
137 | 154 | ||
@@ -149,19 +166,32 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, | |||
149 | const uint16_t *types, | 166 | const uint16_t *types, |
150 | unsigned int tcnt) | 167 | unsigned int tcnt) |
151 | { | 168 | { |
152 | return GNUNET_YES; /* FIXME */ | 169 | unsigned int i; |
170 | |||
171 | for (i=0;i<tcnt;i++) | ||
172 | if (0 != (my_type_map.bits[types[i] / 32] & (1 << (types[i] % 32)))) | ||
173 | return GNUNET_YES; | ||
174 | return GNUNET_NO; | ||
153 | } | 175 | } |
154 | 176 | ||
155 | 177 | ||
178 | /** | ||
179 | * Initialize typemap subsystem. | ||
180 | */ | ||
156 | void | 181 | void |
157 | GSC_TYPEMAP_init () | 182 | GSC_TYPEMAP_init () |
158 | { | 183 | { |
184 | /* nothing to do */ | ||
159 | } | 185 | } |
160 | 186 | ||
161 | 187 | ||
188 | /** | ||
189 | * Shutdown typemap subsystem. | ||
190 | */ | ||
162 | void | 191 | void |
163 | GSC_TYPEMAP_done () | 192 | GSC_TYPEMAP_done () |
164 | { | 193 | { |
194 | /* nothing to do */ | ||
165 | } | 195 | } |
166 | 196 | ||
167 | /* end of gnunet-service-core_typemap.c */ | 197 | /* end of gnunet-service-core_typemap.c */ |