Browse Source

More logging: discarded pieces and peer_id.

master
Richard Nyberg 19 years ago
parent
commit
89b0b8b359
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      btpd/peer.c

+ 17
- 10
btpd/peer.c View File

@@ -2,6 +2,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>


#include <ctype.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@@ -305,6 +306,13 @@ peer_create_out_compact(struct torrent *tp, const char *compact)
void void
peer_on_shake(struct peer *p) peer_on_shake(struct peer *p)
{ {
uint8_t printid[21];
int i;
for (i = 0; i < 20 && isprint(p->id[i]); i++)
printid[i] = p->id[i];
printid[i] = '\0';
btpd_log(BTPD_L_MSG, "received shake with id=\'%s\', from %p.\n",
printid, p);
btpd_log(BTPD_L_MSG, "received shake from %p.\n", p); btpd_log(BTPD_L_MSG, "received shake from %p.\n", p);
p->piece_field = btpd_calloc(1, (int)ceil(p->tp->meta.npieces / 8.0)); p->piece_field = btpd_calloc(1, (int)ceil(p->tp->meta.npieces / 8.0));
if (p->tp->have_npieces > 0) { if (p->tp->have_npieces > 0) {
@@ -395,21 +403,20 @@ void
peer_on_piece(struct peer *p, uint32_t index, uint32_t begin, peer_on_piece(struct peer *p, uint32_t index, uint32_t begin,
uint32_t length, const char *data) uint32_t length, const char *data)
{ {
btpd_log(BTPD_L_MSG, "received piece(%u,%u,%u) from %p\n",
index, begin, length, p);
struct block_request *req = BTPDQ_FIRST(&p->my_reqs); struct block_request *req = BTPDQ_FIRST(&p->my_reqs);
if (req == NULL) if ((req != NULL &&
return; nb_get_begin(req->blk->msg) == begin &&
struct net_buf *nb = req->blk->msg; nb_get_index(req->blk->msg) == index &&
if (nb_get_begin(nb) == begin && nb_get_length(req->blk->msg) == length)) {
nb_get_index(nb) == index && btpd_log(BTPD_L_MSG, "received piece(%u,%u,%u) from %p\n",
nb_get_length(nb) == length) { index, begin, length, p);

assert(p->nreqs_out > 0); assert(p->nreqs_out > 0);
p->nreqs_out--; p->nreqs_out--;
BTPDQ_REMOVE(&p->my_reqs, req, p_entry); BTPDQ_REMOVE(&p->my_reqs, req, p_entry);
cm_on_block(p, req, index, begin, length, data); cm_on_block(p, req, index, begin, length, data);
} } else
btpd_log(BTPD_L_MSG, "discarded piece(%u,%u,%u) from %p\n",
index, begin, length, p);
} }


void void


||||||
x
 
000:0
Loading…
Cancel
Save