Переглянути джерело

Before, the count of uploaded torrent data was increases by the block size

as soon as the message head was written to the network. Now it's increased
for each byte of torrent data we've written.
master
Richard Nyberg 19 роки тому
джерело
коміт
307b9a50aa
2 змінених файлів з 16 додано та 8 видалено
  1. +15
    -8
      btpd/net.c
  2. +1
    -0
      btpd/net.h

+ 15
- 8
btpd/net.c Переглянути файл

@@ -137,8 +137,8 @@ static struct iob_link *
malloc_liob(size_t len) malloc_liob(size_t len)
{ {
struct iob_link *iol; struct iob_link *iol;
iol = (struct iob_link *)btpd_malloc(sizeof(*iol) + len);
iol->iob.buf = (char *)iol + sizeof(*iol);
iol = (struct iob_link *)btpd_calloc(1, sizeof(*iol) + len);
iol->iob.buf = (char *)(iol + 1);
iol->iob.buf_len = len; iol->iob.buf_len = len;
iol->iob.buf_off = 0; iol->iob.buf_off = 0;
iol->kill_buf = nokill_iob; iol->kill_buf = nokill_iob;
@@ -149,7 +149,7 @@ static struct iob_link *
salloc_liob(char *buf, size_t len, void (*kill_buf)(struct io_buffer *)) salloc_liob(char *buf, size_t len, void (*kill_buf)(struct io_buffer *))
{ {
struct iob_link *iol; struct iob_link *iol;
iol = (struct iob_link *)btpd_malloc(sizeof(*iol));
iol = (struct iob_link *)btpd_calloc(1, sizeof(*iol));
iol->iob.buf = buf; iol->iob.buf = buf;
iol->iob.buf_len = len; iol->iob.buf_len = len;
iol->iob.buf_off = 0; iol->iob.buf_off = 0;
@@ -235,26 +235,32 @@ again:
} }


bcount = nwritten; bcount = nwritten;
p->rate_from_me[btpd.seconds % RATEHISTORY] += nwritten;


req = BTPDQ_FIRST(&p->p_reqs); req = BTPDQ_FIRST(&p->p_reqs);
iol = BTPDQ_FIRST(&p->outq); iol = BTPDQ_FIRST(&p->outq);
while (bcount > 0) { while (bcount > 0) {
unsigned long bufdelta = iol->iob.buf_len - iol->iob.buf_off;
if (req != NULL && req->head == iol) { if (req != NULL && req->head == iol) {
struct iob_link *piece = BTPDQ_NEXT(req->head, entry);
struct piece_req *next = BTPDQ_NEXT(req, entry); struct piece_req *next = BTPDQ_NEXT(req, entry);
BTPDQ_REMOVE(&p->p_reqs, req, entry); BTPDQ_REMOVE(&p->p_reqs, req, entry);
free(req); free(req);
req = next; req = next;
p->tp->uploaded += piece->iob.buf_len;
} }
if (bcount >= iol->iob.buf_len - iol->iob.buf_off) {
bcount -= iol->iob.buf_len - iol->iob.buf_off;
if (bcount >= bufdelta) {
if (iol->upload) {
p->tp->uploaded += bufdelta;
p->rate_from_me[btpd.seconds % RATEHISTORY] += bufdelta;
}
bcount -= bufdelta;
BTPDQ_REMOVE(&p->outq, iol, entry); BTPDQ_REMOVE(&p->outq, iol, entry);
iol->kill_buf(&iol->iob); iol->kill_buf(&iol->iob);
free(iol); free(iol);
iol = BTPDQ_FIRST(&p->outq); iol = BTPDQ_FIRST(&p->outq);
} else { } else {
if (iol->upload) {
p->tp->uploaded += bcount;
p->rate_from_me[btpd.seconds % RATEHISTORY] += bcount;
}
iol->iob.buf_off += bcount; iol->iob.buf_off += bcount;
bcount = 0; bcount = 0;
} }
@@ -306,6 +312,7 @@ net_send_piece(struct peer *p, uint32_t index, uint32_t begin,
net_send(p, head); net_send(p, head);


piece = salloc_liob(block, blen, kill_free_buf); piece = salloc_liob(block, blen, kill_free_buf);
piece->upload = 1;
net_send(p, piece); net_send(p, piece);


req = btpd_malloc(sizeof(*req)); req = btpd_malloc(sizeof(*req));


+ 1
- 0
btpd/net.h Переглянути файл

@@ -20,6 +20,7 @@ struct bwlim {
BTPDQ_HEAD(bwlim_tq, bwlim); BTPDQ_HEAD(bwlim_tq, bwlim);


struct iob_link { struct iob_link {
int upload;
BTPDQ_ENTRY(iob_link) entry; BTPDQ_ENTRY(iob_link) entry;
void (*kill_buf)(struct io_buffer *); void (*kill_buf)(struct io_buffer *);
struct io_buffer iob; struct io_buffer iob;


Завантаження…
Відмінити
Зберегти