first,
unsigned int
second,
- enum PeerLists list);
+ enum PeerLists list,
+ unsigned int check);
/**
unsigned int current;
};
+/**
+ * Simple struct to keep track of progress, and print a
+ * nice little percentage meter for long running tasks.
+ */
+struct ProgressMeter
+{
+ unsigned int total;
+
+ unsigned int modnum;
+
+ unsigned int dotnum;
+
+ unsigned int completed;
+
+ int print;
+
+ char *startup_string;
+};
+
#if !OLD
/**
* Convert unique ID to hash code.
static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
#endif
+/**
+ * Create a meter to keep track of the progress of some task.
+ *
+ * @param total the total number of items to complete
+ * @param start_string a string to prefix the meter with (if printing)
+ * @param print GNUNET_YES to print the meter, GNUNET_NO to count
+ * internally only
+ *
+ * @return the progress meter
+ */
+static struct ProgressMeter *
+create_meter(unsigned int total, char * start_string, int print)
+{
+ struct ProgressMeter *ret;
+ ret = GNUNET_malloc(sizeof(struct ProgressMeter));
+ ret->print = print;
+ ret->total = total;
+ ret->modnum = total / 4;
+ ret->dotnum = (total / 50) + 1;
+ if (start_string != NULL)
+ ret->startup_string = GNUNET_strdup(start_string);
+ else
+ ret->startup_string = GNUNET_strdup("");
+
+ return ret;
+}
+
+/**
+ * Update progress meter (increment by one).
+ *
+ * @param meter the meter to update and print info for
+ *
+ * @return GNUNET_YES if called the total requested,
+ * GNUNET_NO if more items expected
+ */
+static int
+update_meter(struct ProgressMeter *meter)
+{
+ if (meter->print == GNUNET_YES)
+ {
+ if (meter->completed % meter->modnum == 0)
+ {
+ if (meter->completed == 0)
+ {
+ fprintf(stdout, "%sProgress: [0%%", meter->startup_string);
+ }
+ else
+ fprintf(stdout, "%d%%", (int) (((float) meter->completed
+ / meter->total) * 100));
+ }
+ else if (meter->completed % meter->dotnum == 0)
+ fprintf(stdout, ".");
+
+ if (meter->completed + 1 == meter->total)
+ fprintf(stdout, "%d%%]\n", 100);
+ fflush(stdout);
+ }
+ meter->completed++;
+
+ if (meter->completed == meter->total)
+ return GNUNET_YES;
+ if (meter->completed > meter->total)
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
+ return GNUNET_NO;
+}
+
+/**
+ * Reset progress meter.
+ *
+ * @param meter the meter to reset
+ *
+ * @return GNUNET_YES if meter reset,
+ * GNUNET_SYSERR on error
+ */
+static int
+reset_meter(struct ProgressMeter *meter)
+{
+ if (meter == NULL)
+ return GNUNET_SYSERR;
+
+ meter->completed = 0;
+ return GNUNET_YES;
+}
+
+/**
+ * Release resources for meter
+ *
+ * @param meter the meter to free
+ */
+static void
+free_meter(struct ProgressMeter *meter)
+{
+ GNUNET_free_non_null (meter->startup_string);
+ GNUNET_free (meter);
+}
+
/**
* Get a topology from a string input.
*
* @param first index of the first peer
* @param second index of the second peer
* @param list the peer list to use
+ * @param check UNUSED
*
* @return the number of connections added (can be 0, 1 or 2)
*
static unsigned int
remove_connections (struct GNUNET_TESTING_PeerGroup *pg,
unsigned int first, unsigned int second,
- enum PeerLists list)
+ enum PeerLists list, unsigned int check)
{
int removed;
#if OLD
* @param first index of the first peer
* @param second index of the second peer
* @param list the list type that we should modify
+ * @param check GNUNET_YES to check lists before adding
+ * GNUNET_NO to force add
*
* @return the number of connections added (can be 0, 1 or 2)
*
static unsigned int
add_connections (struct GNUNET_TESTING_PeerGroup *pg,
unsigned int first, unsigned int second,
- enum PeerLists list)
+ enum PeerLists list,
+ unsigned int check)
{
int added;
int add_first;
add_first = GNUNET_YES;
add_second = GNUNET_YES;
- first_iter = *first_list;
- while (first_iter != NULL)
+ if (check == GNUNET_YES)
{
- if (first_iter->index == second)
+ first_iter = *first_list;
+ while (first_iter != NULL)
{
- add_first = GNUNET_NO;
- break;
+ if (first_iter->index == second)
+ {
+ add_first = GNUNET_NO;
+ break;
+ }
+ first_iter = first_iter->next;
}
- first_iter = first_iter->next;
- }
- second_iter = *second_list;
- while (second_iter != NULL)
- {
- if (second_iter->index == first)
+ second_iter = *second_list;
+ while (second_iter != NULL)
{
- add_second = GNUNET_NO;
- break;
+ if (second_iter->index == first)
+ {
+ add_second = GNUNET_NO;
+ break;
+ }
+ second_iter = second_iter->next;
}
- second_iter = second_iter->next;
}
#else
if (GNUNET_NO ==
GNUNET_assert (pg->total > 1);
/* Add a connection between the first two nodes */
- total_connections = proc (pg, 0, 1, list);
+ total_connections = proc (pg, 0, 1, list, GNUNET_YES);
for (outer_count = 1; outer_count < pg->total; outer_count++)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connecting peer %d to peer %d\n", outer_count, i);
#endif
- total_connections += proc (pg, outer_count, i, list);
+ total_connections += proc (pg, outer_count, i, list, GNUNET_YES);
}
}
}
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
pg->total);
}
- smallWorldConnections += proc (pg, i, randomPeer, list);
+ smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES);
}
else
{
{
nodeToConnect = nodeToConnect - pg->total;
}
- connect_attempts += proc (pg, i, nodeToConnect, list);
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
}
}
"Connecting peer %d to peer %d\n",
outer_count, inner_count);
#endif
- connect_attempts += proc (pg, outer_count, inner_count, list);
+ connect_attempts += proc (pg, outer_count, inner_count, list, GNUNET_YES);
}
}
}
"Connecting peer %d to peer %d\n",
outer_count, inner_count);
#endif
- connect_attempts += proc (pg, outer_count, inner_count, list);
- add_connections(pg, outer_count, inner_count, ALLOWED);
+ connect_attempts += proc (pg, outer_count, inner_count, list, GNUNET_YES);
+ add_connections(pg, outer_count, inner_count, ALLOWED, GNUNET_YES);
}
}
}
else
nodeToConnect = i - cols + 1;
- connect_attempts += proc (pg, i, nodeToConnect, list);
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
if (i < cols)
{
nodeToConnect = i - cols;
if (nodeToConnect < pg->total)
- connect_attempts += proc (pg, i, nodeToConnect, list);
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
}
natLog = log (pg->total);
#if VERBOSE_TESTING > 2
((double) UINT64_MAX);
/* If random < probability, then connect the two nodes */
if (random < probability)
- smallWorldConnections += proc (pg, j, k, list);
+ smallWorldConnections += proc (pg, j, k, list, GNUNET_YES);
}
}
#endif
if (temp_rand < probability)
{
- connect_attempts += proc (pg, outer_count, inner_count, list);
+ connect_attempts += proc (pg, outer_count, inner_count, list, GNUNET_YES);
}
}
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connecting peer %d to peer %d\n", i, nodeToConnect);
#endif
- connect_attempts += proc (pg, i, nodeToConnect, list);
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
/* Second connect to the node immediately above */
if (i < cols)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connecting peer %d to peer %d\n", i, nodeToConnect);
#endif
- connect_attempts += proc (pg, i, nodeToConnect, list);
+ connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
}
}
* @param proc the connection processor to call to actually set
* up connections between two peers
* @param list the peer list to use
+ * @param check does the connection processor need to check before
+ * performing an action on the list?
*
* @return the number of connections that were set up
*
*/
static unsigned int
create_clique (struct GNUNET_TESTING_PeerGroup *pg,
- GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list)
+ GNUNET_TESTING_ConnectionProcessor proc,
+ enum PeerLists list,
+ unsigned int check)
{
unsigned int outer_count;
unsigned int inner_count;
int connect_attempts;
-
+ struct ProgressMeter *conn_meter;
connect_attempts = 0;
+ conn_meter = create_meter((((pg->total * pg->total) + pg->total) / 2) - pg->total, "Create Clique ", GNUNET_YES);
for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
{
for (inner_count = outer_count + 1; inner_count < pg->total;
"Connecting peer %d to peer %d\n",
outer_count, inner_count);
#endif
- connect_attempts += proc (pg, outer_count, inner_count, list);
+ connect_attempts += proc (pg, outer_count, inner_count, list, check);
+ update_meter(conn_meter);
}
}
-
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Meter has %d left\n", conn_meter->total - conn_meter->completed);
+ reset_meter(conn_meter);
+ free_meter(conn_meter);
return connect_attempts;
}
iter = pg->peers[count].allowed_peers_head;
while (iter != NULL)
{
- remove_connections(pg, count, iter->index, BLACKLIST);
+ remove_connections(pg, count, iter->index, BLACKLIST, GNUNET_YES);
//unblacklist_connections(pg, count, iter->index);
iter = iter->next;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connecting peer %d to peer %d\n", count, count + 1);
#endif
- connect_attempts += proc (pg, count, count + 1, list);
+ connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
}
return connect_attempts;
return connect_attempts;
}
/* Assume file is written with first peer 1, but array index is 0 */
- connect_attempts += proc (pg, first_peer_index - 1, second_peer_index - 1, list);
+ connect_attempts += proc (pg, first_peer_index - 1, second_peer_index - 1, list, GNUNET_YES);
while((buf[count] != '\n') && (buf[count] != ',') && (count < frstat.st_size - 1))
count++;
if (buf[count] == '\n')
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connecting peer %d to peer %d\n", count, count + 1);
#endif
- connect_attempts += proc (pg, count, count + 1, list);
+ connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
}
/* Connect the last peer to the first peer */
- connect_attempts += proc (pg, pg->total - 1, 0, list);
+ connect_attempts += proc (pg, pg->total - 1, 0, list, GNUNET_YES);
return connect_attempts;
}
while (iter != NULL)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating connection between %d and %d\n", pg_iter, iter->index);
- total += add_connections(pg, pg_iter, iter->index, CONNECT);
+ total += add_connections(pg, pg_iter, iter->index, CONNECT, GNUNET_NO);
//total += add_actual_connections(pg, pg_iter, iter->index);
iter = iter->next;
}
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n"));
#endif
- num_connections = create_clique (pg, &add_connections, ALLOWED);
+ num_connections = create_clique (pg, &add_connections, ALLOWED, GNUNET_NO);
break;
case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
#if VERBOSE_TESTING
/* Use the create clique method to initially set all connections as blacklisted. */
if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology != GNUNET_TESTING_TOPOLOGY_FROM_FILE))
- create_clique (pg, &add_connections, BLACKLIST);
+ create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO);
unblacklisted_connections = 0;
/* Un-blacklist connections as per the topology specified */
_("Blacklisting all but clique topology\n"));
#endif
unblacklisted_connections =
- create_clique (pg, &remove_connections, BLACKLIST);
+ create_clique (pg, &remove_connections, BLACKLIST, GNUNET_NO);
break;
case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
#if VERBOSE_TESTING
UINT64_MAX)) / ((double) UINT64_MAX);
if (random_number < percentage)
{
- add_connections(pg, pg_iter, conn_iter->index, WORKING_SET);
+ add_connections(pg, pg_iter, conn_iter->index, WORKING_SET, GNUNET_YES);
}
conn_iter = conn_iter->next;
}
{
conn_iter = pg->peers[pg_iter].connect_peers_head;
while (pg->peers[pg_iter].connect_peers_head != NULL)
- remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT);
+ remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES);
pg->peers[pg_iter].connect_peers_head = pg->peers[pg_iter].connect_peers_working_set_head;
pg->peers[pg_iter].connect_peers_tail = pg->peers[pg_iter].connect_peers_working_set_tail;
conn_iter = conn_iter->next;
/* We now have a random connection, connect it! */
GNUNET_assert(conn_iter != NULL);
- add_connections(pg, pg_iter, conn_iter->index, WORKING_SET);
+ add_connections(pg, pg_iter, conn_iter->index, WORKING_SET, GNUNET_YES);
}
}
#else
for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
{
while (pg->peers[pg_iter].connect_peers_head != NULL)
- remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT);
+ remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES);
pg->peers[pg_iter].connect_peers_head = pg->peers[pg_iter].connect_peers_working_set_head;
pg->peers[pg_iter].connect_peers_tail = pg->peers[pg_iter].connect_peers_working_set_tail;
temp_count++;
}
GNUNET_assert(peer_iter != NULL);
- add_connections(pg, starting_peer, peer_iter->index, WORKING_SET);
- remove_connections(pg, starting_peer, peer_iter->index, CONNECT);
+ add_connections(pg, starting_peer, peer_iter->index, WORKING_SET, GNUNET_NO);
+ remove_connections(pg, starting_peer, peer_iter->index, CONNECT, GNUNET_YES);
starting_peer = peer_iter->index;
dfs_count++;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Creating clique CONNECT topology\n"));
#endif
- create_clique (pg, &add_connections, CONNECT);
+ create_clique (pg, &add_connections, CONNECT, GNUNET_NO);
break;
case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
#if VERBOSE_TOPOLOGY