/*
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
*/
{
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);
case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
{
struct TopologyContextUnderlay *underlay;
-
+
underlay = &tc->u.underlay;
underlay->link_array =
GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
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++;
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
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,
* 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);