/*
This file is part of GNUnet.
- Copyright (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009, 2010, 2011, 2016 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.
*/
/**
#include "gnunet_statistics_service.h"
#include "gnunet-service-wdht.h"
#include "gnunet-service-wdht_clients.h"
-#include "gnunet-service-wdht_datacache.h"
+#include "gnunet-service-dht_datacache.h"
#include "gnunet-service-wdht_neighbours.h"
#include "dht.h"
/**
* Actual message to be sent, allocated at the end of the struct:
* // msg = (cast) &pm[1];
- * // memcpy (&pm[1], data, len);
+ * // GNUNET_memcpy (&pm[1], data, len);
*/
const struct GNUNET_MessageHeader *msg;
size_t xquery_size;
/**
- * Number of entries in 'seen_replies'.
+ * Number of entries in @e seen_replies.
*/
unsigned int seen_replies_count;
/**
- * Callback called as a result of issuing a GNUNET_SERVER_notify_transmit_ready
+ * Callback called as a result of issuing a #GNUNET_SERVER_notify_transmit_ready()
* request. A ClientList is passed as closure, take the head of the list
* and copy it into buf, which has the result of sending the message to the
* client.
{
GNUNET_CONTAINER_DLL_remove (client->pending_head, client->pending_tail,
reply);
- memcpy (&cbuf[off], reply->msg, msize);
+ GNUNET_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;
}
/**
- * Closure for 'forward_reply'
+ * Closure for #forward_reply()
*/
struct ForwardReplyContext
{
size_t data_size;
/**
- * Do we need to copy 'pm' because it was already used?
+ * Do we need to copy @e pm because it was already used?
*/
int do_copy;
* each of the matching clients. With some tricky recycling
* of the buffer.
*
- * @param cls the 'struct ForwardReplyContext'
+ * @param cls the `struct ForwardReplyContext`
* @param key current key
* @param value value in the hash map, a ClientQueryRecord
* @return #GNUNET_YES (we should continue to iterate),
* if the result is mal-formed, #GNUNET_NO
*/
static int
-forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value)
+forward_reply (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
{
struct ForwardReplyContext *frc = cls;
struct ClientQueryRecord *record = value;
/* two clients waiting for same reply, must copy for queueing */
pm = GNUNET_malloc (sizeof (struct PendingMessage) +
ntohs (frc->pm->msg->size));
- memcpy (pm, frc->pm,
+ GNUNET_memcpy (pm, frc->pm,
sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size));
pm->next = pm->prev = NULL;
pm->msg = (struct GNUNET_MessageHeader *) &pm[1];
_("Could not pass reply to client, message too big!\n"));
return;
}
- DEBUG("reply FOR DATA_SIZE = %lu\n",msize);
+ DEBUG ("reply FOR DATA_SIZE = %u\n",
+ (unsigned int) msize);
pm = GNUNET_malloc (msize + sizeof (struct PendingMessage));
reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
pm->msg = &reply->header;
reply->expiration = GNUNET_TIME_absolute_hton (expiration);
reply->key = *key;
paths = (struct GNUNET_PeerIdentity *) &reply[1];
- memcpy (paths, put_path,
- sizeof (struct GNUNET_PeerIdentity) * put_path_length);
- memcpy (&paths[put_path_length], get_path,
- sizeof (struct GNUNET_PeerIdentity) * get_path_length);
- memcpy (&paths[get_path_length + put_path_length], data, data_size);
+ GNUNET_memcpy (paths,
+ put_path,
+ sizeof (struct GNUNET_PeerIdentity) * put_path_length);
+ GNUNET_memcpy (&paths[put_path_length],
+ get_path,
+ sizeof (struct GNUNET_PeerIdentity) * get_path_length);
+ GNUNET_memcpy (&paths[get_path_length + put_path_length],
+ data,
+ data_size);
frc.do_copy = GNUNET_NO;
frc.pm = pm;
frc.data = data;
frc.data_size = data_size;
frc.type = type;
- GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply,
+ GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
+ key,
+ &forward_reply,
&frc);
if (GNUNET_NO == frc.do_copy)
{
}
}
+
/**
* Check if some client is monitoring GET messages and notify
* them in that case.
uint32_t desired_replication_level,
unsigned int path_length,
const struct GNUNET_PeerIdentity *path,
- const struct GNUNET_HashCode * key)
+ const struct GNUNET_HashCode *key)
{
struct ClientMonitorRecord *m;
struct ClientList **cl;
mmsg->hop_count = htonl(hop_count);
mmsg->desired_replication_level = htonl(desired_replication_level);
mmsg->get_path_length = htonl(path_length);
- memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
+ GNUNET_memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1];
if (path_length > 0)
- memcpy (msg_path, path,
+ GNUNET_memcpy (msg_path, path,
path_length * sizeof (struct GNUNET_PeerIdentity));
add_pending_message (m->client, pm);
}
* Check if some client is monitoring PUT messages and notify
* them in that case.
*
- * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
- * @param type The type of data in the request.
- * @param hop_count Hop count so far.
- * @param path_length number of entries in path (or 0 if not recorded).
+ * @param options options, for instance RecordRoute, DemultiplexEverywhere.
+ * @param type type of data in the request.
+ * @param hop_count hop count so far.
+ * @param path_length number of entries in @a path (or 0 if not recorded).
* @param path peers on the PUT path (or NULL if not recorded).
- * @param desired_replication_level Desired replication level.
- * @param exp Expiration time of the data.
- * @param key Key under which data is to be stored.
- * @param data Pointer to the data carried.
- * @param size Number of bytes in data.
+ * @param desired_replication_level desired replication level.
+ * @param exp expiration time of the data.
+ * @param key key under which @a data is to be stored.
+ * @param data pointer to the data carried.
+ * @param size number of bytes in @a data.
*/
void
GDS_CLIENTS_process_put (uint32_t options,
msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1];
if (path_length > 0)
{
- memcpy (msg_path, path,
+ GNUNET_memcpy (msg_path, path,
path_length * sizeof (struct GNUNET_PeerIdentity));
}
mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp);
- memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
+ GNUNET_memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
if (size > 0)
- memcpy (&msg_path[path_length], data, size);
+ GNUNET_memcpy (&msg_path[path_length], data, size);
add_pending_message (m->client, pm);
}
}
* 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 = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
* @param message the actual message received
*/
static void
-handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
+handle_dht_local_put (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ClientPutMessage *put_msg;
* @param message the actual message received
*/
static void
-handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client,
+handle_dht_local_get (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ClientGetMessage *get;
cqr->key = get->key;
cqr->client = find_active_client (client);
cqr->xquery = (void *) &cqr[1];
- memcpy (&cqr[1], xquery, xquery_size);
+ GNUNET_memcpy (&cqr[1], xquery, xquery_size);
cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0);
cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS;
cqr->retry_time = GNUNET_TIME_absolute_get ();
/**
- * Closure for 'find_by_unique_id'.
+ * Closure for #find_by_unique_id().
*/
struct FindByUniqueIdContext
{
*/
struct ClientQueryRecord *cqr;
+ /**
+ * Which ID are we looking for?
+ */
uint64_t unique_id;
};
*
* @param cls the search context
* @param key query for the lookup (not used)
- * @param value the 'struct ClientQueryRecord'
- * @return GNUNET_YES to continue iteration (result not yet found)
+ * @param value the `struct ClientQueryRecord`
+ * @return #GNUNET_YES to continue iteration (result not yet found)
*/
static int
find_by_unique_id (void *cls,
* @param message the actual message received
*/
static void
-handle_dht_local_get_result_seen (void *cls, struct GNUNET_SERVER_Client *client,
+handle_dht_local_get_result_seen (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ClientGetResultSeenMessage *seen;
GNUNET_array_grow (cqr->seen_replies,
cqr->seen_replies_count,
cqr->seen_replies_count + hash_count);
- memcpy (&cqr->seen_replies[old_count],
+ GNUNET_memcpy (&cqr->seen_replies[old_count],
hc,
sizeof (struct GNUNET_HashCode) * hash_count);
}
/**
- * Closure for 'remove_by_unique_id'.
+ * Closure for #remove_by_unique_id().
*/
struct RemoveByUniqueIdContext
{
* @return #GNUNET_YES (we should continue to iterate)
*/
static int
-remove_by_unique_id (void *cls, const struct GNUNET_HashCode * key, void *value)
+remove_by_unique_id (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
{
const struct RemoveByUniqueIdContext *ctx = cls;
struct ClientQueryRecord *record = value;
*
*/
static void
-handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client,
+handle_dht_local_get_stop (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg =
GNUNET_NO);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received GET STOP request for %s from local client %p\n",
- client, GNUNET_h2s (&dht_stop_msg->key));
+ GNUNET_h2s (&dht_stop_msg->key),
+ client);
ctx.client = find_active_client (client);
ctx.unique_id = dht_stop_msg->unique_id;
GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, &dht_stop_msg->key,
*
*/
static void
-handle_dht_local_monitor (void *cls, struct GNUNET_SERVER_Client *client,
+handle_dht_local_monitor (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct ClientMonitorRecord *r;
else
{
r->key = GNUNET_new (struct GNUNET_HashCode);
- memcpy (r->key, &msg->key, sizeof (struct GNUNET_HashCode));
+ GNUNET_memcpy (r->key, &msg->key, sizeof (struct GNUNET_HashCode));
}
GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, r);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
* @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_local_monitor_stop (void *cls, struct GNUNET_SERVER_Client *client,
+handle_dht_local_monitor_stop (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct ClientMonitorRecord *r;
}
-
/**
* Initialize client subsystem.
*