diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-14 16:40:38 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-14 16:40:38 +0000 |
commit | b4b8ee35e09ef1828a342355cd0e6ca58fc6441e (patch) | |
tree | fc9edf36a6aacf02e4665efdaecf65f93e9899a9 | |
parent | f0f64d4982fcddec4bfc760cd6ad92ada6b3528e (diff) | |
download | gnunet-b4b8ee35e09ef1828a342355cd0e6ca58fc6441e.tar.gz gnunet-b4b8ee35e09ef1828a342355cd0e6ca58fc6441e.zip |
demultiplexing
-rw-r--r-- | src/transport/gnunet-service-transport-new.c | 97 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 1 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 20 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.h | 9 |
4 files changed, 89 insertions, 38 deletions
diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c index 4536d2573..6bc3c2541 100644 --- a/src/transport/gnunet-service-transport-new.c +++ b/src/transport/gnunet-service-transport-new.c | |||
@@ -116,6 +116,25 @@ process_hello_update (void *cls, | |||
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | /** | ||
120 | * Try to initiate a connection to the given peer if the blacklist | ||
121 | * allowed it. | ||
122 | * | ||
123 | * @param cls closure (unused, NULL) | ||
124 | * @param peer identity of peer that was tested | ||
125 | * @param result GNUNET_OK if the connection is allowed, | ||
126 | * GNUNET_NO if not | ||
127 | */ | ||
128 | static void | ||
129 | try_connect_if_allowed (void *cls, | ||
130 | const struct GNUNET_PeerIdentity *peer, | ||
131 | int result) | ||
132 | { | ||
133 | if (GNUNET_OK != result) | ||
134 | return; /* not allowed */ | ||
135 | GST_neighbours_try_connect (peer); | ||
136 | } | ||
137 | |||
119 | 138 | ||
120 | /** | 139 | /** |
121 | * Function called by the transport for each received message. | 140 | * Function called by the transport for each received message. |
@@ -152,17 +171,74 @@ plugin_env_receive_callback (void *cls, | |||
152 | const char *plugin_name = cls; | 171 | const char *plugin_name = cls; |
153 | int do_forward; | 172 | int do_forward; |
154 | struct GNUNET_TIME_Relative ret; | 173 | struct GNUNET_TIME_Relative ret; |
174 | uint16_t type; | ||
175 | |||
155 | 176 | ||
156 | do_forward = GNUNET_SYSERR; | 177 | ret = GNUNET_TIME_UNIT_ZERO; |
157 | ret = GST_neighbours_calculate_receive_delay (peer, | 178 | if (NULL != message) |
158 | (message == NULL) | 179 | { |
159 | ? 0 | 180 | type = ntohs (message->type); |
160 | : ntohs (message->size), | 181 | switch (type) |
161 | &do_forward); | 182 | { |
162 | /* FIXME: look at the type of the message (PING, PONG, CONNECT, payload...) */ | 183 | case GNUNET_MESSAGE_TYPE_HELLO: |
163 | if ( (NULL != message) && | 184 | GST_validation_handle_hello (message); |
164 | (do_forward == GNUNET_YES) ) | 185 | break; |
165 | GST_clients_broadcast (message, GNUNET_YES); | 186 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: |
187 | #if DEBUG_TRANSPORT | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
189 | "Processing `%s' from `%s'\n", | ||
190 | "PING", | ||
191 | (sender_address != NULL) | ||
192 | ? GST_plugins_a2s (plugin_name, | ||
193 | sender_address, | ||
194 | sender_address_len) | ||
195 | : "<inbound>"); | ||
196 | #endif | ||
197 | GST_validation_handle_ping (peer, | ||
198 | message, | ||
199 | plugin_name, | ||
200 | session, | ||
201 | sender_address, sender_address_len); | ||
202 | break; | ||
203 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | ||
204 | #if DEBUG_TRANSPORT | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
206 | "Processing `%s' from `%s'\n", | ||
207 | "PONG", | ||
208 | (sender_address != NULL) | ||
209 | ? GST_plugins_a2s (plugin_name, | ||
210 | sender_address, | ||
211 | sender_address_len) | ||
212 | : "<inbound>"); | ||
213 | #endif | ||
214 | GST_validation_handle_pong (peer, | ||
215 | message); | ||
216 | break; | ||
217 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: | ||
218 | (void) GST_blacklist_test_allowed (peer, | ||
219 | NULL, | ||
220 | &try_connect_if_allowed, NULL); | ||
221 | /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred | ||
222 | way to communicate with this peer (other peer switched transport) */ | ||
223 | break; | ||
224 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | ||
225 | /* TODO: do some validation to prevent an attacker from sending | ||
226 | a fake disconnect message... */ | ||
227 | GST_neighbours_force_disconnect (peer); | ||
228 | break; | ||
229 | default: | ||
230 | /* should be payload */ | ||
231 | do_forward = GNUNET_SYSERR; | ||
232 | ret = GST_neighbours_calculate_receive_delay (peer, | ||
233 | (message == NULL) | ||
234 | ? 0 | ||
235 | : ntohs (message->size), | ||
236 | &do_forward); | ||
237 | if (do_forward == GNUNET_YES) | ||
238 | GST_clients_broadcast (message, GNUNET_YES); | ||
239 | break; | ||
240 | } | ||
241 | } | ||
166 | GNUNET_ATS_address_update (GST_ats, | 242 | GNUNET_ATS_address_update (GST_ats, |
167 | peer, | 243 | peer, |
168 | GNUNET_TIME_absolute_get (), /* valid at least until right now... */ | 244 | GNUNET_TIME_absolute_get (), /* valid at least until right now... */ |
@@ -171,6 +247,7 @@ plugin_env_receive_callback (void *cls, | |||
171 | sender_address, | 247 | sender_address, |
172 | sender_address_len, | 248 | sender_address_len, |
173 | ats, ats_count); | 249 | ats, ats_count); |
250 | |||
174 | return ret; | 251 | return ret; |
175 | } | 252 | } |
176 | 253 | ||
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 0e701ea02..ca686057d 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -532,7 +532,6 @@ clients_handle_send (void *cls, | |||
532 | &handle_send_transmit_continuation, | 532 | &handle_send_transmit_continuation, |
533 | stcc); | 533 | stcc); |
534 | } | 534 | } |
535 | |||
536 | 535 | ||
537 | 536 | ||
538 | /** | 537 | /** |
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index aabb28068..cbfd16b7e 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -618,7 +618,6 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
618 | const void *sender_address, | 618 | const void *sender_address, |
619 | size_t sender_address_len) | 619 | size_t sender_address_len) |
620 | { | 620 | { |
621 | |||
622 | const struct TransportPingMessage *ping; | 621 | const struct TransportPingMessage *ping; |
623 | struct TransportPongMessage *pong; | 622 | struct TransportPongMessage *pong; |
624 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 623 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
@@ -979,17 +978,10 @@ add_valid_peer_address (void *cls, | |||
979 | * | 978 | * |
980 | * @param sender peer sending the PONG | 979 | * @param sender peer sending the PONG |
981 | * @param hdr the PONG | 980 | * @param hdr the PONG |
982 | * @param plugin_name name of plugin that received the PONG | ||
983 | * @param sender_address address of the sender as known to the plugin, NULL | ||
984 | * if we did not initiate the connection | ||
985 | * @param sender_address_len number of bytes in sender_address | ||
986 | */ | 981 | */ |
987 | void | 982 | void |
988 | GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | 983 | GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, |
989 | const struct GNUNET_MessageHeader *hdr, | 984 | const struct GNUNET_MessageHeader *hdr) |
990 | const char *plugin_name, | ||
991 | const void *sender_address, | ||
992 | size_t sender_address_len) | ||
993 | { | 985 | { |
994 | const struct TransportPongMessage *pong; | 986 | const struct TransportPongMessage *pong; |
995 | struct ValidationEntry *ve; | 987 | struct ValidationEntry *ve; |
@@ -1018,16 +1010,6 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1018 | GNUNET_break_op (0); | 1010 | GNUNET_break_op (0); |
1019 | return; | 1011 | return; |
1020 | } | 1012 | } |
1021 | #if DEBUG_TRANSPORT | ||
1022 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
1023 | "Processing `%s' from `%s'\n", | ||
1024 | "PONG", | ||
1025 | (sender_address != NULL) | ||
1026 | ? GST_plugin_a2s (plugin_name, | ||
1027 | sender_address, | ||
1028 | sender_address_len) | ||
1029 | : "<inbound>"); | ||
1030 | #endif | ||
1031 | addr = (const char*) &pong[1]; | 1013 | addr = (const char*) &pong[1]; |
1032 | alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); | 1014 | alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); |
1033 | addrend = memchr (addr, '\0', alen); | 1015 | addrend = memchr (addr, '\0', alen); |
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index 5ab2e9163..73d346678 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h | |||
@@ -71,17 +71,10 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
71 | * | 71 | * |
72 | * @param sender peer sending the PONG | 72 | * @param sender peer sending the PONG |
73 | * @param hdr the PONG | 73 | * @param hdr the PONG |
74 | * @param plugin_name name of plugin that received the PONG | ||
75 | * @param sender_address address of the sender as known to the plugin, NULL | ||
76 | * if we did not initiate the connection | ||
77 | * @param sender_address_len number of bytes in sender_address | ||
78 | */ | 74 | */ |
79 | void | 75 | void |
80 | GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | 76 | GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, |
81 | const struct GNUNET_MessageHeader *hdr, | 77 | const struct GNUNET_MessageHeader *hdr); |
82 | const char *plugin_name, | ||
83 | const void *sender_address, | ||
84 | size_t sender_address_len); | ||
85 | 78 | ||
86 | 79 | ||
87 | /** | 80 | /** |