[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8121 - GNUnet/src/applications/topology_default
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8121 - GNUnet/src/applications/topology_default |
Date: |
Fri, 16 Jan 2009 16:03:15 -0700 (MST) |
Author: nevans
Date: 2009-01-16 16:03:15 -0700 (Fri, 16 Jan 2009)
New Revision: 8121
Modified:
GNUnet/src/applications/topology_default/topology.c
Log:
Modified: GNUnet/src/applications/topology_default/topology.c
===================================================================
--- GNUnet/src/applications/topology_default/topology.c 2009-01-16 21:14:51 UTC
(rev 8120)
+++ GNUnet/src/applications/topology_default/topology.c 2009-01-16 23:03:15 UTC
(rev 8121)
@@ -84,35 +84,44 @@
*/
static double saturation = 0.0;
-/**
- * Array of our friends.
- */
-static GNUNET_PeerIdentity *friends;
+typedef struct
+{
+ /**
+ * Array of our friends.
+ */
+ GNUNET_PeerIdentity *friends;
-/**
- * Number of friends that we have.
- */
-static unsigned int friendCount;
+ /**
+ * Number of friends that we have.
+ */
+ unsigned int friendCount;
-/**
- * Minimum number of friends to have in the
- * connection set.
- */
-static unsigned int minimum_friend_count;
+ /**
+ * Minimum number of friends to have in the
+ * connection set.
+ */
+ unsigned int minimum_friend_count;
-/**
- * Flag to disallow non-friend connections (pure F2F mode).
- */
-static int friends_only;
+ /**
+ * Flag to disallow non-friend connections (pure F2F mode).
+ */
+ int friends_only;
-/**
- * Last modification of friends file
- */
-static time_t friends_mtime;
+ /**
+ * Last modification of friends file
+ */
+ time_t friends_mtime;
+ /**
+ * Last size of friends file
+ */
+ unsigned int friends_size;
+} FriendListInfo;
+static FriendListInfo fInfo;
+
/**
- * Record for state maintanance between scanHelperCount,
+ * Record for state maintenance between scanHelperCount,
* scanHelperSelect and scanForHosts.
*/
typedef struct
@@ -432,33 +441,33 @@
if (0 != strcmp (section, "F2F"))
return 0;
- friends_only = GNUNET_GC_get_configuration_value_yesno (cfg,
+ fInfo.friends_only = GNUNET_GC_get_configuration_value_yesno (cfg,
"F2F",
"FRIENDS-ONLY",
GNUNET_NO);
- if (friends_only == GNUNET_SYSERR)
+ if (fInfo.friends_only == GNUNET_SYSERR)
return GNUNET_SYSERR; /* invalid */
opt = 0;
GNUNET_GC_get_configuration_value_number (cfg,
"F2F",
"MINIMUM",
0, 1024 * 1024, 0, &opt);
- minimum_friend_count = (unsigned int) opt;
- GNUNET_array_grow (friends, friendCount, 0);
+ fInfo.minimum_friend_count = (unsigned int) opt;
+
fn = NULL;
GNUNET_GC_get_configuration_value_filename (cfg,
"F2F",
"FRIENDS",
GNUNET_DEFAULT_DAEMON_VAR_DIRECTORY
"/friends", &fn);
- /**Nate change, don't beat me up if it's not pretty!*/
+
if (GNUNET_OK != GNUNET_disk_file_test (ectx, fn))
GNUNET_disk_file_write (ectx, fn, NULL, 0, "600");
if ((0 == GNUNET_disk_file_test (ectx, fn)) || (0 != STAT (fn, &frstat)))
{
GNUNET_free (fn);
fn = NULL;
- if ((friends_only) || (minimum_friend_count > 0))
+ if ((fInfo.friends_only) || (fInfo.minimum_friend_count > 0))
{
GNUNET_GE_LOG (ectx,
GNUNET_GE_USER | GNUNET_GE_ADMIN | GNUNET_GE_ERROR |
@@ -467,8 +476,11 @@
return GNUNET_SYSERR;
}
}
- if (frstat.st_mtime != friends_mtime)
- friends_mtime = frstat.st_mtime;
+ if ((frstat.st_mtime != fInfo.friends_mtime) || (frstat.st_size !=
fInfo.friends_size))
+ {
+ fInfo.friends_mtime = frstat.st_mtime;
+ fInfo.friends_size = frstat.st_size;
+ }
else
{
GNUNET_free_non_null (fn);
@@ -476,6 +488,7 @@
}
if ((fn != NULL) && (frstat.st_size > 0))
{
+ GNUNET_array_grow (fInfo.friends, fInfo.friendCount, 0);
data = GNUNET_malloc (frstat.st_size);
if (frstat.st_size !=
GNUNET_disk_file_read (ectx, fn, frstat.st_size, data))
@@ -511,8 +524,8 @@
enc.encoding[sizeof (GNUNET_EncName) - 1] = '\0';
if (GNUNET_OK == GNUNET_enc_to_hash ((char *) &enc, &hc))
{
- GNUNET_array_grow (friends, friendCount, friendCount + 1);
- friends[friendCount - 1].hashPubKey = hc;
+ GNUNET_array_grow (fInfo.friends, fInfo.friendCount,
fInfo.friendCount + 1);
+ fInfo.friends[fInfo.friendCount - 1].hashPubKey = hc;
}
else
{
@@ -527,15 +540,15 @@
while ((pos < frstat.st_size) && isspace (data[pos]))
pos++;
}
- if ((minimum_friend_count > friendCount) && (friends_only == GNUNET_NO))
+ if ((fInfo.minimum_friend_count > fInfo.friendCount) &&
(fInfo.friends_only == GNUNET_NO))
{
GNUNET_GE_LOG (ectx,
GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
_
("Fewer friends specified than required by minimum
friend count. Will only connect to friends.\n"));
}
- if ((minimum_friend_count >
- coreAPI->core_slots_count ()) && (friends_only == GNUNET_NO))
+ if ((fInfo.minimum_friend_count >
+ coreAPI->core_slots_count ()) && (fInfo.friends_only == GNUNET_NO))
{
GNUNET_GE_LOG (ectx,
GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
@@ -554,8 +567,8 @@
unsigned int i;
rereadConfiguration (NULL, coreAPI->cfg, coreAPI->ectx, "F2F", NULL);
- for (i = 0; i < friendCount; i++)
- if (0 == memcmp (&friends[i], peer, sizeof (GNUNET_PeerIdentity)))
+ for (i = 0; i < fInfo.friendCount; i++)
+ if (0 == memcmp (&fInfo.friends[i], peer, sizeof (GNUNET_PeerIdentity)))
return 1;
return 0;
}
@@ -596,9 +609,9 @@
return GNUNET_SYSERR; /* disallow connections to self */
if (is_friend (peer))
return GNUNET_OK;
- if (friends_only)
+ if (fInfo.friends_only)
return GNUNET_SYSERR;
- if (count_connected_friends (&core_wrapper, NULL) >= minimum_friend_count)
+ if (count_connected_friends (&core_wrapper, NULL) >=
fInfo.minimum_friend_count)
return GNUNET_OK;
return GNUNET_SYSERR;
}
@@ -614,7 +627,7 @@
if (!is_friend (peer))
return GNUNET_NO;
if (count_connected_friends (connectionIterator, cls) <=
- minimum_friend_count)
+ fInfo.minimum_friend_count)
return GNUNET_YES;
return GNUNET_NO;
}
@@ -622,7 +635,7 @@
static unsigned int
countGuardedConnections ()
{
- return minimum_friend_count;
+ return fInfo.minimum_friend_count;
}
GNUNET_Topology_ServiceAPI *
@@ -691,7 +704,7 @@
coreAPI->service_release (pingpong);
pingpong = NULL;
coreAPI = NULL;
- GNUNET_array_grow (friends, friendCount, 0);
+ GNUNET_array_grow (fInfo.friends, fInfo.friendCount, 0);
return GNUNET_OK;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8121 - GNUnet/src/applications/topology_default,
gnunet <=