[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3345 - in GNUnet/src: applications/session transports util
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3345 - in GNUnet/src: applications/session transports util/network util/os |
Date: |
Tue, 29 Aug 2006 11:57:41 -0700 (PDT) |
Author: grothoff
Date: 2006-08-29 11:57:35 -0700 (Tue, 29 Aug 2006)
New Revision: 3345
Modified:
GNUnet/src/applications/session/peer2.conf
GNUnet/src/applications/session/sessiontest.c
GNUnet/src/transports/tcp_helper.c
GNUnet/src/util/network/select.c
GNUnet/src/util/os/statuscalls.c
Log:
fixes
Modified: GNUnet/src/applications/session/peer2.conf
===================================================================
--- GNUnet/src/applications/session/peer2.conf 2006-08-29 17:41:31 UTC (rev
3344)
+++ GNUnet/src/applications/session/peer2.conf 2006-08-29 18:57:35 UTC (rev
3345)
@@ -1,4 +1,4 @@
-ps# This is the configuration for the GNUnet daemon when running
+# This is the configuration for the GNUnet daemon when running
# the test in this directory (make check).
[GNUNETD]
Modified: GNUnet/src/applications/session/sessiontest.c
===================================================================
--- GNUnet/src/applications/session/sessiontest.c 2006-08-29 17:41:31 UTC
(rev 3344)
+++ GNUnet/src/applications/session/sessiontest.c 2006-08-29 18:57:35 UTC
(rev 3345)
@@ -31,6 +31,8 @@
#include "gnunet_util_network_client.h"
#include "gnunet_stats_lib.h"
+#define START_PEERS 0
+
static int ok;
static int waitForConnect(const char * name,
@@ -53,8 +55,10 @@
* @return 0: ok, -1: error
*/
int main(int argc, char ** argv) {
+#if START_PEERS
pid_t daemon1;
pid_t daemon2;
+#endif
int ret;
struct ClientServerConnection * sock;
int left;
@@ -66,6 +70,7 @@
GC_free(cfg);
return -1;
}
+#if START_PEERS
daemon1 = os_daemon_start(NULL,
cfg,
"peer1.conf",
@@ -74,11 +79,13 @@
cfg,
"peer2.conf",
NO);
+#endif
/* in case existing hellos have expired */
PTHREAD_SLEEP(30 * cronSECONDS);
system("cp peer1/data/hosts/* peer2/data/hosts/");
system("cp peer2/data/hosts/* peer1/data/hosts/");
ret = 0;
+#if START_PEERS
if (daemon1 != -1) {
if (os_daemon_stop(NULL, daemon1) != YES)
ret = 1;
@@ -97,6 +104,7 @@
cfg,
"peer2.conf",
NO);
+#endif
if (OK == connection_wait_for_running(NULL,
cfg,
30 * cronSECONDS)) {
@@ -120,6 +128,7 @@
printf("Could not establish connection with peer.\n");
}
connection_destroy(sock);
+#if START_PEERS
if (daemon1 != -1) {
if (os_daemon_stop(NULL, daemon1) != YES)
ret = 1;
@@ -128,6 +137,7 @@
if (os_daemon_stop(NULL, daemon2) != YES)
ret = 1;
}
+#endif
if (ok == 0)
ret = 1;
Modified: GNUnet/src/transports/tcp_helper.c
===================================================================
--- GNUnet/src/transports/tcp_helper.c 2006-08-29 17:41:31 UTC (rev 3344)
+++ GNUnet/src/transports/tcp_helper.c 2006-08-29 18:57:35 UTC (rev 3345)
@@ -102,9 +102,13 @@
MUTEX_UNLOCK(tcpsession->lock);
return OK;
}
- MUTEX_UNLOCK(tcpsession->lock);
select_disconnect(selector,
tcpsession->sock);
+ MUTEX_UNLOCK(tcpsession->lock);
+ MUTEX_DESTROY(tcpsession->lock);
+ FREE(tcpsession);
+ FREE(tsession);
+
return OK;
}
@@ -230,13 +234,6 @@
struct SelectHandle * sh,
struct SocketHandle * sock,
void * sock_ctx) {
- TSession * tsession = sock_ctx;
- TCPSession * tcpsession = tsession->internal;
-
- GE_ASSERT(ectx, tcpsession != NULL);
- MUTEX_DESTROY(tcpsession->lock);
- FREE(tcpsession);
- FREE(tsession);
}
/**
@@ -287,6 +284,11 @@
mp,
NO,
important);
+ if ( (OK == ok) &&
+ (stats != NULL) )
+ stats->change(stat_bytesSent,
+ size);
+
FREE(mp);
return ok;
}
@@ -312,7 +314,7 @@
tsession->internal = tcpSession;
tsession->ttype = protocolNumber;
tcpSession->lock = MUTEX_CREATE(YES);
- tcpSession->users = 2; /* caller + us */
+ tcpSession->users = 1; /* caller */
tcpSession->sender = helo->senderIdentity;
tcpSession->expectingWelcome = NO;
MUTEX_LOCK(tcplock);
@@ -332,10 +334,13 @@
&welcome.header,
sizeof(TCPWelcome),
YES)) {
+ /* disconnect caller -- error! */
tcpDisconnect(tsession);
MUTEX_UNLOCK(tcplock);
return SYSERR;
- }
+ } else if (stats != NULL)
+ stats->change(stat_bytesSent,
+ sizeof(TCPWelcome));
MUTEX_UNLOCK(tcplock);
*tsessionPtr = tsession;
return OK;
Modified: GNUnet/src/util/network/select.c
===================================================================
--- GNUnet/src/util/network/select.c 2006-08-29 17:41:31 UTC (rev 3344)
+++ GNUnet/src/util/network/select.c 2006-08-29 18:57:35 UTC (rev 3345)
@@ -726,7 +726,8 @@
struct SocketHandle * sock) {
Session * session;
int i;
-
+
+ session = NULL;
MUTEX_LOCK(sh->lock);
for (i=0;i<sh->sessionCount;i++)
if (sh->sessions[i]->sock == sock) {
Modified: GNUnet/src/util/os/statuscalls.c
===================================================================
--- GNUnet/src/util/os/statuscalls.c 2006-08-29 17:41:31 UTC (rev 3344)
+++ GNUnet/src/util/os/statuscalls.c 2006-08-29 18:57:35 UTC (rev 3345)
@@ -65,6 +65,24 @@
unsigned long long last_out;
} NetworkStats;
+typedef struct {
+ unsigned long long overload;
+
+ unsigned long long lastSum;
+
+ cron_t lastCall;
+
+ int lastValue;
+
+ int have_last;
+
+ /**
+ * Maximum bandwidth as per config.
+ */
+ unsigned long long max;
+
+} DirectionInfo;
+
typedef struct LoadMonitor {
/**
@@ -83,16 +101,6 @@
unsigned int ifcsSize;
/**
- * Maximum bandwidth (down) as per config.
- */
- unsigned long long maxNetDownBPS;
-
- /**
- * Maximum bandwidth (up) as per config.
- */
- unsigned long long maxNetUpBPS;
-
- /**
* How to measure traffic (YES == only gnunetd,
* NO == try to include all apps)
*/
@@ -111,6 +119,10 @@
struct GC_Configuration * cfg;
+ DirectionInfo upload_info;
+
+ DirectionInfo download_info;
+
} LoadMonitor;
void os_network_monitor_notify_transmission(struct LoadMonitor * monitor,
@@ -321,14 +333,14 @@
0,
(unsigned long long)-1,
50000,
- &monitor->maxNetDownBPS);
+ &monitor->download_info.max);
GC_get_configuration_value_number(cfg,
"LOAD",
"MAXNETUPBPSTOTAL",
0,
(unsigned long long)-1,
50000,
- &monitor->maxNetUpBPS);
+ &monitor->upload_info.max);
MUTEX_UNLOCK(monitor->statusMutex);
return 0;
}
@@ -344,9 +356,9 @@
if (monitor == NULL)
return -1;
if (dir == Upload)
- return monitor->maxNetUpBPS;
+ return monitor->upload_info.max;
else if (dir == Download)
- return monitor->maxNetDownBPS;
+ return monitor->download_info.max;
return -1;
}
@@ -357,10 +369,7 @@
*/
int os_network_monitor_get_load(struct LoadMonitor * monitor,
NetworkDirection dir) {
- static unsigned long long overload;
- static unsigned long long lastSum;
- static cron_t lastCall;
- static int lastValue;
+ DirectionInfo * di;
cron_t now;
unsigned long long maxExpect;
unsigned long long currentLoadSum;
@@ -370,49 +379,64 @@
if (monitor == NULL)
return 0; /* no limits */
+ if (dir == Upload)
+ di = &monitor->upload_info;
+ else
+ di = &monitor->download_info;
+
MUTEX_LOCK(monitor->statusMutex);
now = get_time();
if ( (monitor->useBasicMethod == NO) &&
- (now - lastCall > 10 * cronSECONDS) )
+ (now - di->lastCall > 10 * cronSECONDS) )
updateInterfaceTraffic(monitor);
- currentLoadSum = monitor->globalTrafficBetweenProc.last_in;
- for (i=0;i<monitor->ifcsSize;i++)
- currentLoadSum += monitor->ifcs[i].last_in;
- if ( (lastSum > currentLoadSum) ||
- (lastSum == 0) ||
- (now < lastCall) ) {
+ if (dir == Upload) {
+ currentLoadSum = monitor->globalTrafficBetweenProc.last_out;
+ for (i=0;i<monitor->ifcsSize;i++)
+ currentLoadSum += monitor->ifcs[i].last_out;
+ } else {
+ currentLoadSum = monitor->globalTrafficBetweenProc.last_in;
+ for (i=0;i<monitor->ifcsSize;i++)
+ currentLoadSum += monitor->ifcs[i].last_in;
+ }
+ if ( (di->lastSum > currentLoadSum) ||
+ (di->have_last == 0) ||
+ (now < di->lastCall) ) {
/* integer overflow or first datapoint; since we cannot tell where
/ by how much the overflow happened, all we can do is ignore
this datapoint. So we return -1 -- AND reset lastSum / lastCall. */
- lastSum = currentLoadSum;
- lastCall = now;
+ di->lastSum = currentLoadSum;
+ di->lastCall = now;
+ di->have_last = 1;
MUTEX_UNLOCK(monitor->statusMutex);
return -1;
}
- if (monitor->maxNetDownBPS == 0) {
+ if (di->max == 0) {
MUTEX_UNLOCK(monitor->statusMutex);
return -1;
}
- maxExpect = (now - lastCall) * monitor->maxNetDownBPS / cronSECONDS;
- if (now - lastCall < 5 * cronSECONDS) {
+ maxExpect = (now - di->lastCall) * di->max / cronSECONDS;
+ if (now - di->lastCall < 5 * cronSECONDS) {
/* return weighted average between last return value and
load in the last interval */
- weight = (now - lastCall) * 100 / (5 * cronSECONDS); /* how close are we
to lastCall? */
- ret = (lastValue * (100-weight) + weight * (currentLoadSum - lastSum) /
maxExpect) / 2;
+ weight = (now - di->lastCall) * 100 / (5 * cronSECONDS); /* how close are
we to lastCall? */
+ if (maxExpect == 0)
+ ret = di->lastValue;
+ else
+ ret = (di->lastValue * (100-weight) + weight * (currentLoadSum -
di->lastSum) / maxExpect) / 2;
MUTEX_UNLOCK(monitor->statusMutex);
return ret;
}
- currentLoadSum -= lastSum;
- lastSum += currentLoadSum;
- currentLoadSum += overload;
- lastCall = now;
+ currentLoadSum -= di->lastSum;
+ di->lastSum += currentLoadSum;
+ currentLoadSum += di->overload;
+ di->lastCall = now;
if (currentLoadSum < maxExpect)
- overload = 0;
+ di->overload = 0;
else
- overload = currentLoadSum - maxExpect;
- lastValue = currentLoadSum * 100 / maxExpect;
- ret = lastValue;
+ di->overload = currentLoadSum - maxExpect;
+ di->lastValue = currentLoadSum * 100 / maxExpect;
+ ret = di->lastValue;
MUTEX_UNLOCK(monitor->statusMutex);
return ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3345 - in GNUnet/src: applications/session transports util/network util/os,
grothoff <=