- if (service_context != NULL)
- {
- n = service_context->neighbour;
- GNUNET_assert (n != NULL);
- }
- else
- {
- n = find_neighbour (peer);
- if (n == NULL)
- {
- if (message == NULL)
- return NULL; /* disconnect of peer already marked down */
- n = setup_new_neighbour (peer);
- }
- service_context = n->plugins;
- while ((service_context != NULL) && (plugin != service_context->plugin))
- service_context = service_context->next;
- GNUNET_assert ((plugin->api->send == NULL) ||
- (service_context != NULL));
- }
- if (message == NULL)
- {
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Receive failed from `%4s', triggering disconnect\n",
- GNUNET_i2s(&n->id));
-#endif
- /* TODO: call stats */
- if ((service_context != NULL) &&
- (service_context->plugin_handle == plugin_context))
- {
- service_context->connected = GNUNET_NO;
- service_context->plugin_handle = NULL;
- }
- disconnect_neighbour (n, GNUNET_YES);
- return NULL;
- }
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Processing message of type `%u' received by plugin...\n",
- ntohs (message->type));
-#endif
- if (service_context != NULL)
- {
- if (service_context->connected == GNUNET_NO)
- {
- service_context->connected = GNUNET_YES;
- service_context->transmit_ready = GNUNET_YES;
- service_context->connect_attempts++;
- }
- service_context->timeout
- = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- service_context->plugin_handle = plugin_context;
- service_context->latency = latency;
- }
- /* update traffic received amount ... */
- msize = ntohs (message->size);
- n->last_received += msize;
- GNUNET_SCHEDULER_cancel (sched, n->timeout_task);
- n->peer_timeout =
- GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- n->timeout_task =
- GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &neighbour_timeout_task, n);
- update_quota (n);
- if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
- {
- /* dropping message due to frequent inbound volume violations! */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK,
- _
- ("Dropping incoming message due to repeated bandwidth quota violations.\n"));
- /* TODO: call stats */
- GNUNET_assert ( (service_context == NULL) ||
- (NULL != service_context->neighbour) );
- return service_context;
- }
- switch (ntohs (message->type))
- {
- case GNUNET_MESSAGE_TYPE_HELLO:
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving `%s' message from `%4s'.\n", "HELLO",
- GNUNET_i2s(peer));
-#endif
- process_hello (plugin, message);
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message to connecting peer `%4s'.\n", "ACK",
- GNUNET_i2s(peer));
-#endif
- transmit_to_peer (NULL, 0, &ack, GNUNET_YES, n);
- break;
- case GNUNET_MESSAGE_TYPE_TRANSPORT_ACK:
- n->saw_ack = GNUNET_YES;
- /* intentional fall-through! */
- default:
+ n = find_neighbour (peer);
+ if (n == NULL)
+ n = setup_new_neighbour (peer);
+ update_quota (n, GNUNET_NO);
+ service_context = n->plugins;
+ while ((service_context != NULL) && (plugin != service_context->plugin))
+ service_context = service_context->next;
+ GNUNET_assert ((plugin->api->send == NULL) || (service_context != NULL));
+ if (message != NULL)
+ {
+ peer_address = add_peer_address(n,
+ plugin->short_name,
+ sender_address,
+ sender_address_len);
+ if (peer_address != NULL)
+ {
+ peer_address->distance = distance;
+ if (peer_address->connected == GNUNET_NO)
+ {
+ peer_address->connected = GNUNET_YES;
+ peer_address->connect_attempts++;
+ }
+ peer_address->timeout
+ =
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ }
+ /* update traffic received amount ... */
+ msize = ntohs (message->size);
+ n->distance = distance;
+ n->peer_timeout =
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_SCHEDULER_cancel (sched,
+ n->timeout_task);
+ n->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (sched,
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &neighbour_timeout_task, n);
+ if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
+ {
+ /* dropping message due to frequent inbound volume violations! */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
+ GNUNET_ERROR_TYPE_BULK,
+ _
+ ("Dropping incoming message due to repeated bandwidth quota violations (total of %u).\n"),
+ n->quota_violation_count);
+ return GNUNET_TIME_UNIT_MINUTES; /* minimum penalty, likely ignored (UDP...) */
+ }
+ switch (ntohs (message->type))
+ {
+ case GNUNET_MESSAGE_TYPE_HELLO:
+ process_hello (plugin, message);
+ 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;
+ default: