* Called both for locally initiated requests and those
* received from other peers.
*
- * @param cls DHT service closure argument
* @param msg the encapsulated message
* @param peer the peer to forward the message to
* @param msg_ctx the context of the message (hop count, bloom, etc.)
*/
static void
-forward_result_message (void *cls,
- const struct GNUNET_MessageHeader *msg,
+forward_result_message (const struct GNUNET_MessageHeader *msg,
struct PeerInfo *peer,
struct DHT_MessageContext *msg_ctx)
{
}
-
-
/**
* Called when a reply needs to be sent to a client, as
* a result it found to a GET or FIND PEER request.
* Main function that handles whether or not to route a result
* message to other peers, or to send to our local client.
*
- * @param cls closure (unused, always should be NULL)
* @param msg the result message to be routed
* @param message_context context of the message we are routing
*
* @return the number of peers the message was routed to,
* GNUNET_SYSERR on failure
*/
-static int route_result_message(void *cls,
- struct GNUNET_MessageHeader *msg,
+static int route_result_message(struct GNUNET_MessageHeader *msg,
struct DHT_MessageContext *message_context)
{
struct GNUNET_PeerIdentity new_peer;
message_context->peer, &pos->source);
}
#endif
- forward_result_message(cls, msg, peer_info, message_context);
+ forward_result_message(msg, peer_info, message_context);
}
else
{
new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make result routing a higher priority */
new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
increment_stats(STAT_GET_RESPONSE_START);
- route_result_message(cls, &get_result->header, new_msg_ctx);
+ route_result_message(&get_result->header, new_msg_ctx);
GNUNET_free(new_msg_ctx);
GNUNET_free (get_result);
break;
* @param message_context the context containing all pertinent information about the message
*/
static void
-route_message2(const struct GNUNET_MessageHeader *msg,
+route_message(const struct GNUNET_MessageHeader *msg,
struct DHT_MessageContext *message_context);
* Server handler for all dht get requests, look for data,
* if found, send response either to clients or other peers.
*
- * @param cls closure for service
* @param msg the actual get message
* @param message_context struct containing pertinent information about the get request
*
* @return number of items found for GET request
*/
static unsigned int
-handle_dht_get (void *cls,
- const struct GNUNET_MessageHeader *msg,
+handle_dht_get (const struct GNUNET_MessageHeader *msg,
struct DHT_MessageContext *message_context)
{
const struct GNUNET_DHT_GetMessage *get_msg;
#endif
}
if (message_context->do_forward == GNUNET_YES)
- route_message2 (msg, message_context);
+ route_message (msg, message_context);
GNUNET_CONTAINER_bloomfilter_free (message_context->reply_bf);
return results;
}
/**
* Server handler for initiating local dht find peer requests
*
- * @param cls closure for service
* @param find_msg the actual find peer message
* @param message_context struct containing pertinent information about the request
*
*/
static void
-handle_dht_find_peer (void *cls,
- const struct GNUNET_MessageHeader *find_msg,
+handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
struct DHT_MessageContext *message_context)
{
struct GNUNET_MessageHeader *find_peer_result;
increment_stats(STAT_HELLOS_PROVIDED);
GNUNET_TRANSPORT_offer_hello(transport_handle, other_hello);
GNUNET_CORE_peer_request_connect(sched, cfg, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), &peer_id, NULL, NULL);
- route_message2 (find_msg, message_context);
+ route_message (find_msg, message_context);
GNUNET_free (other_hello);
return;
}
else /* We don't want this peer! */
{
- route_message2 (find_msg, message_context);
+ route_message (find_msg, message_context);
return;
}
#endif
"DHT");
#endif
GNUNET_free_non_null (other_hello);
- route_message2 (find_msg, message_context);
+ route_message (find_msg, message_context);
return;
}
increment_stats(STAT_BLOOM_FIND_PEER);
GNUNET_CONTAINER_bloomfilter_free(incoming_bloom);
GNUNET_free_non_null(other_hello);
- route_message2 (find_msg, message_context);
+ route_message (find_msg, message_context);
return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/
}
GNUNET_CONTAINER_bloomfilter_free(incoming_bloom);
{
increment_stats("# dht find peer requests ignored (do not need!)");
GNUNET_free_non_null(other_hello);
- route_message2 (find_msg, message_context);
+ route_message (find_msg, message_context);
return;
}
#endif
new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make find peer requests a higher priority */
new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
increment_stats(STAT_FIND_PEER_ANSWER);
- route_result_message(cls, find_peer_result, new_msg_ctx);
+ route_result_message(find_peer_result, new_msg_ctx);
GNUNET_free(new_msg_ctx);
#if DEBUG_DHT_ROUTING
if ((debug_routes) && (dhtlog_handle != NULL))
#endif
GNUNET_free_non_null(other_hello);
GNUNET_free(find_peer_result);
- route_message2 (find_msg, message_context);
+ route_message (find_msg, message_context);
}
/**
/**
* Server handler for initiating local dht put requests
*
- * @param cls closure for service
* @param msg the actual put message
* @param message_context struct containing pertinent information about the request
*/
static void
-handle_dht_put (void *cls,
- const struct GNUNET_MessageHeader *msg,
+handle_dht_put (const struct GNUNET_MessageHeader *msg,
struct DHT_MessageContext *message_context)
{
const struct GNUNET_DHT_PutMessage *put_msg;
if (message_context->closest != GNUNET_YES)
{
- route_message2 (msg, message_context);
+ route_message (msg, message_context);
return;
}
my_short_id, "DHT", "PUT");
if (stop_on_closest == GNUNET_NO)
- route_message2 (msg, message_context);
+ route_message (msg, message_context);
}
/**
* received we can either forward it to the correct peer
* or return the result locally.
*
- * @param cls DHT service closure
* @param msg_ctx Context of the route request
*
* @return GNUNET_YES if this response was cached, GNUNET_NO if not
*/
-static int cache_response(void *cls, struct DHT_MessageContext *msg_ctx)
+static int cache_response(struct DHT_MessageContext *msg_ctx)
{
struct DHTQueryRecord *record;
struct DHTRouteSource *source_info;
* @param message_context the context containing all pertinent information about the message
*/
static void
-route_message2(const struct GNUNET_MessageHeader *msg,
+route_message(const struct GNUNET_MessageHeader *msg,
struct DHT_MessageContext *message_context)
{
int i;
* Main function that handles whether or not to route a message to other
* peers.
*
- * @param cls closure for dht service (NULL)
* @param msg the message to be routed
* @param message_context the context containing all pertinent information about the message
*/
static void
-route_message(void *cls,
- const struct GNUNET_MessageHeader *msg,
- struct DHT_MessageContext *message_context)
+demultiplex_message(const struct GNUNET_MessageHeader *msg,
+ struct DHT_MessageContext *message_context)
{
message_context->closest = am_closest_peer(&message_context->key, NULL);
switch (ntohs(msg->type))
{
case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen, search for data (always) */
- cache_response (cls, message_context);
- handle_dht_get (cls, msg, message_context);
+ cache_response (message_context);
+ handle_dht_get (msg, message_context);
break;
case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. */
increment_stats(STAT_PUTS);
- handle_dht_put (cls, msg, message_context);
+ handle_dht_put (msg, message_context);
break;
case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */
increment_stats(STAT_FIND_PEER);
if (((message_context->hop_count > 0) && (0 != memcmp(message_context->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) || (message_context->client != NULL))
{
- cache_response (cls, message_context);
+ cache_response (message_context);
if ((message_context->closest == GNUNET_YES) || (message_context->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE))
- handle_dht_find_peer (cls, msg, message_context);
+ handle_dht_find_peer (msg, message_context);
}
+ else
+ route_message (msg, message_context);
#if DEBUG_DHT_ROUTING
if (message_context->hop_count == 0) /* Locally initiated request */
{
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "`%s': Message type (%d) not handled\n", "DHT", ntohs(msg->type));
- route_message (cls, msg, message_context);
+ "`%s': Message type (%d) not handled, forwarding anyway!\n", "DHT", ntohs(msg->type));
+ route_message (msg, message_context);
}
}
new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE;
new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
increment_stats(STAT_PUT_START);
- route_message(cls, &put_msg->header, new_msg_ctx);
+ demultiplex_message(&put_msg->header, new_msg_ctx);
GNUNET_free(new_msg_ctx);
GNUNET_free (put_msg);
#endif
increment_stats(STAT_PUT_START);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s Sending malicious PUT message with hash %s\n", my_short_id, "DHT", GNUNET_h2s(&key));
- route_message(NULL, &put_message.header, &message_context);
+ demultiplex_message(&put_message.header, &message_context);
GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, malicious_put_frequency), &malicious_put_task, NULL);
}
#endif
increment_stats(STAT_GET_START);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s Sending malicious GET message with hash %s\n", my_short_id, "DHT", GNUNET_h2s(&key));
- route_message (NULL, &get_message.header, &message_context);
+ demultiplex_message (&get_message.header, &message_context);
GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, malicious_get_frequency), &malicious_get_task, NULL);
}
message_context.importance = DHT_DEFAULT_FIND_PEER_IMPORTANCE;
message_context.timeout = DHT_DEFAULT_FIND_PEER_TIMEOUT;
- route_message(NULL, &find_peer_msg->header, &message_context);
+ demultiplex_message(&find_peer_msg->header, &message_context);
GNUNET_free(find_peer_msg);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s:%s': Sent `%s' request to some (?) peers\n", my_short_id, "DHT",
else if (ntohs(enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)
increment_stats(STAT_FIND_PEER_START);
- route_message(cls, enc_msg, &message_context);
+ demultiplex_message(enc_msg, &message_context);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
message_context->peer = peer;
message_context->importance = DHT_DEFAULT_P2P_IMPORTANCE;
message_context->timeout = DHT_DEFAULT_P2P_TIMEOUT;
- route_message(cls, enc_msg, message_context);
+ demultiplex_message(enc_msg, message_context);
GNUNET_free(message_context);
return GNUNET_YES;
}
message_context.peer = peer;
message_context.importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make result routing a higher priority */
message_context.timeout = DHT_DEFAULT_P2P_TIMEOUT;
- route_result_message(cls, enc_msg, &message_context);
+ route_result_message(enc_msg, &message_context);
return GNUNET_YES;
}