X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftransport%2Fgnunet-service-transport.c;h=28fd381261fe506399f9d37ea33dcde9405b0fad;hb=f206220e03ccf5cfdb8e8d51d253fed17db4d4ee;hp=b05e8360a300d037dc44e5f584e72a7df0208ec4;hpb=8b62835d8e607d276ce0d1b2e288646e23bd440a;p=oweals%2Fgnunet.git diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index b05e8360a..28fd38126 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -73,7 +73,7 @@ * Besides, if a single request to an address takes a long time, * then the peer is unlikely worthwhile anyway. */ -#define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) +#define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** * How long will we allow sending of a ping to be delayed? @@ -988,7 +988,12 @@ transmit_send_continuation (void *cls, rl->connected = GNUNET_NO; } if (!mq->internal_msg) - rl->transmit_ready = GNUNET_YES; + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Setting transmit_ready on transport!\n"); + rl->transmit_ready = GNUNET_YES; + } + if (mq->client != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1025,6 +1030,16 @@ try_transmission_to_peer (struct NeighborList *neighbor) struct MessageQueue *mq; struct GNUNET_TIME_Absolute now; + if (neighbor->addr != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("try_transmission_to_peer entry: at this point neighbor->addr is NOT NULL\n")); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer entry: at this point neighbor->addr is NULL\n")); + } + if (neighbor->messages == NULL) return; /* nothing to do */ try_alternative_plugins (neighbor); @@ -1045,6 +1060,13 @@ try_transmission_to_peer (struct NeighborList *neighbor) #endif pos->connected = GNUNET_NO; } + if (GNUNET_YES == pos->transmit_ready) + { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found transmit_ready flag...\n"); +#endif + } if (((GNUNET_YES == pos->transmit_ready) || (mq->internal_msg)) && (pos->connect_attempts < MAX_CONNECT_RETRY) && @@ -1084,9 +1106,15 @@ try_transmission_to_peer (struct NeighborList *neighbor) GNUNET_i2s (&neighbor->id), rl->plugin->short_name); #endif + if (rl->neighbor->addr != NULL) + 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); + else + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NULL\n")); + /* FIXME: Change MessageQueue to hold message buffer and size? */ rl->plugin->api->send (rl->plugin->api->cls, &neighbor->id, - mq->message, + (char *)mq->message, + ntohs(mq->message->size), mq->priority, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, rl->neighbor->addr, @@ -1119,6 +1147,8 @@ transmit_to_peer (struct TransportClient *client, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Sending message of type %u to peer `%4s'\n"), ntohs (msg->type), GNUNET_i2s (&neighbor->id)); + if (neighbor->addr != NULL) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("transmit_to_peer: at this point neighbor->addr is NOT NULL\n")); #endif if (client != NULL) { @@ -1154,13 +1184,13 @@ transmit_to_peer (struct TransportClient *client, { /* new head */ neighbor->messages = mq; - try_transmission_to_peer (neighbor); } else { /* append */ mqe->next = mq; } + try_transmission_to_peer (neighbor); } @@ -1190,7 +1220,17 @@ address_generator (void *cls, size_t max, void *buf) gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL; } if (NULL == gc->plug_pos) - return 0; + { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "In address_generator, gc->plug_pos is NULL!\n"); +#endif + return 0; + } +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Should be adding an address...\n"); +#endif ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name, gc->expiration, gc->addr_pos->addr, @@ -1220,6 +1260,10 @@ refresh_hello () gc.addr_pos = plugins != NULL ? plugins->addresses : NULL; gc.expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc); +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Refreshed my `%s', new size is %d\n", "HELLO", GNUNET_HELLO_size(hello)); +#endif cpos = clients; while (cpos != NULL) { @@ -1514,7 +1558,9 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); n = find_neighbor (&pid, NULL, 0); if (NULL != n) - try_transmission_to_peer (n); + { + try_transmission_to_peer (n); + } GNUNET_free (hello); while (NULL != (va = pos->addresses)) { @@ -1551,21 +1597,6 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } -static struct GNUNET_MessageHeader * -createPingMessage (struct GNUNET_PeerIdentity * target, struct ValidationAddress *va) -{ - - struct TransportPingMessage *ping; - ping = GNUNET_malloc(sizeof(struct TransportPingMessage)); - - ping->challenge = htonl(va->challenge); - ping->header.size = sizeof(struct TransportPingMessage); - ping->header.type = GNUNET_MESSAGE_TYPE_TRANSPORT_PING; - memcpy(&ping->target, target, sizeof(struct GNUNET_PeerIdentity)); - - return &ping->header; -} - /** * Function that will be called if we receive a validation * of an address challenge that we transmitted to another @@ -1593,7 +1624,7 @@ handle_pong (void *cls, const struct GNUNET_MessageHeader *message, struct ValidationAddress *va; struct GNUNET_PeerIdentity id; struct TransportPongMessage *pong = (struct TransportPongMessage *)message; - + int count = 0; unsigned int challenge = ntohl(pong->challenge); pos = pending_validations; while (pos != NULL) @@ -1605,14 +1636,15 @@ handle_pong (void *cls, const struct GNUNET_MessageHeader *message, if (0 == memcmp (peer, &id, sizeof (struct GNUNET_PeerIdentity))) break; pos = pos->next; + count++; } if (pos == NULL) { /* TODO: call statistics (unmatched PONG) */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ - ("Received validation response but have no record of any validation request for `%4s'. Ignoring.\n"), - GNUNET_i2s (peer)); + ("Received validation response but have no record of any validation request for `%4s' (out of %d). Ignoring.\n"), + GNUNET_i2s (peer), count); return; } not_done = 0; @@ -1626,13 +1658,14 @@ handle_pong (void *cls, const struct GNUNET_MessageHeader *message, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Confirmed validity of address, peer `%4s' has address `%s'.\n", GNUNET_i2s (peer), - GNUNET_a2s ((const struct sockaddr *) &va[1], - va->addr_len)); + GNUNET_a2s ((const struct sockaddr *) sender_address, + sender_address_len)); #endif GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, _ ("Another peer saw us using the address `%s' via `FIXME'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"), - sender_address); + GNUNET_a2s ((const struct sockaddr *) &va[1], + va->addr_len)); va->ok = GNUNET_YES; va->expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); @@ -1713,7 +1746,12 @@ run_validation (void *cls, struct TransportPlugin *tp; struct ValidationAddress *va; struct GNUNET_PeerIdentity id; - struct GNUNET_MessageHeader *pingMessage; + int sent; + struct TransportPingMessage *ping; + char * message_buf; + int hello_size; + int tsize; + tp = find_transport (tname); if (tp == NULL) { @@ -1741,13 +1779,35 @@ run_validation (void *cls, (unsigned int) -1); memcpy (&va[1], addr, addrlen); - pingMessage = createPingMessage(&id, va); + hello_size = GNUNET_HELLO_size(our_hello); + tsize = sizeof(struct TransportPingMessage) + hello_size; + + message_buf = GNUNET_malloc(tsize); + + ping = GNUNET_malloc(sizeof(struct TransportPingMessage)); + ping->challenge = htonl(va->challenge); + ping->header.size = htons(sizeof(struct TransportPingMessage)); + ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); + memcpy(&ping->target, &id, sizeof(struct GNUNET_PeerIdentity)); + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "hello size is %d, ping size is %d, total size is %d", hello_size, sizeof(struct TransportPingMessage), tsize); + + memcpy(message_buf, our_hello, hello_size); + memcpy(&message_buf[hello_size], ping, sizeof(struct TransportPingMessage)); + + + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ping message to address `%s' via `%s' for `%4s'\n", + GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id)); - tp->api->send(tp->api->cls, &id, pingMessage, GNUNET_SCHEDULER_PRIORITY_DEFAULT, + + sent = tp->api->send(tp->api->cls, &id, message_buf, tsize, GNUNET_SCHEDULER_PRIORITY_DEFAULT, TRANSPORT_DEFAULT_TIMEOUT, addr, addrlen, GNUNET_YES, NULL, NULL); - GNUNET_free(pingMessage); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport returned %d from send!\n", sent); + GNUNET_free(ping); + GNUNET_free(message_buf); return GNUNET_OK; } @@ -1763,6 +1823,8 @@ run_validation (void *cls, * the address via the transport plugin. If not validated, then * do not count this as a good peer/address... * + * Currently this function is not used, ping/pongs get sent from the + * run_validation function. Haven't decided yet how to do this. */ static void validate_address (void *cls, struct ValidationAddress *va, @@ -1792,6 +1854,7 @@ check_hello_validated (void *cls, struct ValidationAddress *va; struct TransportPlugin *tp; int first_call; + int count; struct GNUNET_PeerIdentity apeer; first_call = GNUNET_NO; @@ -1808,6 +1871,10 @@ check_hello_validated (void *cls, chvc->e->next = pending_validations; pending_validations = chvc->e; } + /* no existing HELLO, all addresses are new */ + GNUNET_HELLO_iterate_addresses (chvc->hello, + GNUNET_NO, &run_validation, chvc->e); +#if 0 if (h != NULL) { GNUNET_HELLO_iterate_new_addresses (chvc->hello, @@ -1821,6 +1888,7 @@ check_hello_validated (void *cls, GNUNET_HELLO_iterate_addresses (chvc->hello, GNUNET_NO, &run_validation, chvc->e); } +#endif if (h != NULL) return; /* wait for next call */ /* finally, transmit validation attempts */ @@ -1831,6 +1899,7 @@ check_hello_validated (void *cls, "HELLO", GNUNET_i2s (&apeer)); #endif va = chvc->e->addresses; + count = 0; while (va != NULL) { #if DEBUG_TRANSPORT @@ -1849,7 +1918,13 @@ check_hello_validated (void *cls, &va[1], va->addr_len); /* va->ok = GNUNET_SYSERR; will be set by validate_address! */ va = va->next; + count++; } + +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found %d addresses in hello of size %d\n", count, GNUNET_HELLO_size(chvc->hello)); +#endif GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_absolute_get_remaining (chvc-> e->timeout), @@ -1900,8 +1975,8 @@ process_hello (struct TransportPlugin *plugin, &target.hashPubKey); #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Processing `%s' message for `%4s'\n", - "HELLO", GNUNET_i2s (&target)); + "Processing `%s' message for `%4s' of size %d (hsize is %d)\n", + "HELLO", GNUNET_i2s (&target), GNUNET_HELLO_size(hello), hsize); #endif /* check if a HELLO for this peer is already on the validation list */ e = pending_validations; @@ -2116,7 +2191,7 @@ static int handle_ping(void *cls, const struct GNUNET_MessageHeader *message, struct TransportPingMessage *ping; struct TransportPongMessage *pong; uint16_t msize; - + struct NeighborList *n; pong = GNUNET_malloc(sizeof(struct TransportPongMessage)); #if DEBUG_TRANSPORT @@ -2172,11 +2247,37 @@ static int handle_ping(void *cls, const struct GNUNET_MessageHeader *message, GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_rsa_sign (my_private_key, &pong->purpose, &pong->signature)); + /* Will this nonsense work, even for UDP? + * The idea is that we need an address to send to for UDP, but we may not know + * this peer yet. So in that case, we need to create a new neighbor with the + * current address, but is this address going to be correct, or will it have a + * random high port or something? Another question is, why didn't we get a WELCOME + * from this peer with its advertised addresses already? We don't want to + * differentiate based on transport... */ + n = find_neighbor(peer, NULL, 0); + if (n == NULL) + { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Didn't find peer in list, adding...\n"); +#endif + setup_new_neighbor(peer, sender_address, sender_address_len); + n = find_neighbor(peer, sender_address, sender_address_len); + GNUNET_assert(n != NULL); + } + else if (n->addr == NULL) + { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found peer in list, but without address, adding!\n"); +#endif + n->addr = GNUNET_malloc(sender_address_len); + memcpy(n->addr, sender_address, sender_address_len); + n->addr_len = sender_address_len; + } + + transmit_to_peer(NULL, TRANSPORT_DEFAULT_PRIORITY, &pong->header, GNUNET_NO, n); - transmit_to_peer(NULL, TRANSPORT_DEFAULT_PRIORITY, &pong->header, GNUNET_NO, find_neighbor(peer, NULL, 0)); - /* plugin->api->send(); */ /* We can't directly send back along received address, because - the port we saw for the peer (for TCP especially) will not - likely be the open port on the other side! */ GNUNET_free(pong); return GNUNET_OK; } @@ -2301,8 +2402,10 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, break; case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: handle_ping(plugin, message, peer, sender_address, sender_address_len); + break; case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: handle_pong(plugin, message, peer, sender_address, sender_address_len); + break; //plugin_env_notify_validation(); case GNUNET_MESSAGE_TYPE_TRANSPORT_ACK: n->saw_ack = GNUNET_YES; @@ -2409,6 +2512,10 @@ handle_start (void *cls, } GNUNET_free (im); } + else + { + fprintf(stderr, "Our hello is NULL!\n"); + } GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -2587,8 +2694,8 @@ transmit_address_to_client (void *cls, const char *address) slen = 0; else slen = strlen (address) + 1; - GNUNET_SERVER_transmit_context_append (tc, address, slen, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); + GNUNET_SERVER_transmit_context_append_data (tc, address, slen, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); if (NULL == address) GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); } @@ -2644,8 +2751,8 @@ handle_address_lookup (void *cls, if (NULL == lsPlugin) { tc = GNUNET_SERVER_transmit_context_create (client); - GNUNET_SERVER_transmit_context_append (tc, NULL, 0, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); GNUNET_SERVER_transmit_context_run (tc, rtimeout); return; } @@ -2743,6 +2850,8 @@ client_disconnect_notification (void *cls, struct TransportClient *prev; struct ClientMessageQueueEntry *mqe; + if (client == NULL) + return; #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Client disconnected, cleaning up.\n"); @@ -2889,6 +2998,7 @@ run (void *cls, &unload_plugins, NULL); if (no_transports) refresh_hello (); + #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport service ready.\n")); #endif