3 * A type map describing which messages a given neighbour is able
8 uint32_t bits[(UINT16_MAX + 1) / 32];
13 * Bitmap of message types this peer is able to handle.
15 static uint32_t my_type_map[(UINT16_MAX + 1) / 32];
19 * Add a set of types to our type map.
22 GSC_TYPEMAP_add (const uint16_t *types,
28 my_type_map[types[i] / 32] |= (1 << (types[i] % 32));
30 broadcast_my_type_map ();
35 * Remove a set of types from our type map.
38 GSC_TYPEMAP_remove (const uint16_t *types,
41 /* rebuild my_type_map */
42 memset (my_type_map, 0, sizeof (my_type_map));
43 for (pos = clients; NULL != pos; pos = pos->next)
45 wtypes = (const uint16_t *) &pos[1];
46 for (i = 0; i < pos->tcnt; i++)
47 my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32));
49 broadcast_my_type_map ();
54 * Test if any of the types from the types array is in the
57 * @param map map to test
58 * @param types array of types
59 * @param tcnt number of entries in types
60 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not
63 GSC_TYPEMAP_test_match (struct GSC_TypeMap *tmap,
64 const uint16_t *types,
67 return GNUNET_YES; /* FIXME */
72 * Compute a type map message for this peer.
74 * @return this peers current type map message.
76 static struct GNUNET_MessageHeader *
77 compute_type_map_message ()
81 struct GNUNET_MessageHeader *hdr;
84 dlen = compressBound (sizeof (my_type_map));
86 dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20;
87 /* documentation says 100.1% oldSize + 12 bytes, but we
88 * should be able to overshoot by more to be safe */
90 hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
91 hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
92 tmp = (char *) &hdr[1];
94 compress2 ((Bytef *) tmp, &dlen, (const Bytef *) my_type_map,
95 sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map)))
97 dlen = sizeof (my_type_map);
98 memcpy (tmp, my_type_map, sizeof (my_type_map));
99 hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
103 hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
110 * Send a type map message to the neighbour.
112 * @param cls the type map message
113 * @param key neighbour's identity
114 * @param value 'struct Neighbour' of the target
115 * @return always GNUNET_OK
118 send_type_map_to_neighbour (void *cls, const GNUNET_HashCode * key, void *value)
120 struct GNUNET_MessageHeader *hdr = cls;
121 struct Neighbour *n = value;
122 struct MessageEntry *m;
127 size = ntohs (hdr->size);
128 m = GNUNET_malloc (sizeof (struct MessageEntry) + size);
129 memcpy (&m[1], hdr, size);
130 m->deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
131 m->slack_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
132 m->priority = UINT_MAX;
133 m->sender_status = n->status;
135 m->next = n->messages;
143 * Send my type map to all connected peers (it got changed).
146 broadcast_my_type_map ()
148 struct GNUNET_MessageHeader *hdr;
150 if (NULL == neighbours)
152 hdr = compute_type_map_message ();
153 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
154 &send_type_map_to_neighbour, hdr);