aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_typemap.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/core/gnunet-service-core_typemap.c
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/core/gnunet-service-core_typemap.c')
-rw-r--r--src/core/gnunet-service-core_typemap.c60
1 files changed, 25 insertions, 35 deletions
diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c
index c54e446c6..d3214ea67 100644
--- a/src/core/gnunet-service-core_typemap.c
+++ b/src/core/gnunet-service-core_typemap.c
@@ -36,7 +36,7 @@
36 * A type map describing which messages a given neighbour is able 36 * A type map describing which messages a given neighbour is able
37 * to process. 37 * to process.
38 */ 38 */
39struct GSC_TypeMap 39struct GSC_TypeMap
40{ 40{
41 uint32_t bits[(UINT16_MAX + 1) / 32]; 41 uint32_t bits[(UINT16_MAX + 1) / 32];
42}; 42};
@@ -107,10 +107,8 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
107 switch (ntohs (msg->type)) 107 switch (ntohs (msg->type))
108 { 108 {
109 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: 109 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
110 GNUNET_STATISTICS_update (GSC_stats, 110 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
111 gettext_noop ("# type maps received"), 111 1, GNUNET_NO);
112 1,
113 GNUNET_NO);
114 if (size != sizeof (struct GSC_TypeMap)) 112 if (size != sizeof (struct GSC_TypeMap))
115 { 113 {
116 GNUNET_break_op (0); 114 GNUNET_break_op (0);
@@ -120,16 +118,13 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
120 memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap)); 118 memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap));
121 return ret; 119 return ret;
122 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: 120 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
123 GNUNET_STATISTICS_update (GSC_stats, 121 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
124 gettext_noop ("# type maps received"), 122 1, GNUNET_NO);
125 1,
126 GNUNET_NO);
127 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); 123 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
128 dlen = sizeof (struct GSC_TypeMap); 124 dlen = sizeof (struct GSC_TypeMap);
129 if ( (Z_OK != 125 if ((Z_OK !=
130 uncompress ((Bytef*) ret, &dlen, 126 uncompress ((Bytef *) ret, &dlen, (const Bytef *) &msg[1],
131 (const Bytef*) &msg[1], (uLong) size)) || 127 (uLong) size)) || (dlen != sizeof (struct GSC_TypeMap)))
132 (dlen != sizeof (struct GSC_TypeMap) ) )
133 { 128 {
134 GNUNET_break_op (0); 129 GNUNET_break_op (0);
135 GNUNET_free (ret); 130 GNUNET_free (ret);
@@ -152,10 +147,9 @@ broadcast_my_type_map ()
152 struct GNUNET_MessageHeader *hdr; 147 struct GNUNET_MessageHeader *hdr;
153 148
154 hdr = GSC_TYPEMAP_compute_type_map_message (); 149 hdr = GSC_TYPEMAP_compute_type_map_message ();
155 GNUNET_STATISTICS_update (GSC_stats, 150 GNUNET_STATISTICS_update (GSC_stats,
156 gettext_noop ("# updates to my type map"), 151 gettext_noop ("# updates to my type map"), 1,
157 1, 152 GNUNET_NO);
158 GNUNET_NO);
159 GSC_SESSIONS_broadcast (hdr); 153 GSC_SESSIONS_broadcast (hdr);
160 GNUNET_free (hdr); 154 GNUNET_free (hdr);
161} 155}
@@ -165,14 +159,13 @@ broadcast_my_type_map ()
165 * Add a set of types to our type map. 159 * Add a set of types to our type map.
166 */ 160 */
167void 161void
168GSC_TYPEMAP_add (const uint16_t *types, 162GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen)
169 unsigned int tlen)
170{ 163{
171 unsigned int i; 164 unsigned int i;
172 int changed; 165 int changed;
173 166
174 changed = GNUNET_NO; 167 changed = GNUNET_NO;
175 for (i=0;i<tlen;i++) 168 for (i = 0; i < tlen; i++)
176 { 169 {
177 if (0 == map_counters[types[i]]++) 170 if (0 == map_counters[types[i]]++)
178 { 171 {
@@ -189,14 +182,13 @@ GSC_TYPEMAP_add (const uint16_t *types,
189 * Remove a set of types from our type map. 182 * Remove a set of types from our type map.
190 */ 183 */
191void 184void
192GSC_TYPEMAP_remove (const uint16_t *types, 185GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen)
193 unsigned int tlen)
194{ 186{
195 unsigned int i; 187 unsigned int i;
196 int changed; 188 int changed;
197 189
198 changed = GNUNET_NO; 190 changed = GNUNET_NO;
199 for (i=0;i<tlen;i++) 191 for (i = 0; i < tlen; i++)
200 { 192 {
201 if (0 == --map_counters[types[i]]) 193 if (0 == --map_counters[types[i]])
202 { 194 {
@@ -217,19 +209,18 @@ GSC_TYPEMAP_remove (const uint16_t *types,
217 * @param types array of types 209 * @param types array of types
218 * @param tcnt number of entries in types 210 * @param tcnt number of entries in types
219 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not 211 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not
220 */ 212 */
221int 213int
222GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, 214GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types,
223 const uint16_t *types, 215 unsigned int tcnt)
224 unsigned int tcnt) 216{
225{
226 unsigned int i; 217 unsigned int i;
227 218
228 if (NULL == tmap) 219 if (NULL == tmap)
229 return GNUNET_NO; 220 return GNUNET_NO;
230 if (0 == tcnt) 221 if (0 == tcnt)
231 return GNUNET_YES; /* matches all */ 222 return GNUNET_YES; /* matches all */
232 for (i=0;i<tcnt;i++) 223 for (i = 0; i < tcnt; i++)
233 if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32)))) 224 if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32))))
234 return GNUNET_YES; 225 return GNUNET_YES;
235 return GNUNET_NO; 226 return GNUNET_NO;
@@ -243,11 +234,10 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
243 * @param types array of types to add 234 * @param types array of types to add
244 * @param tcnt number of entries in types 235 * @param tcnt number of entries in types
245 * @return updated type map (fresh copy) 236 * @return updated type map (fresh copy)
246 */ 237 */
247struct GSC_TypeMap * 238struct GSC_TypeMap *
248GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, 239GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types,
249 const uint16_t *types, 240 unsigned int tcnt)
250 unsigned int tcnt)
251{ 241{
252 struct GSC_TypeMap *ret; 242 struct GSC_TypeMap *ret;
253 unsigned int i; 243 unsigned int i;
@@ -255,7 +245,7 @@ GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
255 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); 245 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
256 if (NULL != tmap) 246 if (NULL != tmap)
257 memcpy (ret, tmap, sizeof (struct GSC_TypeMap)); 247 memcpy (ret, tmap, sizeof (struct GSC_TypeMap));
258 for (i=0;i<tcnt;i++) 248 for (i = 0; i < tcnt; i++)
259 ret->bits[types[i] / 32] |= (1 << (types[i] % 32)); 249 ret->bits[types[i] / 32] |= (1 << (types[i] % 32));
260 return ret; 250 return ret;
261} 251}