[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r9439 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r9439 - gnunet/src/util |
Date: |
Mon, 9 Nov 2009 15:40:03 -0700 |
Author: grothoff
Date: 2009-11-09 15:40:03 -0700 (Mon, 09 Nov 2009)
New Revision: 9439
Modified:
gnunet/src/util/connection.c
gnunet/src/util/test_peer.c
Log:
code clean up
Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c 2009-11-09 21:24:44 UTC (rev 9438)
+++ gnunet/src/util/connection.c 2009-11-09 22:40:03 UTC (rev 9439)
@@ -421,17 +421,6 @@
/**
- * It is time to re-try connecting.
- *
- * @param cls the handle for the connection that should be re-tried
- * @param tc unused scheduler taks context
- */
-static void
-retry_connect_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
* This function is called after establishing a connection either has
* succeeded or timed out. Note that it is possible that the attempt
* timed out and that we're immediately retrying. If we are retrying,
@@ -798,29 +787,6 @@
/**
- * It is time to re-try connecting.
- *
- * @param cls the handle for the connection that should be re-tried
- * @param tc unused scheduler taks context
- */
-static void
-retry_connect_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct GNUNET_CONNECTION_Handle *sock = cls;
-
- GNUNET_assert (sock->dns_active == NULL);
- sock->dns_active = GNUNET_RESOLVER_ip_get (sock->sched,
- sock->cfg,
- sock->hostname,
- AF_UNSPEC,
-
GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
- &try_connect_using_address,
- sock);
-}
-
-
-/**
* Create a socket handle by (asynchronously) connecting to a host.
* This function returns immediately, even if the connection has not
* yet been established. This function only creates TCP connections.
@@ -850,7 +816,13 @@
ret->write_buffer_size = maxbuf;
ret->port = port;
ret->hostname = GNUNET_strdup (hostname);
- retry_connect_continuation (ret, NULL);
+ ret->dns_active = GNUNET_RESOLVER_ip_get (sched,
+ cfg,
+ ret->hostname,
+ AF_UNSPEC,
+
GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
+ &try_connect_using_address,
+ ret);
return ret;
}
Modified: gnunet/src/util/test_peer.c
===================================================================
--- gnunet/src/util/test_peer.c 2009-11-09 21:24:44 UTC (rev 9438)
+++ gnunet/src/util/test_peer.c 2009-11-09 22:40:03 UTC (rev 9439)
@@ -30,88 +30,76 @@
#define NUMBER_OF_PEERS 10
/*#define DEBUG*/
-/* Global Variables */
-static struct GNUNET_PeerIdentity** pidArr; /* A list of Peer ID's to play
with */
+/**
+ * A list of Peer ID's to play with
+ */
+static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS];
static void generatePeerIdList()
{
- int i; /* Loop Index */
+ int i;
- pidArr = GNUNET_malloc(NUMBER_OF_PEERS * sizeof(struct
GNUNET_PeerIdentity*));
- for (i = 0; i < NUMBER_OF_PEERS; i++ ) {
- pidArr[i] = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
&(pidArr[i]->hashPubKey));
-
+ for (i = 0; i < NUMBER_OF_PEERS; i++ ) {
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
&pidArr[i].hashPubKey);
#ifdef DEBUG
- {
- struct GNUNET_CRYPTO_HashAsciiEncoded hashAsciiEncoded;
- GNUNET_CRYPTO_hash_to_enc(&(pidArr[i]->hashPubKey),
&hashAsciiEncoded);
- printf ("I'm Peer: %s\n", (char*) &hashAsciiEncoded);
- }
+ printf ("Peer %d: %s\n",
+ i,
+ GNUNET_i2s (&pidArr[i]));
#endif
- }
+ }
}
-static void destroyPeerIdList()
-{
- int i;
- for (i = 0; i < NUMBER_OF_PEERS; i++) {
- GNUNET_free(pidArr[i]);
- }
- GNUNET_free(pidArr);
-}
static int check()
{
- int i = 0;
- GNUNET_PEER_Id pid;
+ int i;
+ GNUNET_PEER_Id pid;
- /* Insert Peers into PeerEntry table and hashmap */
- for (; i < NUMBER_OF_PEERS; i++) {
- pid = GNUNET_PEER_intern(pidArr[i]);
- if ( pid != (i + 1)) {
- fprintf(stderr, "Unexpected Peer ID returned by intern
function \n");
- return 1;
- }
- }
+ /* Insert Peers into PeerEntry table and hashmap */
+ for (i=0; i < NUMBER_OF_PEERS; i++) {
+ pid = GNUNET_PEER_intern(&pidArr[i]);
+ if ( pid != (i + 1)) {
+ fprintf(stderr, "Unexpected Peer ID returned by intern function \n");
+ return 1;
+ }
+ }
- /* Referencing the first 3 peers once again */
- for (i = 0; i < 3; i++) {
- pid = GNUNET_PEER_intern(pidArr[i]);
- if (pid != (i + 1)) {
- fprintf(stderr, "Unexpcted Peer ID returned by intern
function \n");
- return 1;
- }
- }
+ /* Referencing the first 3 peers once again */
+ for (i = 0; i < 3; i++) {
+ pid = GNUNET_PEER_intern(&pidArr[i]);
+ if (pid != (i + 1)) {
+ fprintf(stderr, "Unexpcted Peer ID returned by intern function \n");
+ return 1;
+ }
+ }
- /* Dereferencing the first 3 peers once [decrementing their reference
count] */
- {
- GNUNET_PEER_Id ids[] = {1, 2, 3};
- GNUNET_PEER_decrement_rcs(ids, 3);
- }
+ /* Dereferencing the first 3 peers once [decrementing their reference count]
*/
+ {
+ GNUNET_PEER_Id ids[] = {1, 2, 3};
+ GNUNET_PEER_decrement_rcs(ids, 3);
+ }
+
+ /* re-referencing the first 3 peers using the change_rc function */
+ for (i = 0; i < 3; i++) {
+ GNUNET_PEER_change_rc(i, 1);
+ }
+
+ /* Removing the second Peer from the PeerEntry hash map */
+ GNUNET_PEER_change_rc(2, -2);
+
+ /* convert the pid of the first PeerEntry into that of the third */
+ GNUNET_PEER_resolve(1, &pidArr[3]);
- /* re-referencing the first 3 peers using the change_rc function */
- for (i = 0; i < 3; i++) {
- GNUNET_PEER_change_rc(i, 1);
- }
-
- /* Removing the second Peer from the PeerEntry hash map */
- GNUNET_PEER_change_rc(2, -2);
-
- /* convert the pid of the first PeerEntry into that of the third */
- GNUNET_PEER_resolve(1, pidArr[3]);
-
- return 0;
+ return 0;
}
+
int main()
{
- int ret;
- GNUNET_log_setup ("test-peer", "ERROR", NULL);
- generatePeerIdList();
- ret = check();
- destroyPeerIdList();
-
- return ret;
+ GNUNET_log_setup ("test-peer", "ERROR", NULL);
+ generatePeerIdList();
+ return check();
}
+
+/* end of test_peer.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r9439 - gnunet/src/util,
gnunet <=