/*
This file is part of GNUnet.
- (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009, 2010, 2011 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__)
+#define DEBUG(...) \
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
/**
* Linked list of messages to send to clients.
*/
/**
* Task that re-transmits requests (using retry_heap).
*/
-static GNUNET_SCHEDULER_TaskIdentifier retry_task;
+static struct GNUNET_SCHEDULER_Task * retry_task;
/**
reply);
memcpy (&cbuf[off], reply->msg, msize);
GNUNET_free (reply);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n",
- msize, client->client_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting %u bytes to client %p\n",
+ (unsigned int) msize,
+ client->client_handle);
off += msize;
}
process_pending_messages (client);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n",
- (unsigned int) off, (unsigned int) size, client->client_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitted %u/%u bytes to client %p\n",
+ (unsigned int) off,
+ (unsigned int) size,
+ client->client_handle);
return off;
}
unsigned int i;
LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
- "R5N CLIENT-RESULT %s\n",
+ "XVINE CLIENT-RESULT %s\n",
GNUNET_h2s_full (key));
+#if 0
if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Record type missmatch, not passing request for key %s to local client\n",
GNUNET_h2s (key));
+
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop
("# Key match, type mismatches in REPLY to CLIENT"),
1, GNUNET_NO);
return GNUNET_YES; /* type mismatch */
}
+#endif
GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch);
for (i = 0; i < record->seen_replies_count; i++)
if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (struct GNUNET_HashCode)))
return GNUNET_YES; /* duplicate */
}
eval =
- GNUNET_BLOCK_evaluate (GDS_block_context, record->type, key, NULL, 0,
- record->xquery, record->xquery_size, frc->data,
+ GNUNET_BLOCK_evaluate (GDS_block_context,
+ record->type,
+ GNUNET_BLOCK_EO_NONE,
+ key, NULL, 0,
+ record->xquery,
+ record->xquery_size,
+ frc->data,
frc->data_size);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Evaluation result is %d for key %s for local client's query\n",
_("Could not pass reply to client, message too big!\n"));
return;
}
+ DEBUG("reply FOR DATA_SIZE = %lu\n",msize);
pm = GNUNET_malloc (msize + sizeof (struct PendingMessage));
reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
pm->msg = &reply->header;
frc.type = type;
GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply,
&frc);
-
if (GNUNET_NO == frc.do_copy)
{
/* did not match any of the requests, free! */
/**
- * Route the given request via the DHT.
+ * Route the given request via the DHT.
*/
static void
transmit_request (struct ClientQueryRecord *cqr)
gettext_noop
("# GET requests from clients injected"), 1,
GNUNET_NO);
-
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Initiating GET for %s, replication %u, already have %u replies\n",
GNUNET_h2s (&cqr->key),
cqr->replication,
cqr->seen_replies_count);
- /* FIXME: Here I am passing NULL for parameters check if its correct or
- not. */
-#if 0
- GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication,
- 0 /* hop count */ ,NULL, NULL, 0,
- &cqr->key, NULL, NULL, 0);
-#endif
+ GDS_NEIGHBOURS_handle_get (&cqr->key, cqr->type, cqr->msg_options,
+ cqr->replication);
+
/* exponential back-off for retries.
* max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency);
* itself (unless the heap is empty).
*
* @param cls unused
- * @param tc scheduler context
*/
static void
-transmit_next_request_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_next_request_task (void *cls)
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
- retry_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ retry_task = NULL;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
struct PendingMessage *pm;
struct GNUNET_DHT_ClientPutConfirmationMessage *conf;
uint16_t size;
-
+
size = ntohs (message->size);
if (size < sizeof (struct GNUNET_DHT_ClientPutMessage))
{
("# PUT requests received from clients"), 1,
GNUNET_NO);
put_msg = (const struct GNUNET_DHT_ClientPutMessage *) message;
- LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "R5N CLIENT-PUT %s\n",
+ LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "X-VINE DHT CLIENT-PUT %s\n",
GNUNET_h2s_full (&put_msg->key));
/* give to local clients */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Handling local PUT of %u-bytes for query %s\n",
size - sizeof (struct GNUNET_DHT_ClientPutMessage),
GNUNET_h2s (&put_msg->key));
-
+ DEBUG("PUT doing put i = %s\n",GNUNET_h2s(&(put_msg->key)));
GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put_msg->expiration),
&put_msg->key, 0, NULL, 0, NULL,
ntohl (put_msg->type),
size - sizeof (struct GNUNET_DHT_ClientPutMessage),
&put_msg[1]);
- /* FIXME: Should we store locally? */
- GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put_msg->expiration),
- &put_msg->key, 0, NULL, ntohl (put_msg->type),
- size - sizeof (struct GNUNET_DHT_ClientPutMessage),
- &put_msg[1]);
-
- /* FIXME: Is it correct to pass NULL for current destination and current
- source. */
- GDS_NEIGHBOURS_handle_put (ntohl (put_msg->type), ntohl (put_msg->options),
- ntohl (put_msg->desired_replication_level),
- GNUNET_TIME_absolute_ntoh (put_msg->expiration),
- 0 /* hop count */ ,
- &put_msg->key, 0, NULL, &put_msg[1],
- size -
- sizeof (struct GNUNET_DHT_ClientPutMessage),
- NULL, NULL, 0, NULL);
-
- GDS_CLIENTS_process_put (ntohl (put_msg->options),
- ntohl (put_msg->type),
- 0,
- ntohl (put_msg->desired_replication_level),
- 1,
- GDS_NEIGHBOURS_get_id(),
- GNUNET_TIME_absolute_ntoh (put_msg->expiration),
- &put_msg->key,
- &put_msg[1],
- size - sizeof (struct GNUNET_DHT_ClientPutMessage));
-
+
+ GDS_NEIGHBOURS_handle_put (&put_msg->key,
+ ntohl (put_msg->type), ntohl (put_msg->options),
+ ntohl (put_msg->desired_replication_level),
+ GNUNET_TIME_absolute_ntoh (put_msg->expiration),
+ &put_msg[1],
+ size - sizeof (struct GNUNET_DHT_ClientPutMessage));
pm = GNUNET_malloc (sizeof (struct PendingMessage) +
sizeof (struct GNUNET_DHT_ClientPutConfirmationMessage));
conf = (struct GNUNET_DHT_ClientPutConfirmationMessage *) &pm[1];
"Received GET request for %s from local client %p, xq: %.*s\n",
GNUNET_h2s (&get->key), client, xquery_size, xquery);
- LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "R5N CLIENT-GET %s\n",
+ LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "X-VINE CLIENT-GET %s\n",
GNUNET_h2s_full (&get->key));
cqr->replication = ntohl (get->desired_replication_level);
cqr->msg_options = ntohl (get->options);
cqr->type = ntohl (get->type);
+
// FIXME use cqr->key, set multihashmap create to GNUNET_YES
GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+
+ struct GNUNET_PeerIdentity my_identity;
+ my_identity = GDS_NEIGHBOURS_get_my_id();
GDS_CLIENTS_process_get (ntohl (get->options),
ntohl (get->type),
0,
ntohl (get->desired_replication_level),
1,
- GDS_NEIGHBOURS_get_id(),
+ &my_identity,
&get->key);
/* start remote requests */
- if (GNUNET_SCHEDULER_NO_TASK != retry_task)
+ if (NULL != retry_task)
GNUNET_SCHEDULER_cancel (retry_task);
retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL);
- /* perform local lookup
- * FIXME: Should we call it here or in neighbours file. And how to handle
- * this case where we may get the data locally. You really need to rethink
- * this design again.
- GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size,
- NULL, 0); */
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
}
+#if ENABLE_MALICIOUS
+/**
+ * Handler for act malicious message.
+ *
+ * @param cls closure for the service
+ * @param client the client we received this message from
+ * @param message the actual message received
+ *
+ */
+static void
+handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ const struct GNUNET_DHT_ActMaliciousMessage *msg;
+ struct PendingMessage *pm;
+ struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *conf;
+ unsigned int malicious_action;
+
+ msg = (const struct GNUNET_DHT_ActMaliciousMessage *)message;
+ malicious_action = msg->action;
+
+ if(GNUNET_OK == GDS_NEIGHBOURS_act_malicious (malicious_action))
+ {
+ pm = GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage));
+ conf = (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *) &pm[1];
+ conf->header.size = htons (sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage));
+ conf->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK);
+ pm->msg = &conf->header;
+ add_pending_message (find_active_client (client), pm);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ }
+}
+#endif
+
+
/**
* Functions with this signature are called whenever a client
* is disconnected on the network level.
sizeof (struct GNUNET_DHT_MonitorStartStopMessage)},
{&handle_dht_local_get_result_seen, NULL,
GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0},
+ #if ENABLE_MALICIOUS
+ {&handle_dht_act_malicious, NULL,
+ GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS,
+ sizeof (struct GNUNET_DHT_ActMaliciousMessage)},
+ #endif
{NULL, NULL, 0, 0}
};
forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
{
GNUNET_assert (client_head == NULL);
GNUNET_assert (client_tail == NULL);
- if (GNUNET_SCHEDULER_NO_TASK != retry_task)
+ if (NULL != retry_task)
{
GNUNET_SCHEDULER_cancel (retry_task);
- retry_task = GNUNET_SCHEDULER_NO_TASK;
+ retry_task = NULL;
}
if (NULL != retry_heap)
{