/*
This file is part of GNUnet
- (C) 2008--2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2008--2013 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.
*/
/**
* The type of this context
*/
enum {
-
+
/**
* Type for underlay topology
*/
TOPOLOGYCONTEXT_TYPE_UNDERLAY = 0,
-
+
/**
* Type for overlay topology
*/
* A array of names representing topologies. Should be in sync with enum
* GNUNET_TESTBED_TopologyOption
*/
-const char *topology_strings[] = {
+static const char *topology_strings[] = {
/**
* A clique (everyone connected to everyone else). No options. If there are N
*/
"CLIQUE",
- /**
+ /*
* Small-world network (2d torus plus random links). Followed
* by the number of random links to add (unsigned int).
*/
*/
"RING",
+ /**
+ * Star topology. No options.
+ */
+ "STAR",
+
/**
* 2-d torus. No options.
*/
* operation has executed successfully.
*/
static void
-overlay_link_completed (void *cls, struct GNUNET_TESTBED_Operation *op,
+overlay_link_completed (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
const char *emsg)
{
struct OverlayLink *link = cls;
if (0 != overlay->retry_cnt)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Error while establishing a link: %s -- Retrying\n", emsg);
+ "Error while establishing a link: %s -- Retrying\n",
+ emsg);
retry_entry = GNUNET_new (struct RetryListEntry);
retry_entry->link = link;
- GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head, overlay->rl_tail, retry_entry);
+ GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head,
+ overlay->rl_tail,
+ retry_entry);
}
}
else
{
link = retry_entry->link;
link->op =
- GNUNET_TESTBED_overlay_connect (overlay->op_cls, &overlay_link_completed,
- link, overlay->peers[link->A],
+ GNUNET_TESTBED_overlay_connect (overlay->op_cls,
+ &overlay_link_completed,
+ link,
+ overlay->peers[link->A],
overlay->peers[link->B]);
overlay->nlinks++;
- GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry);
+ GNUNET_CONTAINER_DLL_remove (overlay->rl_head,
+ overlay->rl_tail,
+ retry_entry);
GNUNET_free (retry_entry);
}
return;
}
if (NULL != overlay->comp_cb)
{
- overlay->comp_cb (overlay->comp_cb_cls, overlay->nsuccess, overlay->nfailures);
+ overlay->comp_cb (overlay->comp_cb_cls,
+ overlay->nsuccess,
+ overlay->nfailures);
}
}
for (p = 0; p < tc->link_array_size; p++)
{
overlay->link_array[p].op =
- GNUNET_TESTBED_overlay_connect (overlay->op_cls, &overlay_link_completed,
+ GNUNET_TESTBED_overlay_connect (overlay->op_cls,
+ &overlay_link_completed,
&overlay->link_array[p],
overlay->peers[overlay->link_array[p].A],
overlay->peers[overlay->link_array[p].B]);
* @return
*/
static void
-make_link (unsigned int offset, uint32_t A, uint32_t B,
+make_link (unsigned int offset,
+ uint32_t A,
+ uint32_t B,
struct TopologyContext *tc)
{
GNUNET_assert (A != B);
{
struct TopologyContextOverlay *overlay;
struct OverlayLink *olink;
-
+
overlay = &tc->u.overlay;
GNUNET_assert (offset < tc->link_array_size);
olink = &overlay->link_array[offset];
{
struct TopologyContextUnderlay *underlay;
struct UnderlayLink *ulink;
-
+
underlay = &tc->u.underlay;
GNUNET_assert (offset < tc->link_array_size);
ulink = &underlay->link_array[offset];
case TOPOLOGYCONTEXT_TYPE_OVERLAY:
{
struct TopologyContextOverlay *overlay;
-
+
overlay = &tc->u.overlay;
overlay->link_array =
- GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
+ GNUNET_new_array (tc->link_array_size,
+ struct OverlayLink);
}
break;
case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
{
struct TopologyContextUnderlay *underlay;
-
+
underlay = &tc->u.underlay;
underlay->link_array =
- GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
+ GNUNET_new_array (tc->link_array_size,
+ struct UnderlayLink);
}
break;
}
}
+/**
+ * Generates star topology
+ *
+ * @param tc the topology context
+ */
+static void
+gen_topo_star (struct TopologyContext *tc)
+{
+ unsigned int cnt;
+
+ tc->link_array_size = tc->num_peers - 1;
+ switch (tc->type)
+ {
+ case TOPOLOGYCONTEXT_TYPE_OVERLAY:
+ {
+ struct TopologyContextOverlay *overlay;
+
+ overlay = &tc->u.overlay;
+ overlay->link_array =
+ GNUNET_new_array (tc->link_array_size,
+ struct OverlayLink);
+ }
+ break;
+ case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
+ {
+ struct TopologyContextUnderlay *underlay;
+
+ underlay = &tc->u.underlay;
+ underlay->link_array =
+ GNUNET_new_array (tc->link_array_size,
+ struct UnderlayLink);
+ }
+ break;
+ }
+ for (cnt = tc->link_array_size; cnt; cnt--)
+ make_link (cnt - 1,
+ 0,
+ cnt,
+ tc);
+}
+
+
/**
* Generates ring topology
*
case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
{
struct TopologyContextUnderlay *underlay;
-
+
underlay = &tc->u.underlay;
underlay->link_array =
GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) *
case TOPOLOGYCONTEXT_TYPE_OVERLAY:
{
struct TopologyContextOverlay *overlay;
-
+
overlay = &tc->u.overlay;
overlay->link_array =
GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
*
* @param tc the topology context
* @param links the number of random links to establish
- * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to
+ * @param append #GNUNET_YES to add links to existing link array; #GNUNET_NO to
* create a new link array
*/
static void
-gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
+gen_topo_random (struct TopologyContext *tc,
+ unsigned int links,
+ int append)
{
unsigned int cnt;
unsigned int index;
uint32_t A_rand;
uint32_t B_rand;
+ if (1 == tc->num_peers)
+ return;
if (GNUNET_YES == append)
{
index = tc->link_array_size;
* network
*/
static void
-gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
+gen_topo_scale_free (struct TopologyContext *tc,
+ uint16_t cap,
+ uint8_t m)
{
unsigned int *deg;
unsigned int *etab;
case TOPOLOGYCONTEXT_TYPE_OVERLAY:
{
struct TopologyContextOverlay *overlay;
-
+
overlay = &tc->u.overlay;
- overlay->link_array =
+ overlay->link_array =
GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size);
}
break;
* @param filename the filename of the file containing topology data
*/
static void
-gen_topo_from_file (struct TopologyContext *tc, const char *filename)
+gen_topo_from_file (struct TopologyContext *tc,
+ const char *filename)
{
char *data;
char *end;
status = GNUNET_SYSERR;
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s not found\n"), filename);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Topology file %s not found\n"),
+ filename);
return;
}
if (GNUNET_OK !=
GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"),
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Topology file %s has no data\n"),
filename);
return;
}
data = GNUNET_malloc (fs);
if (fs != GNUNET_DISK_fn_read (filename, data, fs))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s cannot be read\n"),
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Topology file %s cannot be read\n"),
filename);
goto _exit;
}
case TOPOLOGYCONTEXT_TYPE_OVERLAY:
{
struct TopologyContextOverlay *overlay;
-
+
overlay = &tc->u.overlay;
- overlay->link_array =
+ overlay->link_array =
GNUNET_realloc (overlay->link_array,
sizeof (struct OverlayLink) * tc->link_array_size);
}
case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
{
struct TopologyContextUnderlay *underlay;
-
+
underlay = &tc->u.underlay;
underlay->link_array =
GNUNET_realloc (underlay->link_array,
}
else
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Ignoring to connect peer %u to peer %u\n"), peer_id,
+ _("Ignoring to connect peer %u to peer %u\n"),
+ peer_id,
other_peer_id);
while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
offset++;
- if ('\n' == data[offset])
+ if ( (offset < fs) &&
+ ('\n' == data[offset]) )
state = PEER_INDEX;
- else if ('|' == data[offset])
+ else if ( (offset < fs) &&
+ ('|' == data[offset]) )
{
state = OTHER_PEER_INDEX;
offset++;
GNUNET_free (data);
if (GNUNET_OK != status)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, "Removing link data read from the file\n");
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Removing link data read from the file\n");
tc->link_array_size = 0;
switch (tc->type)
{
case TOPOLOGYCONTEXT_TYPE_OVERLAY:
{
struct TopologyContextOverlay *overlay;
-
+
overlay = &tc->u.overlay;
GNUNET_free_non_null (overlay->link_array);
overlay->link_array = NULL;
case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
{
struct TopologyContextUnderlay *underlay;
-
+
underlay = &tc->u.underlay;
GNUNET_free_non_null (underlay->link_array);
underlay->link_array = NULL;
unsigned int cnt;
unsigned int offset;
unsigned int neighbour;
-
+
tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
switch (tc->type)
{
struct TopologyContextOverlay *overlay;
overlay = &tc->u.overlay;
- overlay->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
- tc->link_array_size);
+ overlay->link_array = GNUNET_new_array (tc->link_array_size,
+ struct OverlayLink);
}
break;
case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
struct TopologyContextUnderlay *underlay;
underlay = &tc->u.underlay;
- underlay->link_array = GNUNET_malloc (sizeof (struct UnderlayLink) *
- tc->link_array_size);
+ underlay->link_array = GNUNET_new_array (tc->link_array_size,
+ struct UnderlayLink);
}
}
offset = 0;
* Configure overall network topology to have a particular shape.
*
* @param op_cls closure argument to give with the operation event
- * @param num_peers number of peers in 'peers'
- * @param peers array of 'num_peers' with the peers to configure
+ * @param num_peers number of peers in @a peers
+ * @param peers array of @a num_peers with the peers to configure
* @param topo desired underlay topology to use
* @param ap topology-specific options
* @return handle to the operation, NULL if configuring the topology
* Configure overall network topology to have a particular shape.
*
* @param op_cls closure argument to give with the operation event
- * @param num_peers number of peers in 'peers'
- * @param peers array of 'num_peers' with the peers to configure
+ * @param num_peers number of peers in @a peers
+ * @param peers array of @a num_peers with the peers to configure
* @param topo desired underlay topology to use
* @param ... topology-specific options
* @return handle to the operation, NULL if configuring the topology
*
* @param op_cls closure argument to give with the peer connect operation events
* generated through this function
- * @param num_peers number of peers in 'peers'
- * @param peers array of 'num_peers' with the peers to configure
+ * @param num_peers number of peers in @a peers
+ * @param peers array of @a num_peers with the peers to configure
* @param max_connections the maximums number of overlay connections that will
* be made to achieve the given topology
* @param comp_cb the completion callback to call when the topology generation
case GNUNET_TESTBED_TOPOLOGY_LINE:
gen_topo_line (tc);
break;
+ case GNUNET_TESTBED_TOPOLOGY_STAR:
+ gen_topo_star (tc);
+ break;
case GNUNET_TESTBED_TOPOLOGY_RING:
gen_topo_ring (tc);
break;
GNUNET_TESTBED_operation_queue_insert_
(c->opq_parallel_topology_config_operations, op);
GNUNET_TESTBED_operation_begin_wait_ (op);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Generated %u connections\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Generated %u connections\n",
tc->link_array_size);
if (NULL != max_connections)
*max_connections = tc->link_array_size;
* @param topology where to write the retrieved topology
* @param topology_string The string to attempt to
* get a configuration value from
- * @return GNUNET_YES if topology string matched a
- * known topology, GNUNET_NO if not
+ * @return #GNUNET_YES if topology string matched a
+ * known topology, #GNUNET_NO if not
*/
int
GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
{
if (NULL != topology)
*topology = (enum GNUNET_TESTBED_TopologyOption) cnt;
+ GNUNET_assert (GNUNET_TESTBED_TOPOLOGY_OPTION_END != (enum GNUNET_TESTBED_TopologyOption) cnt);
return GNUNET_YES;
}
}
* generated
* @param proc the underlay link processor callback. Will be called for each
* underlay link generated unless a previous call to this callback
- * returned GNUNET_SYSERR. Cannot be NULL.
- * @param cls closure for proc
+ * returned #GNUNET_SYSERR. Cannot be NULL.
+ * @param cls closure for @a proc
* @param ... variable arguments denoting the topology and its parameters. They
* should start with the type of topology to generate followed by their
* options.
- * @return GNUNET_OK if underlay link generation is successful; GNUNET_SYSERR
+ * @return #GNUNET_OK if underlay link generation is successful; #GNUNET_SYSERR
* upon error in generating the underlay or if any calls to the
- * underlay link processor returned GNUNET_SYSERR
+ * underlay link processor returned #GNUNET_SYSERR
*/
int
GNUNET_TESTBED_underlay_construct_ (int num_peers,
enum GNUNET_TESTBED_TopologyOption topology;
unsigned int cnt;
int ret;
-
+
GNUNET_assert (NULL != proc);
ret = GNUNET_OK;
memset (&tc, 0, sizeof (tc));
+ tc.num_peers = num_peers;
tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
underlay = &tc.u.underlay;
va_start (vargs, cls);
case GNUNET_TESTBED_TOPOLOGY_LINE:
gen_topo_line (&tc);
break;
+ case GNUNET_TESTBED_TOPOLOGY_STAR:
+ gen_topo_star (&tc);
+ break;
case GNUNET_TESTBED_TOPOLOGY_RING:
gen_topo_ring (&tc);
break;