aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-01-25 13:59:55 +0000
committerNathan S. Evans <evans@in.tum.de>2010-01-25 13:59:55 +0000
commite4631ed7857d67135229f9897bfe0d5e203943c1 (patch)
treed31659ab11494cdd867527698e878a25f51bd0b2 /src
parentd227318a905599753d76848b9506bdf215ec1755 (diff)
downloadgnunet-e4631ed7857d67135229f9897bfe0d5e203943c1.tar.gz
gnunet-e4631ed7857d67135229f9897bfe0d5e203943c1.zip
udp closer to working, still wrestling with how to do data structures properly in gnunet-service-transport.c (grr)
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-transport.c99
-rw-r--r--src/transport/plugin_transport_udp.c25
2 files changed, 110 insertions, 14 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 31b6584e9..95ab96919 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -988,7 +988,12 @@ transmit_send_continuation (void *cls,
988 rl->connected = GNUNET_NO; 988 rl->connected = GNUNET_NO;
989 } 989 }
990 if (!mq->internal_msg) 990 if (!mq->internal_msg)
991 rl->transmit_ready = GNUNET_YES; 991 {
992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
993 "Setting transmit_ready on transport!\n");
994 rl->transmit_ready = GNUNET_YES;
995 }
996
992 if (mq->client != NULL) 997 if (mq->client != NULL)
993 { 998 {
994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1025,6 +1030,16 @@ try_transmission_to_peer (struct NeighborList *neighbor)
1025 struct MessageQueue *mq; 1030 struct MessageQueue *mq;
1026 struct GNUNET_TIME_Absolute now; 1031 struct GNUNET_TIME_Absolute now;
1027 1032
1033 if (neighbor->addr != NULL)
1034 {
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1036 _("try_transmission_to_peer entry: at this point neighbor->addr is NOT NULL\n"));
1037 }
1038 else
1039 {
1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer entry: at this point neighbor->addr is NULL\n"));
1041 }
1042
1028 if (neighbor->messages == NULL) 1043 if (neighbor->messages == NULL)
1029 return; /* nothing to do */ 1044 return; /* nothing to do */
1030 try_alternative_plugins (neighbor); 1045 try_alternative_plugins (neighbor);
@@ -1045,6 +1060,13 @@ try_transmission_to_peer (struct NeighborList *neighbor)
1045#endif 1060#endif
1046 pos->connected = GNUNET_NO; 1061 pos->connected = GNUNET_NO;
1047 } 1062 }
1063 if (GNUNET_YES == pos->transmit_ready)
1064 {
1065#if DEBUG_TRANSPORT
1066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1067 "Found transmit_ready flag...\n");
1068#endif
1069 }
1048 if (((GNUNET_YES == pos->transmit_ready) || 1070 if (((GNUNET_YES == pos->transmit_ready) ||
1049 (mq->internal_msg)) && 1071 (mq->internal_msg)) &&
1050 (pos->connect_attempts < MAX_CONNECT_RETRY) && 1072 (pos->connect_attempts < MAX_CONNECT_RETRY) &&
@@ -1084,6 +1106,10 @@ try_transmission_to_peer (struct NeighborList *neighbor)
1084 GNUNET_i2s (&neighbor->id), rl->plugin->short_name); 1106 GNUNET_i2s (&neighbor->id), rl->plugin->short_name);
1085#endif 1107#endif
1086 1108
1109 if (rl->neighbor->addr != NULL)
1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NOT NULL, addrlen is %d\n"), rl->neighbor->addr_len);
1111 else
1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NULL\n"));
1087 rl->plugin->api->send (rl->plugin->api->cls, 1113 rl->plugin->api->send (rl->plugin->api->cls,
1088 &neighbor->id, 1114 &neighbor->id,
1089 mq->message, 1115 mq->message,
@@ -1119,6 +1145,8 @@ transmit_to_peer (struct TransportClient *client,
1119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1120 _("Sending message of type %u to peer `%4s'\n"), 1146 _("Sending message of type %u to peer `%4s'\n"),
1121 ntohs (msg->type), GNUNET_i2s (&neighbor->id)); 1147 ntohs (msg->type), GNUNET_i2s (&neighbor->id));
1148 if (neighbor->addr != NULL)
1149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("transmit_to_peer: at this point neighbor->addr is NOT NULL\n"));
1122#endif 1150#endif
1123 if (client != NULL) 1151 if (client != NULL)
1124 { 1152 {
@@ -1190,7 +1218,17 @@ address_generator (void *cls, size_t max, void *buf)
1190 gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL; 1218 gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL;
1191 } 1219 }
1192 if (NULL == gc->plug_pos) 1220 if (NULL == gc->plug_pos)
1193 return 0; 1221 {
1222#if DEBUG_TRANSPORT
1223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1224 "In address_generator, gc->plug_pos is NULL!\n");
1225#endif
1226 return 0;
1227 }
1228#if DEBUG_TRANSPORT
1229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1230 "Should be adding an address...\n");
1231#endif
1194 ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name, 1232 ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name,
1195 gc->expiration, 1233 gc->expiration,
1196 gc->addr_pos->addr, 1234 gc->addr_pos->addr,
@@ -1220,6 +1258,10 @@ refresh_hello ()
1220 gc.addr_pos = plugins != NULL ? plugins->addresses : NULL; 1258 gc.addr_pos = plugins != NULL ? plugins->addresses : NULL;
1221 gc.expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); 1259 gc.expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1222 hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc); 1260 hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc);
1261#if DEBUG_TRANSPORT
1262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1263 "Refreshed my `%s', new size is %d\n", "HELLO", GNUNET_HELLO_size(hello));
1264#endif
1223 cpos = clients; 1265 cpos = clients;
1224 while (cpos != NULL) 1266 while (cpos != NULL)
1225 { 1267 {
@@ -1801,6 +1843,7 @@ check_hello_validated (void *cls,
1801 struct ValidationAddress *va; 1843 struct ValidationAddress *va;
1802 struct TransportPlugin *tp; 1844 struct TransportPlugin *tp;
1803 int first_call; 1845 int first_call;
1846 int count;
1804 struct GNUNET_PeerIdentity apeer; 1847 struct GNUNET_PeerIdentity apeer;
1805 1848
1806 first_call = GNUNET_NO; 1849 first_call = GNUNET_NO;
@@ -1817,6 +1860,10 @@ check_hello_validated (void *cls,
1817 chvc->e->next = pending_validations; 1860 chvc->e->next = pending_validations;
1818 pending_validations = chvc->e; 1861 pending_validations = chvc->e;
1819 } 1862 }
1863 /* no existing HELLO, all addresses are new */
1864 GNUNET_HELLO_iterate_addresses (chvc->hello,
1865 GNUNET_NO, &run_validation, chvc->e);
1866#if 0
1820 if (h != NULL) 1867 if (h != NULL)
1821 { 1868 {
1822 GNUNET_HELLO_iterate_new_addresses (chvc->hello, 1869 GNUNET_HELLO_iterate_new_addresses (chvc->hello,
@@ -1830,6 +1877,7 @@ check_hello_validated (void *cls,
1830 GNUNET_HELLO_iterate_addresses (chvc->hello, 1877 GNUNET_HELLO_iterate_addresses (chvc->hello,
1831 GNUNET_NO, &run_validation, chvc->e); 1878 GNUNET_NO, &run_validation, chvc->e);
1832 } 1879 }
1880#endif
1833 if (h != NULL) 1881 if (h != NULL)
1834 return; /* wait for next call */ 1882 return; /* wait for next call */
1835 /* finally, transmit validation attempts */ 1883 /* finally, transmit validation attempts */
@@ -1840,6 +1888,7 @@ check_hello_validated (void *cls,
1840 "HELLO", GNUNET_i2s (&apeer)); 1888 "HELLO", GNUNET_i2s (&apeer));
1841#endif 1889#endif
1842 va = chvc->e->addresses; 1890 va = chvc->e->addresses;
1891 count = 0;
1843 while (va != NULL) 1892 while (va != NULL)
1844 { 1893 {
1845#if DEBUG_TRANSPORT 1894#if DEBUG_TRANSPORT
@@ -1858,7 +1907,13 @@ check_hello_validated (void *cls,
1858 &va[1], va->addr_len); 1907 &va[1], va->addr_len);
1859 /* va->ok = GNUNET_SYSERR; will be set by validate_address! */ 1908 /* va->ok = GNUNET_SYSERR; will be set by validate_address! */
1860 va = va->next; 1909 va = va->next;
1910 count++;
1861 } 1911 }
1912
1913#if DEBUG_TRANSPORT
1914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1915 "Found %d addresses in hello of size %d\n", count, GNUNET_HELLO_size(chvc->hello));
1916#endif
1862 GNUNET_SCHEDULER_add_delayed (sched, 1917 GNUNET_SCHEDULER_add_delayed (sched,
1863 GNUNET_TIME_absolute_get_remaining (chvc-> 1918 GNUNET_TIME_absolute_get_remaining (chvc->
1864 e->timeout), 1919 e->timeout),
@@ -1909,8 +1964,8 @@ process_hello (struct TransportPlugin *plugin,
1909 &target.hashPubKey); 1964 &target.hashPubKey);
1910#if DEBUG_TRANSPORT 1965#if DEBUG_TRANSPORT
1911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1966 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1912 "Processing `%s' message for `%4s'\n", 1967 "Processing `%s' message for `%4s' of size %d (hsize is %d)\n",
1913 "HELLO", GNUNET_i2s (&target)); 1968 "HELLO", GNUNET_i2s (&target), GNUNET_HELLO_size(hello), hsize);
1914#endif 1969#endif
1915 /* check if a HELLO for this peer is already on the validation list */ 1970 /* check if a HELLO for this peer is already on the validation list */
1916 e = pending_validations; 1971 e = pending_validations;
@@ -2125,7 +2180,7 @@ static int handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
2125 struct TransportPingMessage *ping; 2180 struct TransportPingMessage *ping;
2126 struct TransportPongMessage *pong; 2181 struct TransportPongMessage *pong;
2127 uint16_t msize; 2182 uint16_t msize;
2128 2183 struct NeighborList *n;
2129 pong = GNUNET_malloc(sizeof(struct TransportPongMessage)); 2184 pong = GNUNET_malloc(sizeof(struct TransportPongMessage));
2130 2185
2131#if DEBUG_TRANSPORT 2186#if DEBUG_TRANSPORT
@@ -2181,11 +2236,37 @@ static int handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
2181 GNUNET_assert (GNUNET_OK == 2236 GNUNET_assert (GNUNET_OK ==
2182 GNUNET_CRYPTO_rsa_sign (my_private_key, 2237 GNUNET_CRYPTO_rsa_sign (my_private_key,
2183 &pong->purpose, &pong->signature)); 2238 &pong->purpose, &pong->signature));
2239 /* Will this nonsense work, even for UDP?
2240 * The idea is that we need an address to send to for UDP, but we may not know
2241 * this peer yet. So in that case, we need to create a new neighbor with the
2242 * current address, but is this address going to be correct, or will it have a
2243 * random high port or something? Another question is, why didn't we get a WELCOME
2244 * from this peer with its advertised addresses already? We don't want to
2245 * differentiate based on transport... */
2246 n = find_neighbor(peer, NULL, 0);
2247 if (n == NULL)
2248 {
2249#if DEBUG_TRANSPORT
2250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2251 "Didn't find peer in list, adding...\n");
2252#endif
2253 setup_new_neighbor(peer, sender_address, sender_address_len);
2254 n = find_neighbor(peer, sender_address, sender_address_len);
2255 GNUNET_assert(n != NULL);
2256 }
2257 else if (n->addr == NULL)
2258 {
2259#if DEBUG_TRANSPORT
2260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2261 "Found peer in list, but without address, adding!\n");
2262#endif
2263 n->addr = GNUNET_malloc(sender_address_len);
2264 memcpy(n->addr, sender_address, sender_address_len);
2265 n->addr_len = sender_address_len;
2266 }
2267
2268 transmit_to_peer(NULL, TRANSPORT_DEFAULT_PRIORITY, &pong->header, GNUNET_NO, n);
2184 2269
2185 transmit_to_peer(NULL, TRANSPORT_DEFAULT_PRIORITY, &pong->header, GNUNET_NO, find_neighbor(peer, NULL, 0));
2186 /* plugin->api->send(); */ /* We can't directly send back along received address, because
2187 the port we saw for the peer (for TCP especially) will not
2188 likely be the open port on the other side! */
2189 GNUNET_free(pong); 2270 GNUNET_free(pong);
2190 return GNUNET_OK; 2271 return GNUNET_OK;
2191} 2272}
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 7697abdd3..75b8c6e56 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -40,7 +40,7 @@
40#include "plugin_transport.h" 40#include "plugin_transport.h"
41#include "transport.h" 41#include "transport.h"
42 42
43#define DEBUG_UDP GNUNET_NO 43#define DEBUG_UDP GNUNET_YES
44 44
45/* 45/*
46 * Transport cost to peer, always 1 for UDP (direct connection) 46 * Transport cost to peer, always 1 for UDP (direct connection)
@@ -216,7 +216,16 @@ udp_plugin_send (void *cls,
216 ssize_t sent; 216 ssize_t sent;
217 217
218 GNUNET_assert(udp_sock != NULL); 218 GNUNET_assert(udp_sock != NULL);
219 GNUNET_assert(addr != NULL); 219
220 if ((addr == NULL) || (addrlen == 0))
221 {
222#if DEBUG_UDP
223 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
224 ("udp_plugin_send called without address, returning!\n"));
225#endif
226 cont (cont_cls, target, GNUNET_OK);
227 return 0; /* Can never send if we don't have an address!! */
228 }
220 229
221 /* Build the message to be sent */ 230 /* Build the message to be sent */
222 message = GNUNET_malloc (sizeof (struct UDPMessage) + ntohs (msg->size)); 231 message = GNUNET_malloc (sizeof (struct UDPMessage) + ntohs (msg->size));
@@ -243,7 +252,13 @@ udp_plugin_send (void *cls,
243 if (sent == GNUNET_SYSERR) 252 if (sent == GNUNET_SYSERR)
244 cont (cont_cls, target, GNUNET_SYSERR); 253 cont (cont_cls, target, GNUNET_SYSERR);
245 else 254 else
246 cont (cont_cls, target, GNUNET_OK); 255 {
256#if DEBUG_UDP
257 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
258 ("Sucessfully sent message, calling transmit continuation!\n"));
259#endif
260 cont (cont_cls, target, GNUNET_OK);
261 }
247 } 262 }
248 GNUNET_free (message); 263 GNUNET_free (message);
249 return sent; 264 return sent;
@@ -405,7 +420,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
405 ntohs (hdr->type)); 420 ntohs (hdr->type));
406#endif 421#endif
407 plugin->env->receive (plugin->env->cls, 422 plugin->env->receive (plugin->env->cls,
408 sender, &msg->header, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); 423 sender, hdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen);
409 424
410 GNUNET_free (sender); 425 GNUNET_free (sender);
411 GNUNET_free (buf); 426 GNUNET_free (buf);
@@ -562,7 +577,7 @@ udp_check_address (void *cls, void *addr, size_t addrlen)
562 v6 = (struct sockaddr_in6 *) buf; 577 v6 = (struct sockaddr_in6 *) buf;
563 v6->sin6_port = htons (check_port (plugin, ntohs (v6->sin6_port))); 578 v6->sin6_port = htons (check_port (plugin, ntohs (v6->sin6_port)));
564 } 579 }
565#if DEBUG_TCP 580#if DEBUG_UDP
566 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 581 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
567 "tcp", 582 "tcp",
568 "Informing transport service about my address `%s'.\n", 583 "Informing transport service about my address `%s'.\n",