Przeglądaj źródła

At each bandwidth call the remaining bandwidht counter is set to limit / hz.

Since the set hz is (almost) never achieved the denominator is now based
on the average hz the last 5 seconds.
master
Richard Nyberg 19 lat temu
rodzic
commit
fcc9418b92
4 zmienionych plików z 37 dodań i 3 usunięć
  1. +7
    -1
      btpd/btpd.c
  2. +5
    -0
      btpd/btpd.h
  3. +24
    -2
      btpd/net.c
  4. +1
    -0
      btpd/net.h

+ 7
- 1
btpd/btpd.c Wyświetl plik

@@ -124,6 +124,10 @@ btpd_init(void)
btpd.port = 6881;

btpd.bw_hz = 8;
btpd.bwcalls = 0;
for (int i = 0; i < BWCALLHISTORY; i++)
btpd.bwrate[i] = 0;

btpd.obwlim = 0;
btpd.ibwlim = 0;
btpd.obw_left = 0;
@@ -190,10 +194,12 @@ heartbeat_cb(int sd, short type, void *arg)

btpd.seconds++;

net_bw_rate();

BTPDQ_FOREACH(tp, &btpd.cm_list, entry)
cm_by_second(tp);

evtimer_add(&btpd.heartbeat, (& (struct timeval) { 0, 1000000 }));
evtimer_add(&btpd.heartbeat, (& (struct timeval) { 1, 0 }));
}

static void


+ 5
- 0
btpd/btpd.h Wyświetl plik

@@ -25,6 +25,8 @@

#define BTPD_VERSION (PACKAGE_NAME "/" PACKAGE_VERSION)

#define BWCALLHISTORY 5

struct child {
pid_t pid;
void *data;
@@ -56,6 +58,9 @@ struct btpd {
int ipc_sd;

unsigned bw_hz;
double bw_hz_avg;
unsigned bwcalls;
unsigned bwrate[BWCALLHISTORY];
unsigned long obwlim, ibwlim;
unsigned long ibw_left, obw_left;
struct event bwlim;


+ 24
- 2
btpd/net.c Wyświetl plik

@@ -846,13 +846,35 @@ net_by_second(void)
}
}

void
net_bw_rate(void)
{
unsigned sum = 0;
for (int i = 0; i < BWCALLHISTORY - 1; i++) {
btpd.bwrate[i] = btpd.bwrate[i + 1];
sum += btpd.bwrate[i];
}
btpd.bwrate[BWCALLHISTORY - 1] = btpd.bwcalls;
sum += btpd.bwrate[BWCALLHISTORY - 1];
btpd.bwcalls = 0;
btpd.bw_hz_avg = sum / 5.0;
}

void
net_bw_cb(int sd, short type, void *arg)
{
struct peer *p;

btpd.obw_left = btpd.obwlim / btpd.bw_hz;
btpd.ibw_left = btpd.ibwlim / btpd.bw_hz;
btpd.bwcalls++;

double avg_hz;
if (btpd.seconds < BWCALLHISTORY)
avg_hz = btpd.bw_hz;
else
avg_hz = btpd.bw_hz_avg;

btpd.obw_left = btpd.obwlim / avg_hz;
btpd.ibw_left = btpd.ibwlim / avg_hz;

if (btpd.ibwlim > 0) {
while ((p = BTPDQ_FIRST(&btpd.readq)) != NULL && btpd.ibw_left > 0) {


+ 1
- 0
btpd/net.h Wyświetl plik

@@ -74,6 +74,7 @@ struct piece_req {
BTPDQ_HEAD(piece_req_tq, piece_req);

void net_connection_cb(int sd, short type, void *arg);
void net_bw_rate(void);
void net_bw_cb(int sd, short type, void *arg);

struct peer;


Ładowanie…
Anuluj
Zapisz