diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-11 08:56:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-11 08:56:00 +0000 |
commit | 8afe6f260b19f148398784a2a918006b91bb4096 (patch) | |
tree | 6cd8160e8e0a183d4071d75abcbbde90b4d532f1 | |
parent | 1f0797c47af2a197b05ac640ce17adc86982d3c0 (diff) | |
download | gnunet-8afe6f260b19f148398784a2a918006b91bb4096.tar.gz gnunet-8afe6f260b19f148398784a2a918006b91bb4096.zip |
process inbound type map messages:
-rw-r--r-- | src/core/gnunet-service-core_clients.c | 7 | ||||
-rw-r--r-- | src/core/gnunet-service-core_clients.h | 4 | ||||
-rw-r--r-- | src/core/gnunet-service-core_kx.c | 29 | ||||
-rw-r--r-- | src/core/gnunet-service-core_sessions.c | 67 | ||||
-rw-r--r-- | src/core/gnunet-service-core_sessions.h | 24 | ||||
-rw-r--r-- | src/core/gnunet-service-core_typemap.c | 86 | ||||
-rw-r--r-- | src/core/gnunet-service-core_typemap.h | 33 |
7 files changed, 232 insertions, 18 deletions
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c index 0b1616c97..9b442bf30 100644 --- a/src/core/gnunet-service-core_clients.c +++ b/src/core/gnunet-service-core_clients.c | |||
@@ -578,7 +578,7 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) | |||
578 | * @param tmap_new updated type map for the neighbour, NULL for disconnect | 578 | * @param tmap_new updated type map for the neighbour, NULL for disconnect |
579 | */ | 579 | */ |
580 | void | 580 | void |
581 | GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, | 581 | GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, |
582 | const struct GNUNET_PeerIdentity *neighbour, | 582 | const struct GNUNET_PeerIdentity *neighbour, |
583 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | 583 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, |
584 | unsigned int atsi_count, | 584 | unsigned int atsi_count, |
@@ -651,7 +651,7 @@ GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, | |||
651 | * @param tmap_new updated type map for the neighbour, NULL for disconnect | 651 | * @param tmap_new updated type map for the neighbour, NULL for disconnect |
652 | */ | 652 | */ |
653 | void | 653 | void |
654 | GDS_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, | 654 | GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, |
655 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | 655 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, |
656 | unsigned int atsi_count, | 656 | unsigned int atsi_count, |
657 | const struct GSC_TypeMap *tmap_old, | 657 | const struct GSC_TypeMap *tmap_old, |
@@ -660,7 +660,7 @@ GDS_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *ne | |||
660 | struct GSC_Client *c; | 660 | struct GSC_Client *c; |
661 | 661 | ||
662 | for (c = client_head; c != NULL; c = c->next) | 662 | for (c = client_head; c != NULL; c = c->next) |
663 | GDS_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, | 663 | GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, |
664 | atsi_count, | 664 | atsi_count, |
665 | tmap_old, tmap_new); | 665 | tmap_old, tmap_new); |
666 | } | 666 | } |
@@ -713,6 +713,7 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
713 | GNUNET_i2s (sender), | 713 | GNUNET_i2s (sender), |
714 | (unsigned int) ntohs (msg->type)); | 714 | (unsigned int) ntohs (msg->type)); |
715 | #endif | 715 | #endif |
716 | GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); | ||
716 | ntm = (struct NotifyTrafficMessage *) buf; | 717 | ntm = (struct NotifyTrafficMessage *) buf; |
717 | ntm->header.size = htons (size); | 718 | ntm->header.size = htons (size); |
718 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); | 719 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); |
diff --git a/src/core/gnunet-service-core_clients.h b/src/core/gnunet-service-core_clients.h index 7e316d90f..9774292c0 100644 --- a/src/core/gnunet-service-core_clients.h +++ b/src/core/gnunet-service-core_clients.h | |||
@@ -58,7 +58,7 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, | |||
58 | * @param tmap_new updated type map for the neighbour, NULL for disconnect | 58 | * @param tmap_new updated type map for the neighbour, NULL for disconnect |
59 | */ | 59 | */ |
60 | void | 60 | void |
61 | GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, | 61 | GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, |
62 | const struct GNUNET_PeerIdentity *neighbour, | 62 | const struct GNUNET_PeerIdentity *neighbour, |
63 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | 63 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, |
64 | unsigned int atsi_count, | 64 | unsigned int atsi_count, |
@@ -78,7 +78,7 @@ GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, | |||
78 | * @param tmap_new updated type map for the neighbour, NULL for disconnect | 78 | * @param tmap_new updated type map for the neighbour, NULL for disconnect |
79 | */ | 79 | */ |
80 | void | 80 | void |
81 | GDS_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, | 81 | GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, |
82 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, | 82 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, |
83 | unsigned int atsi_count, | 83 | unsigned int atsi_count, |
84 | const struct GSC_TypeMap *tmap_old, | 84 | const struct GSC_TypeMap *tmap_old, |
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index 8daf49826..19b692ab9 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c | |||
@@ -1418,16 +1418,25 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) | |||
1418 | { | 1418 | { |
1419 | struct DeliverMessageContext *dmc = client; | 1419 | struct DeliverMessageContext *dmc = client; |
1420 | 1420 | ||
1421 | GSC_CLIENTS_deliver_message (dmc->peer, | 1421 | switch (ntohs (m->type)) |
1422 | dmc->atsi, dmc->atsi_count, | 1422 | { |
1423 | m, | 1423 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: |
1424 | ntohs (m->size), | 1424 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: |
1425 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | 1425 | GSC_SESSIONS_set_typemap (dmc->peer, |
1426 | GSC_CLIENTS_deliver_message (dmc->peer, | 1426 | m); |
1427 | dmc->atsi, dmc->atsi_count, | 1427 | return; |
1428 | m, | 1428 | default: |
1429 | sizeof (struct GNUNET_MessageHeader), | 1429 | GSC_CLIENTS_deliver_message (dmc->peer, |
1430 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | 1430 | dmc->atsi, dmc->atsi_count, |
1431 | m, | ||
1432 | ntohs (m->size), | ||
1433 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | ||
1434 | GSC_CLIENTS_deliver_message (dmc->peer, | ||
1435 | dmc->atsi, dmc->atsi_count, | ||
1436 | m, | ||
1437 | sizeof (struct GNUNET_MessageHeader), | ||
1438 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | ||
1439 | } | ||
1431 | } | 1440 | } |
1432 | 1441 | ||
1433 | 1442 | ||
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c index 7b159022c..480857642 100644 --- a/src/core/gnunet-service-core_sessions.c +++ b/src/core/gnunet-service-core_sessions.c | |||
@@ -188,6 +188,11 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) | |||
188 | gettext_noop ("# established sessions"), | 188 | gettext_noop ("# established sessions"), |
189 | GNUNET_CONTAINER_multihashmap_size (sessions), | 189 | GNUNET_CONTAINER_multihashmap_size (sessions), |
190 | GNUNET_NO); | 190 | GNUNET_NO); |
191 | if (NULL != session->tmap) | ||
192 | { | ||
193 | GSC_TYPEMAP_destroy (session->tmap); | ||
194 | session->tmap = NULL; | ||
195 | } | ||
191 | GNUNET_free (session); | 196 | GNUNET_free (session); |
192 | } | 197 | } |
193 | 198 | ||
@@ -247,7 +252,7 @@ notify_client_about_session (void *cls, | |||
247 | struct GSC_Client *client = cls; | 252 | struct GSC_Client *client = cls; |
248 | struct Session *session = value; | 253 | struct Session *session = value; |
249 | 254 | ||
250 | GDS_CLIENTS_notify_client_about_neighbour (client, | 255 | GSC_CLIENTS_notify_client_about_neighbour (client, |
251 | &session->peer, | 256 | &session->peer, |
252 | NULL, 0, /* FIXME: ATS!? */ | 257 | NULL, 0, /* FIXME: ATS!? */ |
253 | NULL, /* old TMAP: none */ | 258 | NULL, /* old TMAP: none */ |
@@ -690,6 +695,66 @@ GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *cl | |||
690 | 695 | ||
691 | 696 | ||
692 | /** | 697 | /** |
698 | * We've received a typemap message from a peer, update ours. | ||
699 | * Notifies clients about the session. | ||
700 | * | ||
701 | * @param peer peer this is about | ||
702 | * @param msg typemap update message | ||
703 | */ | ||
704 | void | ||
705 | GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, | ||
706 | const struct GNUNET_MessageHeader *msg) | ||
707 | { | ||
708 | struct Session *session; | ||
709 | struct GSC_TypeMap *nmap; | ||
710 | |||
711 | nmap = GSC_TYPEMAP_get_from_message (msg); | ||
712 | if (NULL == nmap) | ||
713 | return; /* malformed */ | ||
714 | session = find_session (peer); | ||
715 | GSC_CLIENTS_notify_clients_about_neighbour (peer, | ||
716 | NULL, 0, /* FIXME: ATS */ | ||
717 | session->tmap, | ||
718 | nmap); | ||
719 | if (NULL != session->tmap) | ||
720 | GSC_TYPEMAP_destroy (session->tmap); | ||
721 | session->tmap = nmap; | ||
722 | } | ||
723 | |||
724 | |||
725 | /** | ||
726 | * The given peer send a message of the specified type. Make sure the | ||
727 | * respective bit is set in its type-map and that clients are notified | ||
728 | * about the session. | ||
729 | * | ||
730 | * @param peer peer this is about | ||
731 | * @param type type of the message | ||
732 | */ | ||
733 | void | ||
734 | GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, | ||
735 | uint16_t type) | ||
736 | { | ||
737 | struct Session *session; | ||
738 | struct GSC_TypeMap *nmap; | ||
739 | |||
740 | session = find_session (peer); | ||
741 | if (GNUNET_YES == | ||
742 | GSC_TYPEMAP_test_match (session->tmap, | ||
743 | &type, 1)) | ||
744 | return; /* already in it */ | ||
745 | nmap = GSC_TYPEMAP_extend (session->tmap, | ||
746 | &type, 1); | ||
747 | GSC_CLIENTS_notify_clients_about_neighbour (peer, | ||
748 | NULL, 0, /* FIXME: ATS */ | ||
749 | session->tmap, | ||
750 | nmap); | ||
751 | if (NULL != session->tmap) | ||
752 | GSC_TYPEMAP_destroy (session->tmap); | ||
753 | session->tmap = nmap; | ||
754 | } | ||
755 | |||
756 | |||
757 | /** | ||
693 | * Initialize sessions subsystem. | 758 | * Initialize sessions subsystem. |
694 | */ | 759 | */ |
695 | void | 760 | void |
diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h index a795c417c..b70bd59fd 100644 --- a/src/core/gnunet-service-core_sessions.h +++ b/src/core/gnunet-service-core_sessions.h | |||
@@ -116,6 +116,30 @@ GSC_SESSIONS_broadcast (const struct GNUNET_MessageHeader *msg); | |||
116 | void | 116 | void |
117 | GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client); | 117 | GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client); |
118 | 118 | ||
119 | /** | ||
120 | * We've received a typemap message from a peer, update ours. | ||
121 | * Notifies clients about the session. | ||
122 | * | ||
123 | * @param peer peer this is about | ||
124 | * @param msg typemap update message | ||
125 | */ | ||
126 | void | ||
127 | GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, | ||
128 | const struct GNUNET_MessageHeader *msg); | ||
129 | |||
130 | |||
131 | /** | ||
132 | * The given peer send a message of the specified type. Make sure the | ||
133 | * respective bit is set in its type-map and that clients are notified | ||
134 | * about the session. | ||
135 | * | ||
136 | * @param peer peer this is about | ||
137 | * @param type type of the message | ||
138 | */ | ||
139 | void | ||
140 | GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, | ||
141 | uint16_t type); | ||
142 | |||
119 | 143 | ||
120 | /** | 144 | /** |
121 | * Handle CORE_ITERATE_PEERS request. For this request type, the client | 145 | * Handle CORE_ITERATE_PEERS request. For this request type, the client |
diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c index 78dfc2bb9..db9b2a136 100644 --- a/src/core/gnunet-service-core_typemap.c +++ b/src/core/gnunet-service-core_typemap.c | |||
@@ -72,7 +72,6 @@ GSC_TYPEMAP_compute_type_map_message () | |||
72 | * should be able to overshoot by more to be safe */ | 72 | * should be able to overshoot by more to be safe */ |
73 | #endif | 73 | #endif |
74 | hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); | 74 | hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); |
75 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); | ||
76 | tmp = (char *) &hdr[1]; | 75 | tmp = (char *) &hdr[1]; |
77 | if ((Z_OK != | 76 | if ((Z_OK != |
78 | compress2 ((Bytef *) tmp, &dlen, (const Bytef *) &my_type_map, | 77 | compress2 ((Bytef *) tmp, &dlen, (const Bytef *) &my_type_map, |
@@ -86,11 +85,57 @@ GSC_TYPEMAP_compute_type_map_message () | |||
86 | { | 85 | { |
87 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP); | 86 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP); |
88 | } | 87 | } |
88 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); | ||
89 | return hdr; | 89 | return hdr; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Extract a type map from a TYPE_MAP message. | ||
95 | * | ||
96 | * @param msg a type map message | ||
97 | * @return NULL on error | ||
98 | */ | ||
99 | struct GSC_TypeMap * | ||
100 | GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg) | ||
101 | { | ||
102 | struct GSC_TypeMap *ret; | ||
103 | uint16_t size; | ||
104 | uLongf dlen; | ||
105 | |||
106 | size = ntohs (msg->size); | ||
107 | switch (msg->type) | ||
108 | { | ||
109 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: | ||
110 | if (size != sizeof (struct GSC_TypeMap)) | ||
111 | { | ||
112 | GNUNET_break_op (0); | ||
113 | return NULL; | ||
114 | } | ||
115 | ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); | ||
116 | memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap)); | ||
117 | return ret; | ||
118 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: | ||
119 | ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); | ||
120 | dlen = sizeof (struct GSC_TypeMap); | ||
121 | if ( (Z_OK != | ||
122 | uncompress ((Bytef*) ret, &dlen, | ||
123 | (const Bytef*) &msg[1], (uLong) size)) || | ||
124 | (dlen != sizeof (struct GSC_TypeMap) ) ) | ||
125 | { | ||
126 | GNUNET_break_op (0); | ||
127 | GNUNET_free (ret); | ||
128 | return NULL; | ||
129 | } | ||
130 | return ret; | ||
131 | default: | ||
132 | GNUNET_break (0); | ||
133 | return NULL; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
94 | * Send my type map to all connected peers (it got changed). | 139 | * Send my type map to all connected peers (it got changed). |
95 | */ | 140 | */ |
96 | static void | 141 | static void |
@@ -169,13 +214,50 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, | |||
169 | unsigned int i; | 214 | unsigned int i; |
170 | 215 | ||
171 | for (i=0;i<tcnt;i++) | 216 | for (i=0;i<tcnt;i++) |
172 | if (0 != (my_type_map.bits[types[i] / 32] & (1 << (types[i] % 32)))) | 217 | if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32)))) |
173 | return GNUNET_YES; | 218 | return GNUNET_YES; |
174 | return GNUNET_NO; | 219 | return GNUNET_NO; |
175 | } | 220 | } |
176 | 221 | ||
177 | 222 | ||
178 | /** | 223 | /** |
224 | * Add additional types to a given typemap. | ||
225 | * | ||
226 | * @param map map to extend (not changed) | ||
227 | * @param types array of types to add | ||
228 | * @param tcnt number of entries in types | ||
229 | * @return updated type map (fresh copy) | ||
230 | */ | ||
231 | struct GSC_TypeMap * | ||
232 | GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, | ||
233 | const uint16_t *types, | ||
234 | unsigned int tcnt) | ||
235 | { | ||
236 | struct GSC_TypeMap *ret; | ||
237 | unsigned int i; | ||
238 | |||
239 | ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); | ||
240 | if (NULL != tmap) | ||
241 | memcpy (ret, tmap, sizeof (struct GSC_TypeMap)); | ||
242 | for (i=0;i<tcnt;i++) | ||
243 | ret->bits[types[i] / 32] |= (1 << (types[i] % 32)); | ||
244 | return ret; | ||
245 | } | ||
246 | |||
247 | |||
248 | /** | ||
249 | * Free the given type map. | ||
250 | * | ||
251 | * @param map a type map | ||
252 | */ | ||
253 | void | ||
254 | GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap) | ||
255 | { | ||
256 | GNUNET_free (tmap); | ||
257 | } | ||
258 | |||
259 | |||
260 | /** | ||
179 | * Initialize typemap subsystem. | 261 | * Initialize typemap subsystem. |
180 | */ | 262 | */ |
181 | void | 263 | void |
diff --git a/src/core/gnunet-service-core_typemap.h b/src/core/gnunet-service-core_typemap.h index 10c614a85..72eb5b566 100644 --- a/src/core/gnunet-service-core_typemap.h +++ b/src/core/gnunet-service-core_typemap.h | |||
@@ -61,6 +61,16 @@ GSC_TYPEMAP_compute_type_map_message (void); | |||
61 | 61 | ||
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Extract a type map from a TYPE_MAP message. | ||
65 | * | ||
66 | * @param msg a type map message | ||
67 | * @return NULL on error | ||
68 | */ | ||
69 | struct GSC_TypeMap * | ||
70 | GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg); | ||
71 | |||
72 | |||
73 | /** | ||
64 | * Test if any of the types from the types array is in the | 74 | * Test if any of the types from the types array is in the |
65 | * given type map. | 75 | * given type map. |
66 | * | 76 | * |
@@ -76,6 +86,29 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, | |||
76 | 86 | ||
77 | 87 | ||
78 | /** | 88 | /** |
89 | * Add additional types to a given typemap. | ||
90 | * | ||
91 | * @param map map to extend (not changed) | ||
92 | * @param types array of types to add | ||
93 | * @param tcnt number of entries in types | ||
94 | * @return updated type map (fresh copy) | ||
95 | */ | ||
96 | struct GSC_TypeMap * | ||
97 | GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, | ||
98 | const uint16_t *types, | ||
99 | unsigned int tcnt); | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Free the given type map. | ||
104 | * | ||
105 | * @param map a type map | ||
106 | */ | ||
107 | void | ||
108 | GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap); | ||
109 | |||
110 | |||
111 | /** | ||
79 | * Initialize typemap subsystem. | 112 | * Initialize typemap subsystem. |
80 | */ | 113 | */ |
81 | void | 114 | void |