#define MESH_DEBUG_DHT GNUNET_NO
#define MESH_DEBUG_CONNECTION GNUNET_NO
-#define MESH_DEBUG_TIMING __LINUX__ && GNUNET_YES
+#define MESH_DEBUG_TIMING __LINUX__ && GNUNET_NO
+
+#define MESH_MAX_POLL_TIME GNUNET_TIME_relative_multiply (\
+ GNUNET_TIME_UNIT_MINUTES,\
+ 10)
#if MESH_DEBUG_CONNECTION
#define DEBUG_CONN(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
};
+/**
+ * Struct to store regex information announced by clients.
+ */
+struct MeshRegexDescriptor
+{
+ /**
+ * Regular expression itself.
+ */
+ char *regex;
+
+ /**
+ * Cached DFA for regular expression 'regex'.
+ */
+ struct GNUNET_REGEX_Automaton *dfa;
+
+ /**
+ * How many characters per edge can we squeeze?
+ */
+ uint16_t compression;
+};
+
/**
* Struct containing all info possibly needed to build a package when called
* back by core.
*/
struct GNUNET_TIME_Absolute last_contact;
+ /**
+ * Task handler for delayed connect task;
+ */
+ GNUNET_SCHEDULER_TaskIdentifier connect_task;
+
/**
* Number of attempts to reconnect so far
*/
*/
uint32_t bck_pid;
- /**
+ /**
* SKIP value for this tunnel.
*/
uint32_t skip;
+ /**
+ * Force sending ACK? Flag to allow duplicate ACK on POLL.
+ */
+ int force_ack;
+
/**
* MeshTunnelChildInfo of all children, indexed by GNUNET_PEER_Id.
* Contains the Flow Control info: FWD ACK value received,
*/
unsigned int bck_queue_max;
+ /**
+ * Task to poll peer in case of a stall.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier fc_poll_bck;
+
/**
* Last time the tunnel was used
*/
* when the queue is empty.
*/
int destroy;
+
+ /**
+ * Total messages pending for this tunnels, payload or not.
+ */
+ unsigned int pending_messages;
+
+ /**
+ * If the tunnel is empty, destoy it.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier delayed_destroy;
};
/**
* Last sent PID.
*/
- uint32_t pid;
+ uint32_t fwd_pid;
+
+ /**
+ * Last received PID.
+ */
+ uint32_t bck_pid;
/**
* Maximum PID allowed (FWD ACK received).
* How many elements are already in the buffer.
*/
unsigned int send_buffer_n;
+
+ /**
+ * Tunnel this info is about
+ */
+ struct MeshTunnel *t;
+
+ /**
+ * Task to poll peer in case of a stall.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier fc_poll;
+
+ /**
+ * Time to use for next polling call.
+ */
+ struct GNUNET_TIME_Relative fc_poll_time;
};
/**
* Regular expressions describing the services offered by this client.
*/
- char **regexes; // FIXME add timeout? API to remove a regex?
+ struct MeshRegexDescriptor *regexes; // FIXME regex add timeout? API to remove a regex?
/**
* Number of regular expressions in regexes.
*/
GNUNET_SCHEDULER_TaskIdentifier regex_announce_task;
+ /**
+ * Tmp store for partially retrieved regex.
+ */
+ char *partial_regex;
+
};
/*********************** GLOBAL VARIABLES ****************************/
/******************************************************************************/
+/************************** Configuration parameters **************************/
+
/**
- * Configuration parameters
+ * How often to send tunnel keepalives. Tunnels timeout after 4 missed.
*/
static struct GNUNET_TIME_Relative refresh_path_time;
+
+/**
+ * How often to PUT local application numbers in the DHT.
+ */
static struct GNUNET_TIME_Relative app_announce_time;
+
+/**
+ * How often to PUT own ID in the DHT.
+ */
static struct GNUNET_TIME_Relative id_announce_time;
-static struct GNUNET_TIME_Relative unacknowledged_wait_time;
+
+/**
+ * Maximum time allowed to connect to a peer found by string.
+ */
static struct GNUNET_TIME_Relative connect_timeout;
-static long long unsigned int default_ttl;
-static long long unsigned int dht_replication_level;
-static long long unsigned int max_tunnels;
-static long long unsigned int max_msgs_queue;
+/**
+ * Default TTL for payload packets.
+ */
+static unsigned long long default_ttl;
+
+/**
+ * DHT replication level, see DHT API: GNUNET_DHT_get_start, GNUNET_DHT_put.
+ */
+static unsigned long long dht_replication_level;
+
+/**
+ * How many tunnels are we willing to maintain.
+ * Local tunnels are always allowed, even if there are more tunnels than max.
+ */
+static unsigned long long max_tunnels;
+
+/**
+ * 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;
+
+/**
+ * How many peers do we want to remember?
+ */
+static unsigned long long max_peers;
+
+
+/*************************** Static global variables **************************/
/**
* Hostkey generation context
/*********************** DECLARATIONS **************************/
/******************************************************************************/
-/* FIXME move declarations here */
-
/**
* Function to process paths received for a new peer addition. The recorded
* paths form the initial tunnel, which can be optimized later.
* @return tunnel handler, NULL if doesn't exist.
*/
static struct MeshTunnel *
-tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid);
+tunnel_get (const struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid);
/**
}
regex_next_edge(block, SIZE_MAX, ctx);
+ GNUNET_STATISTICS_update (stats, "# regex mesh blocks iterated", 1, GNUNET_NO);
+
return GNUNET_YES;
}
char *current;
size_t current_len;
+ GNUNET_STATISTICS_update (stats, "# regex edges iterated", 1, GNUNET_NO);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Start of regex edge iterator\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* descr : %s\n", info->description);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* posit : %u\n", ctx->position);
current_len = strlen (info->description) - ctx->position;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* ctlen : %u\n", current_len);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* tklen : %u\n", len);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* tk[0] : %c\n", token[0]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* token : %.*s\n", len, token);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* nextk : %s\n", GNUNET_h2s(key));
if (len > current_len)
{
struct MeshRegexSearchContext *new_ctx;
struct MeshRegexSearchInfo *info = ctx->info;
struct GNUNET_DHT_GetHandle *get_h;
-
+ const char *rest;
int result;
/* Find the longest match for the current string position,
ctx->longest_match = 0;
result = GNUNET_MESH_regex_block_iterate (block, size,
®ex_edge_iterator, ctx);
- GNUNET_break (GNUNET_OK == result || SIZE_MAX == size);
+ GNUNET_break (GNUNET_OK == result);
/* Did anything match? */
if (0 == ctx->longest_match)
&ctx->hash,
®ex_result_iterator,
new_ctx);
+ // FIXME: "leaks" new_ctx? avoid keeping it around?
return; // We are already looking for it
}
+ GNUNET_STATISTICS_update (stats, "# regex nodes traversed", 1, GNUNET_NO);
+
/* Start search in DHT */
+ rest = &new_ctx->info->description[new_ctx->position];
get_h =
GNUNET_DHT_get_start (dht_handle, /* handle */
GNUNET_BLOCK_TYPE_MESH_REGEX, /* type */
&ctx->hash, /* key to search */
dht_replication_level, /* replication level */
GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */ // FIXME BLOOMFILTER
- 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
+ rest, /* xquery */
+ // FIXME add BLOOMFILTER to exclude filtered peers
+ strlen(rest) + 1, /* xquery bits */
+ // FIXME add BLOOMFILTER SIZE
&dht_get_string_handler, new_ctx);
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles,
}
-/**
- * Regex callback iterator to store own service description in the DHT.
- *
- * @param cls closure.
- * @param key hash for current state.
- * @param proof proof for current state.
- * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
- * @param num_edges number of edges leaving current state.
- * @param edges edges leaving current state.
- */
-void
-regex_iterator (void *cls,
- const struct GNUNET_HashCode *key,
- const char *proof,
- int accepting,
- unsigned int num_edges,
- const struct GNUNET_REGEX_Edge *edges)
-{
- struct MeshRegexBlock *block;
- struct MeshRegexEdge *block_edge;
- enum GNUNET_DHT_RouteOption opt;
- size_t size;
- size_t len;
- unsigned int i;
- unsigned int offset;
- char *aux;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " regex dht put for state %s\n",
- GNUNET_h2s(key));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " proof: %s\n",
- proof);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " num edges: %u\n",
- num_edges);
-
- opt = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
- if (GNUNET_YES == accepting)
- {
- struct MeshRegexAccept block;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " state %s is accepting, putting own id\n",
- GNUNET_h2s(key));
- size = sizeof (block);
- block.key = *key;
- block.id = my_full_id;
- (void)
- GNUNET_DHT_put(dht_handle, key,
- dht_replication_level,
- opt | GNUNET_DHT_RO_RECORD_ROUTE,
- GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT,
- size,
- (char *) &block,
- GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
- app_announce_time),
- app_announce_time,
- NULL, NULL);
- }
- len = strlen(proof);
- size = sizeof (struct MeshRegexBlock) + len;
- block = GNUNET_malloc (size);
-
- block->key = *key;
- block->n_proof = htonl (len);
- block->n_edges = htonl (num_edges);
- block->accepting = htonl (accepting);
-
- /* Store the proof at the end of the block. */
- aux = (char *) &block[1];
- memcpy (aux, proof, len);
- aux = &aux[len];
-
- /* Store each edge in a variable length MeshEdge struct at the
- * very end of the MeshRegexBlock structure.
- */
- for (i = 0; i < num_edges; i++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- " edge %s towards %s\n",
- edges[i].label,
- GNUNET_h2s(&edges[i].destination));
-
- /* aux points at the end of the last block */
- len = strlen (edges[i].label);
- size += sizeof (struct MeshRegexEdge) + len;
- // Calculate offset FIXME is this ok? use size instead?
- offset = aux - (char *) block;
- block = GNUNET_realloc (block, size);
- aux = &((char *) block)[offset];
- block_edge = (struct MeshRegexEdge *) aux;
- block_edge->key = edges[i].destination;
- block_edge->n_token = htonl (len);
- aux = (char *) &block_edge[1];
- memcpy (aux, edges[i].label, len);
- aux = &aux[len];
- }
- (void)
- GNUNET_DHT_put(dht_handle, key,
- dht_replication_level,
- opt,
- GNUNET_BLOCK_TYPE_MESH_REGEX, size,
- (char *) block,
- GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
- app_announce_time),
- app_announce_time,
- NULL, NULL);
- GNUNET_free (block);
-}
-
-
-/**
- * Store the regular expression describing a local service into the DHT.
- *
- * @param regex The regular expresion.
- */
-static void
-regex_put (const char *regex)
-{
- struct GNUNET_REGEX_Automaton *dfa;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "regex_put (%s) start\n", regex);
- dfa = GNUNET_REGEX_construct_dfa (regex, strlen(regex));
- GNUNET_REGEX_iterate_all_edges (dfa, ®ex_iterator, NULL);
- GNUNET_REGEX_automaton_destroy (dfa);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "regex_put (%s) end\n", regex);
-
-}
-
/**
* Find a path to a peer that offers a regex servcie compatible
* with a given string.
GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT, /* type */
key, /* key to search */
dht_replication_level, /* replication level */
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
- GNUNET_DHT_RO_RECORD_ROUTE,
- NULL, /* xquery */ // FIXME BLOOMFILTER
- 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE/* |
+ GNUNET_DHT_RO_RECORD_ROUTE*/,
+ NULL, /* xquery */
+ // FIXME add BLOOMFILTER to exclude filtered peers
+ 0, /* xquery bits */
+ // FIXME add BLOOMFILTER SIZE
&dht_get_string_accept_handler, ctx);
GNUNET_break (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put(ctx->info->dht_get_handles,
GNUNET_break (NULL !=
GNUNET_DHT_put (dht_handle, key,
- dht_replication_level,
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE,
- sizeof (block),
- (const char *) &block,
- GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
- app_announce_time),
- app_announce_time, NULL, NULL));
+ dht_replication_level,
+ GNUNET_DHT_RO_RECORD_ROUTE |
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE,
+ sizeof (block),
+ (const char *) &block,
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: this should be an option */
+ app_announce_time, NULL, NULL));
return GNUNET_OK;
}
+#if 0
+/**
+ * Function called when the DHT regex put is complete.
+ *
+ * @param the 'struct MeshClient' for which we were PUTting
+ * @param success GNUNET_OK if the PUT was transmitted,
+ * GNUNET_NO on timeout,
+ * GNUNET_SYSERR on disconnect from service
+ * after the PUT message was transmitted
+ * (so we don't know if it was received or not)
+ */
+static void
+announce_regex_done (void *cls,
+ int success)
+{
+ struct MeshClient *c = cls;
+
+}
+#endif
+
+
+/**
+ * Regex callback iterator to store own service description in the DHT.
+ *
+ * @param cls closure.
+ * @param key hash for current state.
+ * @param proof proof for current state.
+ * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
+ * @param num_edges number of edges leaving current state.
+ * @param edges edges leaving current state.
+ */
+static void
+regex_iterator (void *cls,
+ const struct GNUNET_HashCode *key,
+ const char *proof,
+ int accepting,
+ unsigned int num_edges,
+ const struct GNUNET_REGEX_Edge *edges)
+{
+ struct MeshRegexBlock *block;
+ struct MeshRegexEdge *block_edge;
+ enum GNUNET_DHT_RouteOption opt;
+ size_t size;
+ size_t len;
+ unsigned int i;
+ unsigned int offset;
+ char *aux;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " regex dht put for state %s\n",
+ GNUNET_h2s(key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " proof: %s\n",
+ proof);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " num edges: %u\n",
+ num_edges);
+
+ opt = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
+ if (GNUNET_YES == accepting)
+ {
+ struct MeshRegexAccept block;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " state %s is accepting, putting own id\n",
+ GNUNET_h2s(key));
+ size = sizeof (block);
+ block.key = *key;
+ block.id = my_full_id;
+ GNUNET_STATISTICS_update (stats, "# regex accepting blocks stored",
+ 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# regex accepting block bytes stored",
+ sizeof (block), GNUNET_NO);
+ (void)
+ GNUNET_DHT_put(dht_handle, key,
+ dht_replication_level,
+ opt/* | GNUNET_DHT_RO_RECORD_ROUTE*/,
+ GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT,
+ size,
+ (char *) &block,
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: expiration time should be option */
+ app_announce_time,
+ NULL, NULL);
+ }
+ len = strlen(proof);
+ size = sizeof (struct MeshRegexBlock) + len;
+ block = GNUNET_malloc (size);
+
+ block->key = *key;
+ block->n_proof = htonl (len);
+ block->n_edges = htonl (num_edges);
+ block->accepting = htonl (accepting);
+
+ /* Store the proof at the end of the block. */
+ aux = (char *) &block[1];
+ memcpy (aux, proof, len);
+ aux = &aux[len];
+
+ /* Store each edge in a variable length MeshEdge struct at the
+ * very end of the MeshRegexBlock structure.
+ */
+ for (i = 0; i < num_edges; i++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " edge %s towards %s\n",
+ edges[i].label,
+ GNUNET_h2s(&edges[i].destination));
+
+ /* aux points at the end of the last block */
+ len = strlen (edges[i].label);
+ size += sizeof (struct MeshRegexEdge) + len;
+ // Calculate offset FIXME is this ok? use size instead?
+ offset = aux - (char *) block;
+ block = GNUNET_realloc (block, size);
+ aux = &((char *) block)[offset];
+ block_edge = (struct MeshRegexEdge *) aux;
+ block_edge->key = edges[i].destination;
+ block_edge->n_token = htonl (len);
+ aux = (char *) &block_edge[1];
+ memcpy (aux, edges[i].label, len);
+ aux = &aux[len];
+ }
+ (void)
+ GNUNET_DHT_put(dht_handle, key,
+ dht_replication_level,
+ opt,
+ GNUNET_BLOCK_TYPE_MESH_REGEX, size,
+ (char *) block,
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: this should be an option */
+ app_announce_time,
+ NULL, NULL);
+ GNUNET_STATISTICS_update (stats, "# regex blocks stored",
+ 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# regex block bytes stored",
+ size, GNUNET_NO);
+
+ GNUNET_free (block);
+}
+
+
+/**
+ * Store the regular expression describing a local service into the DHT.
+ *
+ * @param regex The regular expresion.
+ */
+static void
+regex_put (struct MeshRegexDescriptor *regex)
+{
+ if (NULL == regex->dfa)
+ {
+ regex->dfa = GNUNET_REGEX_construct_dfa (regex->regex,
+ strlen (regex->regex),
+ regex->compression);
+ }
+
+ DEBUG_DHT (" regex_put (%s) start\n", regex->regex);
+ GNUNET_REGEX_iterate_all_edges (regex->dfa, ®ex_iterator, NULL);
+ DEBUG_DHT (" regex_put (%s) end\n", regex->regex);
+}
+
+
/**
* Periodically announce what applications are provided by local clients
* (by regex)
struct MeshClient *c = cls;
unsigned int i;
+ c->regex_announce_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- c->regex_announce_task = GNUNET_SCHEDULER_NO_TASK;
return;
- }
-
DEBUG_DHT ("Starting PUT for regex\n");
-
for (i = 0; i < c->n_regex; i++)
- {
- regex_put (c->regexes[i]);
- }
- c->regex_announce_task =
- GNUNET_SCHEDULER_add_delayed (app_announce_time, &announce_regex, cls);
+ regex_put (&c->regexes[i]);
+ c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time,
+ &announce_regex,
+ cls);
DEBUG_DHT ("Finished PUT for regex\n");
-
- return;
}
GNUNET_SCHEDULER_add_delayed (app_announce_time, &announce_applications,
cls);
DEBUG_DHT ("Finished PUT for apps\n");
-
- return;
}
tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
GNUNET_PEER_resolve (t->id.oid, &tmsg.peer);
tmsg.tunnel_id = htonl (t->local_tid_dest);
+ tmsg.opt = 0;
+ if (GNUNET_YES == t->speed_min)
+ tmsg.opt |= MESH_TUNNEL_OPT_SPEED_MIN;
+ if (GNUNET_YES == t->nobuffer)
+ tmsg.opt |= MESH_TUNNEL_OPT_NOBUFFER;
GNUNET_SERVER_notification_context_unicast (nc, c->handle,
&tmsg.header, GNUNET_NO);
tunnel_add_client (t, c);
{
struct GNUNET_MESH_PeerControl pc;
+ if (NULL == t->owner || GNUNET_YES == t->destroy)
+ return;
+
pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
pc.tunnel_id = htonl (t->local_tid);
}
+/**
+ * Iterator over all the peers to remove the oldest not-used entry.
+ *
+ * @param cls Closure (unsued).
+ * @param key ID of the peer.
+ * @param value Peer_Info of the peer.
+ *
+ * FIXME implement
+ */
+static int
+peer_info_timeout (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ return GNUNET_YES;
+}
+
/**
* Retrieve the MeshPeerInfo stucture associated with the peer, create one
* and insert it in the appropiate structures if the peer is not known yet.
{
peer_info =
(struct MeshPeerInfo *) GNUNET_malloc (sizeof (struct MeshPeerInfo));
+ if (GNUNET_CONTAINER_multihashmap_size (peers) > max_peers)
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (peers,
+ &peer_info_timeout,
+ NULL);
+ }
GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, peer_info,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
peer_info->id = GNUNET_PEER_intern (peer);
}
+ peer_info->last_contact = GNUNET_TIME_absolute_get();
return peer_info;
}
info->mesh_data->data = GNUNET_malloc (size);
memcpy (info->mesh_data->data, message, size);
type = ntohs(message->type);
- if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == type)
+ switch (type)
{
struct GNUNET_MESH_Unicast *m;
+ struct GNUNET_MESH_ToOrigin *to;
- m = (struct GNUNET_MESH_Unicast *) info->mesh_data->data;
- m->ttl = htonl (ntohl (m->ttl) - 1);
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ m = (struct GNUNET_MESH_Unicast *) info->mesh_data->data;
+ m->ttl = htonl (ntohl (m->ttl) - 1);
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ to = (struct GNUNET_MESH_ToOrigin *) info->mesh_data->data;
+ t->bck_pid++;
+ to->pid = htonl(t->bck_pid);
}
info->mesh_data->data_len = size;
info->mesh_data->reference_counter = 1;
}
#endif
GNUNET_break (0); // FIXME sometimes fails (testing disconnect?)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ " no direct connection to %s\n",
+ GNUNET_i2s (peer));
GNUNET_free (info->mesh_data->data);
GNUNET_free (info->mesh_data);
GNUNET_free (info);
{
struct MeshPathInfo *path_info = cls;
+ path_info->peer->connect_task = GNUNET_SCHEDULER_NO_TASK;
+
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
{
GNUNET_free (cls);
path_destroy (p);
p = nextp;
}
+ if (GNUNET_SCHEDULER_NO_TASK != pi->connect_task)
+ {
+ GNUNET_free (GNUNET_SCHEDULER_cancel (pi->connect_task));
+ }
GNUNET_free (pi);
return GNUNET_OK;
}
}
+/**
+ * Function called if the connection to the peer has been stalled for a while,
+ * possibly due to a missed ACK. Poll the peer about its ACK status.
+ *
+ * @param cls Closure (cinfo).
+ * @param tc TaskContext.
+ */
+static void
+tunnel_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MeshTunnelChildInfo *cinfo = cls;
+ struct GNUNET_MESH_Poll msg;
+ struct GNUNET_PeerIdentity id;
+ struct MeshTunnel *t;
+
+ cinfo->fc_poll = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ {
+ return;
+ }
+
+ t = cinfo->t;
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL);
+ msg.header.size = htons (sizeof (msg));
+ msg.tid = htonl (t->id.tid);
+ GNUNET_PEER_resolve (t->id.oid, &msg.oid);
+ msg.last_ack = htonl (cinfo->fwd_ack);
+
+ GNUNET_PEER_resolve (cinfo->id, &id);
+ send_prebuilt_message (&msg.header, &id, cinfo->t);
+ cinfo->fc_poll_time = GNUNET_TIME_relative_min (
+ MESH_MAX_POLL_TIME,
+ GNUNET_TIME_relative_multiply (cinfo->fc_poll_time, 2));
+ cinfo->fc_poll = GNUNET_SCHEDULER_add_delayed (cinfo->fc_poll_time,
+ &tunnel_poll, cinfo);
+}
+
+
/**
* Build a PeerPath from the paths returned from the DHT, reversing the paths
* to obtain a local peer -> destination path and interning the peer ids.
* @return tunnel handler, NULL if doesn't exist
*/
static struct MeshTunnel *
-tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid)
+tunnel_get (const struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid)
{
return tunnel_get_by_pi (GNUNET_PEER_search (oid), tid);
}
{
struct MeshTunnelChildInfo *cinfo = value;
struct MeshTunnel *t = cls;
+ struct MeshPeerQueue *q;
unsigned int c;
unsigned int i;
for (c = 0; c < cinfo->send_buffer_n; c++)
{
i = (cinfo->send_buffer_start + c) % t->fwd_queue_max;
- if (NULL != cinfo->send_buffer[i])
- queue_destroy (cinfo->send_buffer[i], GNUNET_YES);
+ q = cinfo->send_buffer[i];
+ cinfo->send_buffer[i] = NULL;
+ if (NULL != q)
+ queue_destroy (q, GNUNET_YES);
else
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u %u\n", c, cinfo->send_buffer_n);
}
GNUNET_free_non_null (cinfo->send_buffer);
+ if (GNUNET_SCHEDULER_NO_TASK != cinfo->fc_poll)
+ {
+ GNUNET_SCHEDULER_cancel (cinfo->fc_poll);
+ cinfo->fc_poll = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free (cinfo);
return GNUNET_YES;
}
path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
path_info->peer = peer;
path_info->t = t;
- GNUNET_SCHEDULER_add_now (&peer_info_connect_task, path_info);
+ peer->connect_task = GNUNET_SCHEDULER_add_now (&peer_info_connect_task,
+ path_info);
}
" no one to send data to\n");
GNUNET_free (mdata->data);
GNUNET_free (mdata);
- t->fwd_queue_n--;
+ if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_MESH_MULTICAST)
+ t->fwd_queue_n--;
}
else
{
* @return Neighbor's Flow Control info.
*/
static struct MeshTunnelChildInfo *
-tunnel_get_neighbor_fc (const struct MeshTunnel *t,
+tunnel_get_neighbor_fc (struct MeshTunnel *t,
const struct GNUNET_PeerIdentity *peer)
{
struct MeshTunnelChildInfo *cinfo;
+
+ if (NULL == t->children_fc)
+ return NULL;
+
cinfo = GNUNET_CONTAINER_multihashmap_get (t->children_fc,
&peer->hashPubKey);
if (NULL == cinfo)
cinfo = GNUNET_malloc (sizeof (struct MeshTunnelChildInfo));
cinfo->id = GNUNET_PEER_intern (peer);
cinfo->skip = t->fwd_pid;
+ cinfo->t = t;
- delta = t->nobuffer ? 1 : INITIAL_WINDOW_SIZE - 1;
+ delta = t->nobuffer ? 1 : INITIAL_WINDOW_SIZE;
cinfo->fwd_ack = t->fwd_pid + delta;
cinfo->bck_ack = delta;
+ cinfo->bck_pid = -1;
+
+ cinfo->fc_poll = GNUNET_SCHEDULER_NO_TASK;
+ cinfo->fc_poll_time = GNUNET_TIME_UNIT_SECONDS;
cinfo->send_buffer =
GNUNET_malloc (sizeof(struct MeshPeerQueue *) * t->fwd_queue_max);
ctx.t = t;
ctx.max_child_ack = 0;
ctx.nchildren = 0;
+ ctx.init = GNUNET_NO;
tree_iterate_children (t->tree, tunnel_get_child_fwd_ack, &ctx);
if (0 == ctx.nchildren)
count = t->fwd_pid - t->skip;
buffer_free = t->fwd_queue_max - t->fwd_queue_n;
- ack = count;
child_ack = tunnel_get_children_fwd_ack (t);
client_ack = tunnel_get_clients_fwd_ack (t);
+ if (GNUNET_YES == t->nobuffer)
+ {
+ ack = count;
+ if (-1LL == child_ack)
+ child_ack = client_ack;
+ if (-1LL == child_ack)
+ {
+ GNUNET_break (0);
+ client_ack = child_ack = ack;
+ }
+ }
+ else
+ {
+ ack = count + buffer_free; // Overflow? OK!
+ }
if (-1LL == child_ack)
{
// Node has no children, child_ack AND core buffer are irrelevant.
- GNUNET_break (-1LL != client_ack); // No children AND no clients? Not good!
+ if (-1LL == client_ack) // No children AND no clients? Not good!
+ {
+ GNUNET_STATISTICS_update (stats, "# mesh acks with no target",
+ 1, GNUNET_NO);
+
+ }
return (uint32_t) client_ack;
}
if (-1LL == client_ack)
{
- client_ack = ack + buffer_free; // Might overflow 32 bits, it's ok!
+ client_ack = ack;
}
if (GNUNET_YES == t->speed_min)
{
- ack = GMC_min_pid ((uint32_t) child_ack, ack) + buffer_free; // Might overflow 32 bits, it's ok!;
+ ack = GMC_min_pid ((uint32_t) child_ack, ack);
ack = GMC_min_pid ((uint32_t) client_ack, ack);
}
else
{
- ack = GMC_max_pid ((uint32_t) child_ack, ack) + buffer_free; // Might overflow 32 bits, it's ok!;
+ ack = GMC_max_pid ((uint32_t) child_ack, ack);
ack = GMC_max_pid ((uint32_t) client_ack, ack);
}
- if (GNUNET_YES == t->nobuffer && GMC_is_pid_bigger(ack, t->fwd_pid))
- ack = t->fwd_pid + 1; // Might overflow 32 bits, it's ok!
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"c %u, bf %u, ch %lld, cl %lld, ACK: %u\n",
count, buffer_free, child_ack, client_ack, ack);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", ack);
if (t->last_fwd_ack == ack)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " same as last, not sending!\n");
return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending!\n");
t->last_fwd_ack = ack;
case GNUNET_MESSAGE_TYPE_MESH_ACK:
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
break;
+ case GNUNET_MESSAGE_TYPE_MESH_POLL:
+ t->force_ack = GNUNET_YES;
+ break;
default:
GNUNET_break (0);
}
- /* Check if we need no retransmit the ACK */
+ /* Check if we need to transmit the ACK */
if (t->fwd_queue_max > t->fwd_queue_n * 4 &&
- GMC_is_pid_bigger(t->last_fwd_ack, t->fwd_pid))
+ GMC_is_pid_bigger(t->last_fwd_ack, t->fwd_pid) &&
+ GNUNET_NO == t->force_ack)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
ack = tunnel_get_fwd_ack (t);
/* If speed_min and not all children have ack'd, dont send yet */
- if (ack == t->last_fwd_ack)
+ if (ack == t->last_fwd_ack && GNUNET_NO == t->force_ack)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not ready\n");
return;
GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
send_ack (t, &id, ack);
debug_fwd_ack++;
+ t->force_ack = GNUNET_NO;
}
struct MeshTunnel *t = cls;
struct MeshTunnelChildInfo *cinfo;
struct GNUNET_PeerIdentity peer;
+ uint32_t ack;
GNUNET_PEER_resolve (id, &peer);
cinfo = tunnel_get_neighbor_fc (t, &peer);
+ ack = cinfo->bck_pid + t->bck_queue_max - t->bck_queue_n;
- if (cinfo->bck_ack != cinfo->pid &&
- GNUNET_NO == GMC_is_pid_bigger (cinfo->bck_ack, cinfo->pid))
+ if (cinfo->bck_ack == ack && GNUNET_NO == t->force_ack)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " Not sending ACK, not needed\n");
return;
+ }
+ cinfo->bck_ack = ack;
- cinfo->bck_ack++;
- send_ack (t, &peer, cinfo->bck_ack);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " Sending BCK ACK %u (last sent: %u)\n",
+ ack, cinfo->bck_ack);
+ send_ack (t, &peer, ack);
}
* @brief Send BCK ACKs to clients to allow them more to_origin traffic
*
* Iterates over all clients and sends BCK ACKs to the ones that need it.
+ *
+ * FIXME fc: what happens if we have 2 clients but q_size is 1?
+ * - implement a size 1 buffer in each client_fc AND children_fc
+ * to hold at least 1 message per "child".
+ * problem: violates no buffer policy
+ * - ack 0 and make "children" poll for transmission slots
+ * problem: big overhead, extra latency even in low traffic
+ * settings
*
* @param t Tunnel on which to send the BCK ACKs.
*/
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Sending BCK ACK to clients\n");
- tunnel_delta = t->bck_ack - t->bck_pid;
+ tunnel_delta = t->bck_queue_max - t->bck_queue_n;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " tunnel delta: %u\n", tunnel_delta);
/* Find client whom to allow to send to origin (with lowest buffer space) */
send_local_ack (t, t->clients[i], ack);
clinfo->bck_ack = ack;
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " not sending ack to client %u (td %u, d %u)\n",
+ t->clients[i]->id, tunnel_delta, delta);
+ }
}
}
case GNUNET_MESSAGE_TYPE_MESH_ACK:
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
break;
+ case GNUNET_MESSAGE_TYPE_MESH_POLL:
+ t->force_ack = GNUNET_YES;
+ break;
default:
GNUNET_break (0);
}
tunnel_send_clients_bck_ack (t);
tree_iterate_children (t->tree, &tunnel_send_child_bck_ack, t);
+ t->force_ack = GNUNET_NO;
}
* valid.
*
* @param t The tunnel whose peers to notify.
+ * @param send_back Do we need to notify our parent node?
*/
static void
-tunnel_send_destroy (struct MeshTunnel *t)
+tunnel_send_destroy (struct MeshTunnel *t, int send_back)
{
struct GNUNET_MESH_TunnelDestroy msg;
+ struct GNUNET_PeerIdentity id;
+ GNUNET_PEER_Id parent;
+
+ if (tree_count_children(t->tree) > 0)
+ {
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);
+ GNUNET_PEER_resolve (t->id.oid, &msg.oid);
+ msg.tid = htonl (t->id.tid);
+ tunnel_send_multicast (t, &msg.header);
+ }
+ parent = tree_get_predecessor(t->tree);
+ if (GNUNET_NO == send_back || 0 == parent)
+ return;
msg.header.size = htons (sizeof (msg));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);
- GNUNET_PEER_resolve (t->id.oid, &msg.oid);
- msg.tid = htonl (t->id.tid);
- tunnel_send_multicast (t, &msg.header);
+ send_prebuilt_message(&msg.header, &id, t);
}
}
}
- if (t->nclients > 0)
- {
- if (GNUNET_YES !=
- GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t))
- {
- GNUNET_break (0);
- r = GNUNET_SYSERR;
- }
- GNUNET_free (t->clients);
- }
+ (void) GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t);
+ GNUNET_free_non_null (t->clients);
+ GNUNET_free_non_null (t->clients_fc);
if (NULL != t->peers)
{
&tunnel_destroy_child,
t);
GNUNET_CONTAINER_multihashmap_destroy (t->children_fc);
+ t->children_fc = NULL;
tree_iterate_children (t->tree, &tunnel_cancel_queues, t);
-
tree_destroy (t->tree);
if (NULL != t->regex_ctx)
n_tunnels--;
GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO);
- GNUNET_assert (0 <= n_tunnels);
GNUNET_free (t);
return r;
}
+#define TUNNEL_DESTROY_EMPTY_TIME GNUNET_TIME_UNIT_MILLISECONDS
+
+/**
+ * Tunnel is empty: destroy it.
+ *
+ * @param cls Closure (Tunnel).
+ * @param tc TaskContext.
+ */
+static void
+tunnel_destroy_empty_delayed (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MeshTunnel *t = cls;
+
+ t->delayed_destroy = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+
+ if (0 != t->nclients ||
+ 0 != tree_count_children (t->tree))
+ return;
+
+ #if MESH_DEBUG
+ {
+ struct GNUNET_PeerIdentity id;
+
+ GNUNET_PEER_resolve (t->id.oid, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "executing destruction of empty tunnel %s [%X]\n",
+ GNUNET_i2s (&id), t->id.tid);
+ }
+ #endif
+
+ tunnel_destroy (t);
+}
+
+
+/**
+ * Schedule tunnel destruction if is empty and no new traffic comes in a time.
+ *
+ * @param t Tunnel to destroy if empty.
+ */
+static void
+tunnel_destroy_empty (struct MeshTunnel *t)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != t->delayed_destroy ||
+ 0 != t->nclients ||
+ 0 != tree_count_children (t->tree))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%u %u %u\n",
+ t->delayed_destroy, t->nclients, tree_count_children(t->tree));
+ return;
+ }
+
+ #if MESH_DEBUG
+ {
+ struct GNUNET_PeerIdentity id;
+
+ GNUNET_PEER_resolve (t->id.oid, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "scheduling destruction of empty tunnel %s [%X]\n",
+ GNUNET_i2s (&id), t->id.tid);
+ }
+ #endif
+
+ t->delayed_destroy =
+ GNUNET_SCHEDULER_add_delayed (TUNNEL_DESTROY_EMPTY_TIME,
+ &tunnel_destroy_empty_delayed,
+ t);
+}
+
/**
* Create a new tunnel
t->bck_ack = INITIAL_WINDOW_SIZE - 1;
t->last_fwd_ack = INITIAL_WINDOW_SIZE - 1;
t->local_tid = local;
- t->children_fc = GNUNET_CONTAINER_multihashmap_create (8);
+ t->children_fc = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
n_tunnels++;
GNUNET_STATISTICS_update (stats, "# tunnels", 1, GNUNET_NO);
static void
tunnel_delete_peer (struct MeshTunnel *t, GNUNET_PEER_Id peer)
{
- if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL))
- tunnel_destroy (t);
+ int r;
+
+ r = tree_del_peer (t->tree, peer, NULL, NULL);
+ if (GNUNET_NO == r)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Tunnel %u [%u] has no more nodes\n",
+ t->id.oid, t->id.tid);
+ }
}
* @return GNUNET_OK, keep iterating.
*/
static int
-tunnel_destroy_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
+tunnel_destroy_iterator (void *cls,
+ const struct GNUNET_HashCode * key,
+ void *value)
{
struct MeshTunnel *t = value;
struct MeshClient *c = cls;
- send_client_tunnel_disconnect(t, c);
+ send_client_tunnel_disconnect (t, c);
if (c != t->owner)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %u is destination, keeping the tunnel alive.\n", c->id);
- tunnel_delete_client(t, c);
- client_delete_tunnel(c, t);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %u is destination.\n", c->id);
+ tunnel_delete_client (t, c);
+ client_delete_tunnel (c, t);
+ tunnel_destroy_empty (t);
return GNUNET_OK;
}
- tunnel_send_destroy(t);
+ tunnel_send_destroy (t, GNUNET_YES);
t->owner = NULL;
t->destroy = GNUNET_YES;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Tunnel %s [%X] timed out. Destroying.\n",
GNUNET_i2s(&id), t->id.tid);
+ send_clients_tunnel_destroy (t);
tunnel_destroy (t);
}
if (GNUNET_YES == t->nobuffer)
opt |= MESH_TUNNEL_OPT_NOBUFFER;
msg->opt = htonl(opt);
+ msg->reserved = 0;
peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
for (i = 0; i < p->length; i++)
switch (queue->type)
{
case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " cancelling TUNNEL_DESTROY\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, " cancelling TUNNEL_DESTROY\n");
+ GNUNET_break (GNUNET_YES == queue->tunnel->destroy);
+ /* fall through */
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type payload\n");
+ case GNUNET_MESSAGE_TYPE_MESH_ACK:
+ case GNUNET_MESSAGE_TYPE_MESH_POLL:
+ case GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " prebuilt message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " type %s\n",
+ GNUNET_MESH_DEBUG_M2S(queue->type));
dd = queue->cls;
data_descriptor_decrement_rc (dd->mesh_data);
break;
max = queue->tunnel->fwd_queue_max;
GNUNET_PEER_resolve (queue->peer->id, &id);
cinfo = tunnel_get_neighbor_fc (queue->tunnel, &id);
- for (i = 0; i < cinfo->send_buffer_n; i++)
+ if (NULL != cinfo)
{
- unsigned int i2;
- i2 = (cinfo->send_buffer_start + i) % max;
- if (cinfo->send_buffer[i2] == queue)
+ for (i = 0; i < cinfo->send_buffer_n; i++)
{
- /* Found corresponding entry in the send_buffer. Move all others back. */
- unsigned int j;
- unsigned int j2;
- unsigned int j3;
-
- for (j = i; j < cinfo->send_buffer_n - 1; j++)
+ unsigned int i2;
+ i2 = (cinfo->send_buffer_start + i) % max;
+ if (cinfo->send_buffer[i2] == queue)
{
- j2 = (cinfo->send_buffer_start + j) % max;
- j3 = (cinfo->send_buffer_start + j + 1) % max;
- cinfo->send_buffer[j2] = cinfo->send_buffer[j3];
+ /* Found corresponding entry in the send_buffer. Move all others back. */
+ unsigned int j;
+ unsigned int j2;
+ unsigned int j3;
+
+ for (j = i, j2 = 0, j3 = 0; j < cinfo->send_buffer_n - 1; j++)
+ {
+ j2 = (cinfo->send_buffer_start + j) % max;
+ j3 = (cinfo->send_buffer_start + j + 1) % max;
+ cinfo->send_buffer[j2] = cinfo->send_buffer[j3];
+ }
+
+ cinfo->send_buffer[j3] = NULL;
+ cinfo->send_buffer_n--;
}
- cinfo->send_buffer[j3] = NULL;
- cinfo->send_buffer_n--;
}
}
- //queue->
GNUNET_free (queue);
}
size_t data_size;
peer->core_transmit = NULL;
+ cinfo = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* Queue send\n");
queue = queue_get_next (peer);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* not empty\n");
GNUNET_PEER_resolve (peer->id, &dst_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* towards %s\n",
+ GNUNET_i2s(&dst_id));
/* Check if buffer size is enough for the message */
if (queue->size > size)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* size ok\n");
t = queue->tunnel;
+ GNUNET_assert (0 < t->pending_messages);
+ t->pending_messages--;
if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == queue->type)
{
t->fwd_queue_n--;
{
case 0:
case GNUNET_MESSAGE_TYPE_MESH_ACK:
+ case GNUNET_MESSAGE_TYPE_MESH_POLL:
case GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN:
case GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY:
+ case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"********* raw: %s\n",
GNUNET_MESH_DEBUG_M2S (queue->type));
"********* considered sent\n");
t->fwd_queue_n--;
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "********* NOT considered sent yet\n");
+ t->pending_messages++;
+ }
}
data_size = send_core_data_multicast(queue->cls, size, buf);
tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
break;
default:
GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"********* type unknown: %u\n",
queue->type);
data_size = 0;
/* Free queue, but cls was freed by send_core_* */
queue_destroy (queue, GNUNET_NO);
- if (GNUNET_YES == t->destroy && 0 == t->fwd_queue_n)
+ if (GNUNET_YES == t->destroy && 0 == t->pending_messages)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* destroying tunnel!\n");
tunnel_destroy (t);
else
{
if (NULL != peer->queue_head)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"********* %s stalled\n",
GNUNET_i2s(&my_full_id));
+ if (NULL == cinfo)
+ cinfo = tunnel_get_neighbor_fc (t, &dst_id);
+ // FIXME unify bck/fwd structures, bck does not have cinfo right now
+ if (NULL != cinfo && GNUNET_SCHEDULER_NO_TASK == cinfo->fc_poll)
+ {
+ cinfo->fc_poll = GNUNET_SCHEDULER_add_delayed (cinfo->fc_poll_time,
+ &tunnel_poll, cinfo);
+ }
+ }
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "********* return %d\n", data_size);
return data_size;
n = &t->bck_queue_n;
max = &t->bck_queue_max;
}
- if (NULL != n) {
+ if (NULL != n)
+ {
if (*n >= *max)
{
- if (NULL == t->owner)
- GNUNET_break_op(0); // TODO: kill connection?
- else
- GNUNET_break(0);
- GNUNET_STATISTICS_update(stats, "# messages dropped (buffer full)",
+ GNUNET_break(0);
+ GNUNET_STATISTICS_update(stats,
+ "# messages dropped (buffer full)",
1, GNUNET_NO);
- return; // Drop message
+ return; // Drop message
}
(*n)++;
}
&queue_send,
dst);
}
+ t->pending_messages++;
if (NULL == n) // Is this internal mesh traffic?
return;
opt = ntohl (msg->opt);
t->speed_min = (0 != (opt & MESH_TUNNEL_OPT_SPEED_MIN)) ?
GNUNET_YES : GNUNET_NO;
- t->nobuffer = (0 != (opt & MESH_TUNNEL_OPT_NOBUFFER)) ?
- GNUNET_YES : GNUNET_NO;
+ if (0 != (opt & MESH_TUNNEL_OPT_NOBUFFER))
+ {
+ t->nobuffer = GNUNET_YES;
+ t->last_fwd_ack = t->fwd_pid + 1;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" speed_min: %d, nobuffer:%d\n",
t->speed_min, t->nobuffer);
if (NULL == t->peers)
{
/* New tunnel! Notify clients on first payload message. */
- t->peers = GNUNET_CONTAINER_multihashmap_create (4);
+ t->peers = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
}
GNUNET_break (GNUNET_SYSERR !=
GNUNET_CONTAINER_multihashmap_put (t->peers,
struct GNUNET_MESH_TunnelDestroy *msg;
struct MeshTunnel *t;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got a TUNNEL DESTROY packet from %s\n", GNUNET_i2s (peer));
msg = (struct GNUNET_MESH_TunnelDestroy *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for tunnel %s [%u]\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got a TUNNEL DESTROY packet from %s\n",
+ GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " for tunnel %s [%u]\n",
GNUNET_i2s (&msg->oid), ntohl (msg->tid));
t = tunnel_get (&msg->oid, ntohl (msg->tid));
if (NULL == t)
* destroyed the tunnel and retransmitted to children.
* Safe to ignore.
*/
- GNUNET_STATISTICS_update (stats, "# control on unknown tunnel", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# control on unknown tunnel",
+ 1, GNUNET_NO);
return GNUNET_OK;
}
if (t->id.oid == myid)
t->local_tid, t->local_tid_dest);
send_clients_tunnel_destroy (t);
}
- tunnel_send_destroy (t);
+ tunnel_send_destroy (t, GNUNET_YES);
t->destroy = GNUNET_YES;
// TODO: add timeout to destroy the tunnel anyway
return GNUNET_OK;
neighbor = tree_get_first_hop (t->tree, dest_id);
cinfo = tunnel_get_neighbor_fc (t, neighbor);
- cinfo->pid = pid;
+ cinfo->fwd_pid = pid;
GNUNET_CONTAINER_multihashmap_iterate (t->children_fc,
&tunnel_add_skip,
&neighbor);
GNUNET_YES == GMC_is_pid_bigger (pid, cinfo->fwd_ack))
{
GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, " %u > %u\n", pid, cinfo->fwd_ack);
GNUNET_break_op (0);
return GNUNET_OK;
}
struct GNUNET_PeerIdentity id;
struct MeshPeerInfo *peer_info;
struct MeshTunnel *t;
+ struct MeshTunnelChildInfo *cinfo;
+ GNUNET_PEER_Id predecessor;
size_t size;
-
+ uint32_t pid;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a ToOrigin packet from %s\n",
GNUNET_i2s (peer));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %s\n",
GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
t = tunnel_get (&msg->oid, ntohl (msg->tid));
+ pid = ntohl (msg->pid);
if (NULL == t)
{
/* TODO notify that we dont know this tunnel (whom)? */
GNUNET_STATISTICS_update (stats, "# data on unknown tunnel", 1, GNUNET_NO);
- GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received to_origin with PID %u on unknown tunnel %s [%u]\n",
+ pid, GNUNET_i2s (&msg->oid), ntohl (msg->tid));
+ return GNUNET_OK;
+ }
+
+ cinfo = tunnel_get_neighbor_fc(t, peer);
+ if (NULL == cinfo)
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+
+ if (cinfo->bck_pid == pid)
+ {
+ /* already seen this packet, drop */
+ GNUNET_STATISTICS_update (stats, "# duplicate PID drops BCK", 1, GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " Already seen pid %u, DROPPING!\n", pid);
+ tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
return GNUNET_OK;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " pid %u not seen yet, forwarding\n", pid);
+ cinfo->bck_pid = pid;
+
if (NULL != t->owner)
{
char cbuf[size];
memcpy (cbuf, message, size);
copy = (struct GNUNET_MESH_ToOrigin *) cbuf;
copy->tid = htonl (t->local_tid);
+ t->bck_pid++;
+ copy->pid = htonl (t->bck_pid);
GNUNET_STATISTICS_update (stats, "# to origin received", 1, GNUNET_NO);
GNUNET_SERVER_notification_context_unicast (nc, t->owner->handle,
©->header, GNUNET_NO);
GNUNET_break (0);
return GNUNET_OK;
}
- GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
+ predecessor = tree_get_predecessor (t->tree);
+ if (0 == predecessor)
+ {
+ if (GNUNET_YES == t->destroy)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "to orig received on a dying tunnel %s [%X]\n",
+ GNUNET_i2s (&msg->oid), ntohl(msg->tid));
+ return GNUNET_OK;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "unknown to origin at %s\n",
+ GNUNET_i2s (&my_full_id));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "from peer %s\n",
+ GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "for tunnel %s [%X]\n",
+ GNUNET_i2s (&msg->oid), ntohl(msg->tid));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "current tree:\n");
+ tree_debug (t->tree);
+ return GNUNET_OK;
+ }
+ GNUNET_PEER_resolve (predecessor, &id);
send_prebuilt_message (message, &id, t);
GNUNET_STATISTICS_update (stats, "# to origin forwarded", 1, GNUNET_NO);
/**
- * Core handler for mesh network traffic point-to-point acks.
+ * Core handler for mesh network traffic point-to-point acks.
+ *
+ * @param cls closure
+ * @param message message
+ * @param peer peer identity this notification is about
+ * @param atsi performance data
+ * @param atsi_count number of records in 'atsi'
+ *
+ * @return GNUNET_OK to keep the connection open,
+ * GNUNET_SYSERR to close it (signal serious error)
+ */
+static int
+handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
+{
+ struct GNUNET_MESH_ACK *msg;
+ struct MeshTunnel *t;
+ uint32_t ack;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n",
+ GNUNET_i2s (peer));
+ msg = (struct GNUNET_MESH_ACK *) message;
+
+ t = tunnel_get (&msg->oid, ntohl (msg->tid));
+
+ if (NULL == t)
+ {
+ /* TODO notify that we dont know this tunnel (whom)? */
+ GNUNET_STATISTICS_update (stats, "# ack on unknown tunnel", 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
+ ack = ntohl (msg->pid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack);
+
+ /* Is this a forward or backward ACK? */
+ if (tree_get_predecessor(t->tree) != GNUNET_PEER_search(peer))
+ {
+ struct MeshTunnelChildInfo *cinfo;
+
+ debug_bck_ack++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
+ cinfo = tunnel_get_neighbor_fc (t, peer);
+ cinfo->fwd_ack = ack;
+ tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
+ tunnel_unlock_fwd_queues (t);
+ if (GNUNET_SCHEDULER_NO_TASK != cinfo->fc_poll)
+ {
+ GNUNET_SCHEDULER_cancel (cinfo->fc_poll);
+ cinfo->fc_poll = GNUNET_SCHEDULER_NO_TASK;
+ cinfo->fc_poll_time = GNUNET_TIME_UNIT_SECONDS;
+ }
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
+ t->bck_ack = ack;
+ tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
+ tunnel_unlock_bck_queue (t);
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Core handler for mesh network traffic point-to-point ack polls.
*
* @param cls closure
* @param message message
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
-handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
- struct GNUNET_MESH_ACK *msg;
+ struct GNUNET_MESH_Poll *msg;
struct MeshTunnel *t;
- uint32_t ack;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an POLL packet from %s!\n",
GNUNET_i2s (peer));
- msg = (struct GNUNET_MESH_ACK *) message;
+
+ msg = (struct GNUNET_MESH_Poll *) message;
t = tunnel_get (&msg->oid, ntohl (msg->tid));
if (NULL == t)
{
/* TODO notify that we dont know this tunnel (whom)? */
- GNUNET_STATISTICS_update (stats, "# ack on unknown tunnel", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# poll on unknown tunnel", 1, GNUNET_NO);
GNUNET_break_op (0);
return GNUNET_OK;
}
- ack = ntohl (msg->pid);
/* Is this a forward or backward ACK? */
if (tree_get_predecessor(t->tree) != GNUNET_PEER_search(peer))
{
struct MeshTunnelChildInfo *cinfo;
- debug_bck_ack++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " from FWD\n");
cinfo = tunnel_get_neighbor_fc (t, peer);
- cinfo->fwd_ack = ack;
- tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
- tunnel_unlock_fwd_queues (t);
+ cinfo->bck_ack = cinfo->fwd_pid; // mark as ready to send
+ tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_POLL);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
- t->bck_ack = ack;
- tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
- tunnel_unlock_bck_queue (t);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " from BCK\n");
+ tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_POLL);
}
+
return GNUNET_OK;
}
{&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
{&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK,
sizeof (struct GNUNET_MESH_ACK)},
+ {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL,
+ sizeof (struct GNUNET_MESH_Poll)},
{&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK,
sizeof (struct GNUNET_MESH_PathACK)},
{NULL, 0, 0}
const struct MeshRegexAccept *block = data;
struct MeshRegexSearchContext *ctx = cls;
struct MeshRegexSearchInfo *info = ctx->info;
- struct MeshPeerPath *p;
+// struct MeshPeerPath *p;
struct MeshPeerInfo *peer_info;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", info->description);
+ GNUNET_STATISTICS_update (stats, "# regex accepting blocks found",
+ 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# regex accepting block bytes found",
+ size, GNUNET_NO);
peer_info = peer_info_get(&block->id);
- p = path_build_from_dht (get_path, get_path_length, put_path,
- put_path_length);
- path_add_to_peers (p, GNUNET_NO);
- path_destroy(p);
+// p = path_build_from_dht (get_path, get_path_length, put_path,
+// put_path_length);
+// path_add_to_peers (p, GNUNET_NO);
+// path_destroy(p);
tunnel_add_peer (info->t, peer_info);
peer_info_connect (peer_info, info->t);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" key: %s\n", GNUNET_h2s (key));
+ GNUNET_STATISTICS_update (stats, "# regex blocks found",
+ 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# regex block bytes found",
+ size, GNUNET_NO);
+
copy = GNUNET_malloc (size);
memcpy (copy, data, size);
GNUNET_break (GNUNET_OK ==
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (SERVER DOWN)\n");
return;
}
+
c = clients;
while (NULL != c)
{
GNUNET_CONTAINER_multihashmap_destroy (c->types);
for (i = 0; i < c->n_regex; i++)
{
- GNUNET_free (c->regexes[i]);
+ GNUNET_free (c->regexes[i].regex);
+ if (NULL != c->regexes[i].dfa)
+ GNUNET_REGEX_automaton_destroy (c->regexes[i].dfa);
}
GNUNET_free_non_null (c->regexes);
if (GNUNET_SCHEDULER_NO_TASK != c->regex_announce_task)
GNUNET_MESH_ApplicationType at;
struct GNUNET_HashCode hc;
- c->apps = GNUNET_CONTAINER_multihashmap_create (napps);
+ c->apps = GNUNET_CONTAINER_multihashmap_create (napps, GNUNET_NO);
for (i = 0; i < napps; i++)
{
at = ntohl (a[i]);
struct GNUNET_HashCode hc;
t = (uint16_t *) & a[napps];
- c->types = GNUNET_CONTAINER_multihashmap_create (ntypes);
+ c->types = GNUNET_CONTAINER_multihashmap_create (ntypes, GNUNET_NO);
for (i = 0; i < ntypes; i++)
{
u16 = ntohs (t[i]);
" client has %u+%u subscriptions\n", napps, ntypes);
GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c);
- c->own_tunnels = GNUNET_CONTAINER_multihashmap_create (32);
- c->incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32);
- c->ignore_tunnels = GNUNET_CONTAINER_multihashmap_create (32);
+ c->own_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ c->incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ c->ignore_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
GNUNET_SERVER_notification_context_add (nc, client);
GNUNET_STATISTICS_update (stats, "# clients", 1, GNUNET_NO);
handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
+ const struct GNUNET_MESH_RegexAnnounce *msg;
+ struct MeshRegexDescriptor rd;
struct MeshClient *c;
char *regex;
size_t len;
+ size_t offset;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex started\n");
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
- len = ntohs (message->size) - sizeof(struct GNUNET_MessageHeader);
- regex = GNUNET_malloc (len + 1);
- memcpy (regex, &message[1], len);
- regex[len] = '\0';
- GNUNET_array_append (c->regexes, c->n_regex, regex);
+ msg = (const struct GNUNET_MESH_RegexAnnounce *) message;
+
+ len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce);
+ if (NULL != c->partial_regex)
+ {
+ regex = c->partial_regex;
+ offset = strlen (c->partial_regex);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " continuation, already have %u bytes\n",
+ offset);
+ }
+ else
+ {
+ regex = NULL;
+ offset = 0;
+ }
+
+ regex = GNUNET_realloc (regex, offset + len + 1);
+ memcpy (®ex[offset], &msg[1], len);
+ regex[offset + len] = '\0';
+ if (0 == ntohs (msg->last))
+ {
+ c->partial_regex = regex;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " not ended, stored %u bytes for later\n",
+ len);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ rd.regex = regex;
+ rd.compression = ntohs (msg->compression_characters);
+ rd.dfa = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " length %u\n", len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex %s\n", regex);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " cm %u\n", ntohs(rd.compression));
+ GNUNET_array_append (c->regexes, c->n_regex, rd);
+ c->partial_regex = NULL;
if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task)
{
c->regex_announce_task = GNUNET_SCHEDULER_add_now(&announce_regex, c);
}
else
{
- regex_put(regex);
+ regex_put(&rd);
}
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex processed\n");
next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n",
GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
- t->peers = GNUNET_CONTAINER_multihashmap_create (32);
+ t->peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new tunnel created\n");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
if (c != t->owner || tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
{
client_ignore_tunnel (c, t);
-#if 0
- // TODO: when to destroy incoming tunnel?
- if (t->nclients == 0)
- {
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels,
- &hash, t));
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (t->peers,
- &my_full_id.hashPubKey,
- t));
- }
-#endif
+ tunnel_destroy_empty (t);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
/* Don't try to ACK the client about the tunnel_destroy multicast packet */
t->owner = NULL;
- tunnel_send_destroy (t);
+ tunnel_send_destroy (t, GNUNET_YES);
t->destroy = GNUNET_YES;
// The tunnel will be destroyed when the last message is transmitted.
GNUNET_SERVER_receive_done (client, GNUNET_OK);
const char *string;
size_t size;
size_t len;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connect by string started\n");
msg = (struct GNUNET_MESH_ConnectPeerByString *) message;
string = (const char *) &msg[1];
/* Initialize context */
- size = GNUNET_REGEX_get_first_key(string, len, &key);
+ size = GNUNET_REGEX_get_first_key (string, len, &key);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" consumed %u bits out of %u\n", size, len);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
info = GNUNET_malloc (sizeof (struct MeshRegexSearchInfo));
info->t = t;
- info->description = GNUNET_malloc (len + 1);
- memcpy (info->description, string, len);
- info->description[len] = '\0';
- info->dht_get_handles = GNUNET_CONTAINER_multihashmap_create(32);
- info->dht_get_results = GNUNET_CONTAINER_multihashmap_create(32);
+ info->description = GNUNET_strndup (string, len);
+ info->dht_get_handles = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO);
+ info->dht_get_results = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " string: %s\n", info->description);
ctx = GNUNET_malloc (sizeof (struct MeshRegexSearchContext));
&key, /* key to search */
dht_replication_level, /* replication level */
GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */ // FIXME BLOOMFILTER
- 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
+ &info->description[size], /* xquery */
+ // FIXME add BLOOMFILTER to exclude filtered peers
+ len + 1 - size, /* xquery bits */
+ // FIXME add BLOOMFILTER SIZE
&dht_get_string_handler, ctx);
GNUNET_break (GNUNET_OK ==
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ clinfo->bck_pid++;
/* Ok, everything is correct, send the message
* (pretend we got it from a mesh peer)
*/
- clinfo->bck_pid++;
{
char buf[ntohs (message->size)] GNUNET_ALIGN;
struct GNUNET_MESH_ToOrigin *copy;
GNUNET_PEER_resolve (t->id.oid, ©->oid);
copy->tid = htonl (t->id.tid);
copy->ttl = htonl (default_ttl);
- if (ntohl (copy->pid) != (t->bck_pid + 1))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "To Origin PID, expected %u, got %u\n",
- t->bck_pid + 1,
- ntohl (copy->pid));
- return;
- }
- t->bck_pid++;
+ copy->pid = htonl (t->bck_pid + 1);
+
copy->sender = my_full_id;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" calling generic handler...\n");
ack = ntohl (msg->max_pid);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", ack);
- /* Does client own tunnel? I.E: Is this and ACK for BCK traffic? */
+ /* Does client own tunnel? I.E: Is this an ACK for BCK traffic? */
if (NULL != t->owner && t->owner->handle == client)
{
/* The client owns the tunnel, ACK is for data to_origin, send BCK ACK. */
tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK);
}
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
+/**
+ * Iterator over all peers to send a monitoring client info about a tunnel.
+ *
+ * @param cls Closure (message being built).
+ * @param key Key (hashed tunnel ID, unused).
+ * @param value Peer info.
+ *
+ * @return GNUNET_YES, to keep iterating.
+ */
+static int
+monitor_peers_iterator (void *cls,
+ const struct GNUNET_HashCode * key,
+ void *value)
+{
+ struct GNUNET_MESH_LocalMonitor *msg = cls;
+ struct GNUNET_PeerIdentity *id;
+ struct MeshPeerInfo *info = value;
+
+ id = (struct GNUNET_PeerIdentity *) &msg[1];
+ GNUNET_PEER_resolve (info->id, &id[msg->npeers]);
+ msg->npeers++;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "* sending info about peer %s [%u]\n",
+ GNUNET_i2s (&id[msg->npeers - 1]), msg->npeers);
+
+ return GNUNET_YES;
+}
+
+
+
+/**
+ * Iterator over all tunnels to send a monitoring client info about each tunnel.
+ *
+ * @param cls Closure (client handle).
+ * @param key Key (hashed tunnel ID, unused).
+ * @param value Tunnel info.
+ *
+ * @return GNUNET_YES, to keep iterating.
+ */
+static int
+monitor_all_tunnels_iterator (void *cls,
+ const struct GNUNET_HashCode * key,
+ void *value)
+{
+ struct GNUNET_SERVER_Client *client = cls;
+ struct MeshTunnel *t = value;
+ struct GNUNET_MESH_LocalMonitor *msg;
+ uint32_t npeers;
+
+ npeers = GNUNET_CONTAINER_multihashmap_size (t->peers);
+ msg = GNUNET_malloc (sizeof(struct GNUNET_MESH_LocalMonitor) +
+ npeers * sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_PEER_resolve(t->id.oid, &msg->owner);
+ msg->tunnel_id = htonl (t->id.tid);
+ msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor) +
+ npeers * sizeof (struct GNUNET_PeerIdentity));
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+ msg->npeers = 0;
+ (void) GNUNET_CONTAINER_multihashmap_iterate (t->peers,
+ monitor_peers_iterator,
+ msg);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "* sending info about tunnel %s [%u] (%u peers)\n",
+ GNUNET_i2s (&msg->owner), t->id.tid, npeers);
+
+ if (msg->npeers != npeers)
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Get tunnels fail: size %u - iter %u\n",
+ npeers, msg->npeers);
+ }
+
+ msg->npeers = htonl (npeers);
+ GNUNET_SERVER_notification_context_unicast (nc, client,
+ &msg->header, GNUNET_NO);
+ return GNUNET_YES;
+}
+
+
+/**
+ * Handler for client's MONITOR request.
+ *
+ * @param cls Closure (unused).
+ * @param client Identification of the client.
+ * @param message The actual message.
+ */
+static void
+handle_local_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct MeshClient *c;
+
+ /* Sanity check for client registration */
+ if (NULL == (c = client_get (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received get tunnels request from client %u\n",
+ c->id);
+ GNUNET_CONTAINER_multihashmap_iterate (tunnels,
+ monitor_all_tunnels_iterator,
+ client);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Get tunnels request from client %u completed\n",
+ c->id);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
+/**
+ * Data needed to build a Monitor_Tunnel message.
+ */
+struct MeshMonitorTunnelContext
+{
+ /**
+ * Partial message, including peer count.
+ */
+ struct GNUNET_MESH_LocalMonitor *msg;
+
+ /**
+ * Hashmap with positions: peer->position.
+ */
+ struct GNUNET_CONTAINER_MultiHashMap *lookup;
+
+ /**
+ * Index of the parent of each peer in the message, realtive to the absolute
+ * order in the array (can be in a previous message).
+ */
+ uint32_t parents[1024];
+
+ /**
+ * Peers visited so far in the tree, aka position of the current peer.
+ */
+ unsigned int npeers;
+
+ /**
+ * Client requesting the info.
+ */
+ struct MeshClient *c;
+};
+
+
+/**
+ * Send a client a message about the structure of a tunnel.
+ *
+ * @param ctx Context of the tunnel iteration, with info regarding the state
+ * of the execution and the number of peers visited for this message.
+ */
+static void
+send_client_tunnel_info (struct MeshMonitorTunnelContext *ctx)
+{
+ struct GNUNET_MESH_LocalMonitor *resp = ctx->msg;
+ struct GNUNET_PeerIdentity *pid;
+ unsigned int *parent;
+ size_t size;
+
+ size = sizeof (struct GNUNET_MESH_LocalMonitor);
+ size += (sizeof (struct GNUNET_PeerIdentity) + sizeof (int)) * resp->npeers;
+ resp->header.size = htons (size);
+ pid = (struct GNUNET_PeerIdentity *) &resp[1];
+ parent = (unsigned int *) &pid[resp->npeers];
+ memcpy (parent, ctx->parents, sizeof(uint32_t) * resp->npeers);
+ GNUNET_SERVER_notification_context_unicast (nc, ctx->c->handle,
+ &resp->header, GNUNET_NO);
+}
+
+/**
+ * Iterator over a tunnel tree to build a message containing all peers
+ * the in the tunnel, including relay nodes.
+ *
+ * @param cls Closure (pointer to pointer of message being built).
+ * @param peer Short ID of a peer.
+ * @param parent Short ID of the @c peer 's parent.
+ */
+static void
+tunnel_tree_iterator (void *cls,
+ GNUNET_PEER_Id peer,
+ GNUNET_PEER_Id parent)
+{
+ struct MeshMonitorTunnelContext *ctx = cls;
+ struct GNUNET_MESH_LocalMonitor *msg;
+ struct GNUNET_PeerIdentity *pid;
+ struct GNUNET_PeerIdentity ppid;
+
+ msg = ctx->msg;
+ pid = (struct GNUNET_PeerIdentity *) &msg[1];
+ GNUNET_PEER_resolve (peer, &pid[msg->npeers]);
+ GNUNET_CONTAINER_multihashmap_put (ctx->lookup,
+ &pid[msg->npeers].hashPubKey,
+ (void *) (long) ctx->npeers,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ GNUNET_PEER_resolve (parent, &ppid);
+ ctx->parents[msg->npeers] =
+ htonl ((long) GNUNET_CONTAINER_multihashmap_get (ctx->lookup,
+ &ppid.hashPubKey));
+
+ ctx->npeers++;
+ msg->npeers++;
+
+ if (sizeof (struct GNUNET_MESH_LocalMonitor) +
+ (msg->npeers + 1) *
+ (sizeof (struct GNUNET_PeerIdentity) + sizeof (uint32_t))
+ > USHRT_MAX)
+ {
+ send_client_tunnel_info (ctx);
+ msg->npeers = 0;
+ }
+}
+
+
+/**
+ * Handler for client's MONITOR_TUNNEL request.
+ *
+ * @param cls Closure (unused).
+ * @param client Identification of the client.
+ * @param message The actual message.
+ */
+static void
+handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ const struct GNUNET_MESH_LocalMonitor *msg;
+ struct GNUNET_MESH_LocalMonitor *resp;
+ struct MeshMonitorTunnelContext ctx;
+ struct MeshClient *c;
+ struct MeshTunnel *t;
+
+ /* Sanity check for client registration */
+ if (NULL == (c = client_get (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+
+ msg = (struct GNUNET_MESH_LocalMonitor *) message;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received tunnel info request from client %u for tunnel %s[%X]\n",
+ c->id,
+ &msg->owner,
+ ntohl (msg->tunnel_id));
+ t = tunnel_get (&msg->owner, ntohl (msg->tunnel_id));
+ if (NULL == t)
+ {
+ /* We don't know the tunnel */
+ struct GNUNET_MESH_LocalMonitor warn;
+
+ warn = *msg;
+ warn.npeers = htonl (UINT_MAX);
+ GNUNET_SERVER_notification_context_unicast (nc, client,
+ &warn.header,
+ GNUNET_NO);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+
+ /* Initialize context */
+ resp = GNUNET_malloc (USHRT_MAX); /* avoid realloc'ing on each step */
+ *resp = *msg;
+ resp->npeers = 0;
+ ctx.msg = resp;
+ ctx.lookup = GNUNET_CONTAINER_multihashmap_create (4 * t->peers_total,
+ GNUNET_YES);
+ ctx.c = c;
+
+ /* Collect and send information */
+ tree_iterate_all (t->tree, &tunnel_tree_iterator, &ctx);
+ send_client_tunnel_info (&ctx);
+
+ /* Free context */
+ GNUNET_CONTAINER_multihashmap_destroy (ctx.lookup);
+ GNUNET_free (resp);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Monitor tunnel request from client %u completed\n",
+ c->id);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
/**
* Functions to handle messages from clients
*/
{&handle_local_ack, NULL,
GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
sizeof (struct GNUNET_MESH_LocalAck)},
+ {&handle_local_get_tunnels, NULL,
+ GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&handle_local_show_tunnel, NULL,
+ GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,
+ sizeof (struct GNUNET_MESH_LocalMonitor)},
{NULL, NULL, 0, 0}
};
NULL == server)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ " core id %s\n",
+ GNUNET_i2s (identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ " my id %s\n",
+ GNUNET_i2s (&my_full_id));
GNUNET_SCHEDULER_shutdown (); // Try gracefully
if (10 < i++)
GNUNET_abort(); // Try harder
queue_destroy(q, GNUNET_YES);
q = n;
}
+ if (NULL != pi->core_transmit)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit);
+ pi->core_transmit = NULL;
+ }
peer_info_remove_path (pi, pi->id, myid);
if (myid == pi->id)
{
GNUNET_CORE_disconnect (core_handle);
core_handle = NULL;
}
- if (NULL != keygen)
+ if (NULL != keygen)
{
GNUNET_CRYPTO_rsa_key_create_stop (keygen);
keygen = NULL;
GNUNET_SCHEDULER_cancel (announce_id_task);
announce_id_task = GNUNET_SCHEDULER_NO_TASK;
}
+ if (GNUNET_SCHEDULER_NO_TASK != announce_applications_task)
+ {
+ GNUNET_SCHEDULER_cancel (announce_applications_task);
+ announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
}
/**
* Callback for hostkey read/generation
*
- * @param cls NULL
+ * @param cls Closure (Configuration handle).
* @param pk the private key
* @param emsg error message
*/
struct GNUNET_CRYPTO_RsaPrivateKey *pk,
const char *emsg)
{
+ const struct GNUNET_CONFIGURATION_Handle *c = cls;
struct MeshPeerInfo *peer;
struct MeshPeerPath *p;
if (NULL == pk)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Mesh service could not access hostkey. Exiting.\n"));
+ _("Mesh service could not access hostkey: %s. Exiting.\n"),
+ emsg);
GNUNET_SCHEDULER_shutdown ();
return;
}
// NULL,
// NULL);
-
+ core_handle = GNUNET_CORE_connect (c, /* Main configuration */
+ NULL, /* Closure passed to MESH functions */
+ &core_init, /* Call core_init once connected */
+ &core_connect, /* Handle connects */
+ &core_disconnect, /* remove peers on disconnects */
+ NULL, /* Don't notify about all incoming messages */
+ GNUNET_NO, /* For header only in notification */
+ NULL, /* Don't notify about all outbound messages */
+ GNUNET_NO, /* For header-only out notification */
+ core_handlers); /* Register these handlers */
+
+ if (core_handle == NULL)
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
next_tid = 0;
next_local_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
server_handle = server;
- core_handle = GNUNET_CORE_connect (c, /* Main configuration */
- NULL, /* Closure passed to MESH functions */
- &core_init, /* Call core_init once connected */
- &core_connect, /* Handle connects */
- &core_disconnect, /* remove peers on disconnects */
- NULL, /* Don't notify about all incoming messages */
- GNUNET_NO, /* For header only in notification */
- NULL, /* Don't notify about all outbound messages */
- GNUNET_NO, /* For header-only out notification */
- core_handlers); /* Register these handlers */
-
- if (core_handle == NULL)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "hostkey");
+ ("%s service is lacking key configuration settings (%s). Exiting.\n"),
+ "mesh", "hostkey");
GNUNET_SCHEDULER_shutdown ();
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "refresh path time");
+ ("%s service is lacking key configuration settings (%s). Exiting.\n"),
+ "mesh", "refresh path time");
GNUNET_SCHEDULER_shutdown ();
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "app announce time");
+ ("%s service is lacking key configuration settings (%s). Exiting.\n"),
+ "mesh", "app announce time");
GNUNET_SCHEDULER_shutdown ();
return;
}
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "APP_ANNOUNCE_TIME %llu ms\n",
+ app_announce_time.rel_value);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (c, "MESH", "ID_ANNOUNCE_TIME",
&id_announce_time))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "id announce time");
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (c, "MESH", "UNACKNOWLEDGED_WAIT",
- &unacknowledged_wait_time))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "unacknowledged wait time");
+ ("%s service is lacking key configuration settings (%s). Exiting.\n"),
+ "mesh", "id announce time");
GNUNET_SCHEDULER_shutdown ();
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "connect timeout");
+ ("%s service is lacking key configuration settings (%s). Exiting.\n"),
+ "mesh", "connect timeout");
GNUNET_SCHEDULER_shutdown ();
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "max msgs queue");
+ ("%s service is lacking key configuration settings (%s). Exiting.\n"),
+ "mesh", "max msgs queue");
GNUNET_SCHEDULER_shutdown ();
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
- "max tunnels");
+ ("%s service is lacking key configuration settings (%s). Exiting.\n"),
+ "mesh", "max tunnels");
GNUNET_SCHEDULER_shutdown ();
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_
- ("Mesh service is lacking key configuration settings (%s). Using default (%u).\n"),
- "default ttl", 64);
+ ("%s service is lacking key configuration settings (%s). Using default (%u).\n"),
+ "mesh", "default ttl", 64);
default_ttl = 64;
}
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_PEERS",
+ &max_peers))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("%s service is lacking key configuration settings (%s). Using default (%u).\n"),
+ "mesh", "max peers", 1000);
+ max_peers = 1000;
+ }
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DHT_REPLICATION_LEVEL",
&dht_replication_level))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_
- ("Mesh service is lacking key configuration settings (%s). Using default (%u).\n"),
- "dht replication level", 10);
- dht_replication_level = 10;
+ ("%s service is lacking key configuration settings (%s). Using default (%u).\n"),
+ "mesh", "dht replication level", 3);
+ dht_replication_level = 3;
}
- tunnels = GNUNET_CONTAINER_multihashmap_create (32);
- incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32);
- peers = GNUNET_CONTAINER_multihashmap_create (32);
- applications = GNUNET_CONTAINER_multihashmap_create (32);
- types = GNUNET_CONTAINER_multihashmap_create (32);
+ tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ applications = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ types = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
dht_handle = GNUNET_DHT_connect (c, 64);
if (NULL == dht_handle)
/* Scheduled the task to clean up when shutdown is called */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
NULL);
- keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, &key_generation_cb, NULL);
+ keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile,
+ &key_generation_cb,
+ (void *) c);
GNUNET_free (keyfile);
}
main (int argc, char *const *argv)
{
int ret;
+ int r;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
- ret =
- (GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run,
- NULL)) ? 0 : 1;
+ r = GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run,
+ NULL);
+ ret = (GNUNET_OK == r) ? 0 : 1;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");
INTERVAL_SHOW;