/**
* Struct containing information about a client of the service
- *
+ *
* TODO: add a list of 'waiting' ports
*/
struct MeshClient
static unsigned long long max_tunnels;
/**
- * How many messages *in total* are we willing to queue, divided by number of
+ * How many messages *in total* are we willing to queue, divided by number of
* tunnels to get tunnel queue size.
*/
static unsigned long long max_msgs_queue;
/**
* Peers known, indexed by PeerIdentity (MeshPeer).
*/
-static struct GNUNET_CONTAINER_MultiHashMap *peers;
+static struct GNUNET_CONTAINER_MultiPeerMap *peers;
/*
* Handle to communicate with transport
/**
* Own private key.
*/
-static struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
-
-/**
- * Own public key.
- */
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
/**
* Tunnel ID for the next created tunnel (global tunnel number).
* @brief Use the given path for the tunnel.
* Update the next and prev hops (and RCs).
* (Re)start the path refresh in case the tunnel is locally owned.
- *
+ *
* @param t Tunnel to update.
* @param p Path to use.
*/
/**
* Tunnel is empty: destroy it.
- *
+ *
* Notifies all participants (peers, cleints) about the destruction.
- *
- * @param t Tunnel to destroy.
+ *
+ * @param t Tunnel to destroy.
*/
static void
tunnel_destroy_empty (struct MeshTunnel *t);
/**
* @brief Queue and pass message to core when possible.
- *
+ *
* If type is payload (UNICAST, TO_ORIGIN, MULTICAST) checks for queue status
* and accounts for it. In case the queue is full, the message is dropped and
* a break issued.
- *
- * Otherwise, message is treated as internal and allowed to go regardless of
+ *
+ * Otherwise, message is treated as internal and allowed to go regardless of
* queue status.
*
* @param cls Closure (@c type dependant). It will be used by queue_send to
announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PBlock block;
+ struct GNUNET_HashCode phash;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
* - Adapt X to churn
*/
DEBUG_DHT ("DHT_put for ID %s started.\n", GNUNET_i2s (&my_full_id));
-
+ GNUNET_CRYPTO_hash (&my_full_id, sizeof (my_full_id), &phash);
block.id = my_full_id;
GNUNET_DHT_put (dht_handle, /* DHT handle */
- &my_full_id.hashPubKey, /* Key to use */
+ &phash,
dht_replication_level, /* Replication level */
GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
GNUNET_BLOCK_TYPE_MESH_PEER, /* Block type */
/**
* Build a local ACK message and send it to a local client.
- *
+ *
* @param t Tunnel on which to send the ACK.
* @param c Client to whom send the ACK.
* @param is_fwd Set to GNUNET_YES for FWD ACK (dest->owner)
* @param t Tunnel which to confirm.
*/
static void
-send_path_ack (struct MeshTunnel *t)
+send_path_ack (struct MeshTunnel *t)
{
struct MeshPeer *neighbor;
/**
* Build an ACK message and queue it to send to the given peer.
- *
+ *
* @param t Tunnel on which to send the ACK.
* @param peer Peer to whom send the ACK.
* @param ack Value of the ACK.
*/
static int
peer_timeout (void *cls,
- const struct GNUNET_HashCode *key,
+ const struct GNUNET_PeerIdentity *key,
void *value)
{
return GNUNET_YES;
{
struct MeshPeer *peer;
- peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer_id->hashPubKey);
+ peer = GNUNET_CONTAINER_multipeermap_get (peers, peer_id);
if (NULL == peer)
{
- peer = (struct MeshPeer *) GNUNET_malloc (sizeof (struct MeshPeer));
- if (GNUNET_CONTAINER_multihashmap_size (peers) > max_peers)
+ peer = GNUNET_new (struct MeshPeer);
+ if (GNUNET_CONTAINER_multipeermap_size (peers) > max_peers)
{
- GNUNET_CONTAINER_multihashmap_iterate (peers,
+ GNUNET_CONTAINER_multipeermap_iterate (peers,
&peer_timeout,
NULL);
}
- GNUNET_CONTAINER_multihashmap_put (peers, &peer_id->hashPubKey, peer,
+ GNUNET_CONTAINER_multipeermap_put (peers, peer_id, peer,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
peer->id = GNUNET_PEER_intern (peer_id);
}
*
* @param pi Peer we want to poll.
* @param t Tunnel about which we want to poll.
- *
+ *
* @return PID to use, either last sent or first_in_queue - 1
*/
static uint32_t
/**
* Choose the best path towards a peer considering the tunnel properties.
- *
+ *
* @param peer The destination peer.
* @param t The tunnel the path is for.
*
peer_connect (struct MeshPeer *peer, struct MeshTunnel *t)
{
struct MeshPeerPath *p;
+ struct GNUNET_HashCode phash;
if (NULL != peer->path_head)
{
GNUNET_PEER_resolve (peer->id, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " Starting DHT GET for peer %s\n", GNUNET_i2s (&id));
+ "Starting DHT GET for peer %s\n",
+ GNUNET_i2s (&id));
+ GNUNET_CRYPTO_hash (&id, sizeof (my_full_id), &phash);
peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
GNUNET_BLOCK_TYPE_MESH_PEER, /* type */
- &id.hashPubKey, /* key to search */
+ &phash, /* key to search */
dht_replication_level, /* replication level */
GNUNET_DHT_RO_RECORD_ROUTE |
GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
GNUNET_PEER_change_rc (peer->id, -1);
if (GNUNET_YES !=
- GNUNET_CONTAINER_multihashmap_remove (peers, &id.hashPubKey, peer))
+ GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
/**
* Add a tunnel to the list of tunnels a peer participates in.
* Update the tunnel's destination.
- *
+ *
* @param p Peer to add to.
* @param t Tunnel to add.
*/
/**
* Remove a tunnel from the list of tunnels a peer participates in.
* Free the tunnel's destination.
- *
+ *
* @param p Peer to clean.
* @param t Tunnel to remove.
*/
GNUNET_break (0);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** peer: %s!\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** peer: %s!\n",
GNUNET_i2s(GNUNET_PEER_resolve2 (peer)));
if (0 == peer)
{
/**
* Add a client to a tunnel, initializing all needed data structures.
- *
+ *
* @param t Tunnel to which add the client.
* @param c Client which to add to the tunnel.
*/
// {
// return;
// }
-//
+//
// if (tree_get_predecessor (t->tree) != 0)
// {
// /* We are the peer still connected, notify owner of the disconnection. */
// struct GNUNET_MESH_PathBroken msg;
// struct GNUNET_PeerIdentity neighbor;
-//
+//
// msg.header.size = htons (sizeof (msg));
// msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN);
// GNUNET_PEER_resolve (t->id.oid, &msg.oid);
/**
* Send an end-to-end FWD ACK message for the most recent in-sequence payload.
- *
+ *
* @param t Tunnel this is about.
* @param fwd Is for FWD traffic? (ACK dest->owner)
*/
* If buffering is on, send when sent to children and buffer space is free.
* Note that although the name is fwd_ack, the FWD mean forward *traffic*,
* the ACK itself goes "back" (towards root).
- *
+ *
* @param t Tunnel on which to send the ACK.
* @param type Type of message that triggered the ACK transmission.
* @param fwd Is this FWD ACK? (Going dest->owner)
delta_mid = rel->mid_sent - rel->head_sent->mid;
else
delta_mid = 0;
- if (0 > delta || (GNUNET_YES == t->reliable &&
+ if (0 > delta || (GNUNET_YES == t->reliable &&
NULL != o &&
(10 < rel->n_sent || 64 <= delta_mid)))
delta = 0;
/**
* Modify the mesh message TID from global to local and send to client.
- *
+ *
* @param t Tunnel on which to send the message.
* @param msg Message to modify and send.
* @param c Client to send to.
/**
* Modify the unicast message TID from global to local and send to client.
- *
+ *
* @param t Tunnel on which to send the message.
* @param msg Message to modify and send.
* @param fwd Forward?
/**
* Send up to 64 buffered messages to the client for in order delivery.
- *
+ *
* @param t Tunnel on which to empty the message buffer.
* @param c Client to send to.
* @param rel Reliability structure to corresponding peer.
/**
* We have received a message out of order, buffer it until we receive
* the missing one and we can feed the rest to the client.
- *
+ *
* @param t Tunnel to add to.
* @param msg Message to buffer.
* @param rel Reliability data to the corresponding direction.
* Destroy a reliable message after it has been acknowledged, either by
* direct mid ACK or bitfield. Updates the appropriate data structures and
* timers and frees all memory.
- *
+ *
* @param copy Message that is no longer needed: remote peer got it.
*/
static void
rel = copy->rel;
time = GNUNET_TIME_absolute_get_duration (copy->timestamp);
- rel->expected_delay.rel_value *= 7;
- rel->expected_delay.rel_value += time.rel_value;
- rel->expected_delay.rel_value /= 8;
+ rel->expected_delay.rel_value_us *= 7;
+ rel->expected_delay.rel_value_us += time.rel_value_us;
+ rel->expected_delay.rel_value_us /= 8;
rel->n_sent--;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! Freeing %u\n", copy->mid);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " n_sent %u\n", rel->n_sent);
GNUNET_break (0);
r = GNUNET_SYSERR;
}
- if (GNUNET_YES !=
+ if (GNUNET_YES !=
GNUNET_CONTAINER_multihashmap32_remove (incoming_tunnels,
t->local_tid_dest, t))
{
/**
* Tunnel is empty: destroy it.
- *
+ *
* Notifies all participants (peers, cleints) about the destruction.
- *
- * @param t Tunnel to destroy.
+ *
+ * @param t Tunnel to destroy.
*/
static void
tunnel_destroy_empty (struct MeshTunnel *t)
/**
* Initialize a Flow Control structure to the initial state.
- *
+ *
* @param fc Flow Control structure to initialize.
*/
static void
/**
* Create a new tunnel
- *
+ *
* @param owner Who is the owner of the tunnel (short ID).
* @param tid Tunnel Number of the tunnel.
* @param client Clients that owns the tunnel, NULL for foreign tunnels.
* @param local Tunnel Number for the tunnel, for the client point of view.
- *
+ *
* @return A new initialized tunnel. NULL on error.
*/
static struct MeshTunnel *
/**
* Set options in a tunnel, extracted from a bit flag field
- *
+ *
* @param t Tunnel to set options to.
* @param options Bit array in host byte order.
*/
/**
* @brief Queue and pass message to core when possible.
- *
+ *
* If type is payload (UNICAST, TO_ORIGIN) checks for queue status and
* accounts for it. In case the queue is full, the message is dropped and
* a break issued.
- *
- * Otherwise, message is treated as internal and allowed to go regardless of
+ *
+ * Otherwise, message is treated as internal and allowed to go regardless of
* queue status.
*
* @param cls Closure (@c type dependant). It will be used by queue_send to
tunnel_reset_timeout (t, GNUNET_YES);
tunnel_change_state (t, MESH_TUNNEL_WAITING);
dest_peer_info =
- GNUNET_CONTAINER_multihashmap_get (peers, &pi[size - 1].hashPubKey);
+ GNUNET_CONTAINER_multipeermap_get (peers, &pi[size - 1]);
if (NULL == dest_peer_info)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" Creating PeerInfo for destination.\n");
dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeer));
dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]);
- GNUNET_CONTAINER_multihashmap_put (peers, &pi[size - 1].hashPubKey,
+ GNUNET_CONTAINER_multipeermap_put (peers, &pi[size - 1],
dest_peer_info,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
}
- orig_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &pi->hashPubKey);
+ orig_peer_info = GNUNET_CONTAINER_multipeermap_get (peers, pi);
if (NULL == orig_peer_info)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" Creating PeerInfo for origin.\n");
- orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeer));
+ orig_peer_info = GNUNET_new (struct MeshPeer);
orig_peer_info->id = GNUNET_PEER_intern (pi);
- GNUNET_CONTAINER_multihashmap_put (peers, &pi->hashPubKey, orig_peer_info,
+ GNUNET_CONTAINER_multipeermap_put (peers, pi, orig_peer_info,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n");
/* Eliminate tunnel when origin dies */
tunnel_reset_timeout (t, GNUNET_YES);
/* Keep tunnel alive in direction dest->owner*/
- tunnel_reset_timeout (t, GNUNET_NO);
+ tunnel_reset_timeout (t, GNUNET_NO);
}
else
{
return GNUNET_OK;
}
- fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ?
+ fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ?
GNUNET_YES : GNUNET_NO;
c = fwd ? t->client : t->owner;
hop = fwd ? t->next_hop : t->prev_hop;
GNUNET_PEER_resolve (peer->tunnels[i]->id.oid, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... tunnel %s:%X (%X / %X)\n",
GNUNET_i2s (&id), peer->tunnels[i]->id.tid,
- peer->tunnels[i]->local_tid,
+ peer->tunnels[i]->local_tid,
peer->tunnels[i]->local_tid_dest);
if (peer->tunnels[i]->state == MESH_TUNNEL_SEARCHING)
{
handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct MeshClient *c;
- struct MeshClient *next;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected: %p\n", client);
if (client == NULL)
&client_release_ports, c);
GNUNET_CONTAINER_multihashmap32_destroy (c->ports);
}
- next = c->next;
GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client free (%p)\n", c);
GNUNET_free (c);
GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO);
- c = next;
}
else
{
peer_remove_tunnel (peer_get_short (t->dest), t);
t->owner = NULL;
}
- else
+ else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
" tunnel %X client %p (%p, %p)\n",
t->owner->handle == client)
||
(tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV &&
- t->client &&
+ t->client &&
t->client->handle == client) ) )
{
GNUNET_break (0);
struct MeshPeerQueue *n;
DEBUG_CONN ("Peer disconnected\n");
- pi = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
+ pi = GNUNET_CONTAINER_multipeermap_get (peers, peer);
if (NULL == pi)
{
GNUNET_break (0);
* To be called on core init/fail.
*
* @param cls Closure (config)
- * @param server handle to the server for this service
* @param identity the public identity of this peer
*/
static void
-core_init (void *cls, struct GNUNET_CORE_Handle *server,
+core_init (void *cls,
const struct GNUNET_PeerIdentity *identity)
{
const struct GNUNET_CONFIGURATION_Handle *c = cls;
static int i = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
- GNUNET_break (core_handle == server);
- if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)) ||
- NULL == server)
+ if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
* GNUNET_NO if not.
*/
static int
-shutdown_peer (void *cls, const struct GNUNET_HashCode * key, void *value)
+shutdown_peer (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
{
struct MeshPeer *p = value;
struct MeshPeerQueue *q;
core_handle = NULL;
}
GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL);
- GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (peers, &shutdown_peer, NULL);
if (dht_handle != NULL)
{
GNUNET_DHT_disconnect (dht_handle);
const struct GNUNET_CONFIGURATION_Handle *c)
{
char *keyfile;
- struct GNUNET_CRYPTO_EccPrivateKey *pk;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
server_handle = server;
tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
incoming_tunnels = GNUNET_CONTAINER_multihashmap32_create (32);
- peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ peers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_NO);
ports = GNUNET_CONTAINER_multihashmap32_create (32);
dht_handle = GNUNET_DHT_connect (c, 64);
/* Scheduled the task to clean up when shutdown is called */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
NULL);
- pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
+ pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
GNUNET_assert (NULL != pk);
my_private_key = pk;
- GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
- GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
- &my_full_id.hashPubKey);
+ GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
+ &my_full_id.public_key);
myid = GNUNET_PEER_intern (&my_full_id);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Mesh for peer [%s] starting\n",