@@ -106,7 +106,7 @@ heartbeat_cb(int sd, short type, void *arg) | |||||
btpd_seconds++; | btpd_seconds++; | ||||
BTPDQ_FOREACH(tp, &m_torrents, entry) | BTPDQ_FOREACH(tp, &m_torrents, entry) | ||||
cm_by_second(tp); | |||||
dl_by_second(tp); | |||||
evtimer_add(&m_heartbeat, (& (struct timeval) { 1, 0 })); | evtimer_add(&m_heartbeat, (& (struct timeval) { 1, 0 })); | ||||
} | } | ||||
@@ -26,9 +26,9 @@ peer_kill(struct peer *p) | |||||
btpd_log(BTPD_L_CONN, "killed peer %p\n", p); | btpd_log(BTPD_L_CONN, "killed peer %p\n", p); | ||||
if (p->flags & PF_ATTACHED) | if (p->flags & PF_ATTACHED) | ||||
cm_on_lost_peer(p); | |||||
dl_on_lost_peer(p); | |||||
else | else | ||||
BTPDQ_REMOVE(&net_unattached, p, cm_entry); | |||||
BTPDQ_REMOVE(&net_unattached, p, p_entry); | |||||
if (p->flags & PF_ON_READQ) | if (p->flags & PF_ON_READQ) | ||||
BTPDQ_REMOVE(&net_bw_readq, p, rq_entry); | BTPDQ_REMOVE(&net_bw_readq, p, rq_entry); | ||||
if (p->flags & PF_ON_WRITEQ) | if (p->flags & PF_ON_WRITEQ) | ||||
@@ -268,7 +268,7 @@ peer_create_common(int sd) | |||||
event_set(&p->in_ev, p->sd, EV_READ, net_read_cb, p); | event_set(&p->in_ev, p->sd, EV_READ, net_read_cb, p); | ||||
event_add(&p->in_ev, NULL); | event_add(&p->in_ev, NULL); | ||||
BTPDQ_INSERT_TAIL(&net_unattached, p, cm_entry); | |||||
BTPDQ_INSERT_TAIL(&net_unattached, p, p_entry); | |||||
net_npeers++; | net_npeers++; | ||||
return p; | return p; | ||||
} | } | ||||
@@ -348,7 +348,7 @@ peer_on_shake(struct peer *p) | |||||
peer_send(p, nb_create_bitdata(p->tp)); | peer_send(p, nb_create_bitdata(p->tp)); | ||||
} | } | ||||
} | } | ||||
cm_on_new_peer(p); | |||||
dl_on_new_peer(p); | |||||
} | } | ||||
void | void | ||||
@@ -361,7 +361,7 @@ peer_on_choke(struct peer *p) | |||||
if (p->nreqs_out > 0) | if (p->nreqs_out > 0) | ||||
peer_on_no_reqs(p); | peer_on_no_reqs(p); | ||||
p->flags |= PF_P_CHOKE; | p->flags |= PF_P_CHOKE; | ||||
cm_on_choke(p); | |||||
dl_on_choke(p); | |||||
struct nb_link *nl = BTPDQ_FIRST(&p->outq); | struct nb_link *nl = BTPDQ_FIRST(&p->outq); | ||||
while (nl != NULL) { | while (nl != NULL) { | ||||
struct nb_link *next = BTPDQ_NEXT(nl, entry); | struct nb_link *next = BTPDQ_NEXT(nl, entry); | ||||
@@ -380,7 +380,7 @@ peer_on_unchoke(struct peer *p) | |||||
return; | return; | ||||
else { | else { | ||||
p->flags &= ~PF_P_CHOKE; | p->flags &= ~PF_P_CHOKE; | ||||
cm_on_unchoke(p); | |||||
dl_on_unchoke(p); | |||||
} | } | ||||
} | } | ||||
@@ -392,7 +392,7 @@ peer_on_interest(struct peer *p) | |||||
return; | return; | ||||
else { | else { | ||||
p->flags |= PF_P_WANT; | p->flags |= PF_P_WANT; | ||||
cm_on_interest(p); | |||||
dl_on_interest(p); | |||||
} | } | ||||
} | } | ||||
@@ -404,7 +404,7 @@ peer_on_uninterest(struct peer *p) | |||||
return; | return; | ||||
else { | else { | ||||
p->flags &= ~PF_P_WANT; | p->flags &= ~PF_P_WANT; | ||||
cm_on_uninterest(p); | |||||
dl_on_uninterest(p); | |||||
} | } | ||||
} | } | ||||
@@ -415,7 +415,7 @@ peer_on_have(struct peer *p, uint32_t index) | |||||
if (!has_bit(p->piece_field, index)) { | if (!has_bit(p->piece_field, index)) { | ||||
set_bit(p->piece_field, index); | set_bit(p->piece_field, index); | ||||
p->npieces++; | p->npieces++; | ||||
cm_on_piece_ann(p, index); | |||||
dl_on_piece_ann(p, index); | |||||
} | } | ||||
} | } | ||||
@@ -428,7 +428,7 @@ peer_on_bitfield(struct peer *p, const uint8_t *field) | |||||
for (uint32_t i = 0; i < p->tp->meta.npieces; i++) { | for (uint32_t i = 0; i < p->tp->meta.npieces; i++) { | ||||
if (has_bit(p->piece_field, i)) { | if (has_bit(p->piece_field, i)) { | ||||
p->npieces++; | p->npieces++; | ||||
cm_on_piece_ann(p, i); | |||||
dl_on_piece_ann(p, i); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -449,7 +449,7 @@ peer_on_piece(struct peer *p, uint32_t index, uint32_t begin, | |||||
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); | |||||
dl_on_block(p, req, index, begin, length, data); | |||||
if (p->nreqs_out == 0) | if (p->nreqs_out == 0) | ||||
peer_on_no_reqs(p); | peer_on_no_reqs(p); | ||||
} else | } else | ||||
@@ -61,7 +61,7 @@ struct peer { | |||||
size_t off; | size_t off; | ||||
} net; | } net; | ||||
BTPDQ_ENTRY(peer) cm_entry; | |||||
BTPDQ_ENTRY(peer) p_entry; | |||||
BTPDQ_ENTRY(peer) rq_entry; | BTPDQ_ENTRY(peer) rq_entry; | ||||
BTPDQ_ENTRY(peer) wq_entry; | BTPDQ_ENTRY(peer) wq_entry; | ||||
@@ -11,38 +11,38 @@ void next_optimistic(struct torrent *tp, struct peer *np); | |||||
int piece_full(struct piece *pc); | int piece_full(struct piece *pc); | ||||
void piece_free(struct piece *pc); | void piece_free(struct piece *pc); | ||||
void cm_on_piece_unfull(struct piece *pc); | |||||
void cm_on_piece(struct piece *pc); | |||||
struct piece *cm_new_piece(struct torrent *tp, uint32_t index); | |||||
struct piece *cm_find_piece(struct torrent *tp, uint32_t index); | |||||
unsigned cm_piece_assign_requests(struct piece *pc, struct peer *p); | |||||
unsigned cm_assign_requests(struct peer *p); | |||||
void cm_assign_requests_eg(struct peer *p); | |||||
void cm_unassign_requests(struct peer *p); | |||||
void cm_unassign_requests_eg(struct peer *p); | |||||
void cm_piece_reorder_eg(struct piece *pc); | |||||
void dl_on_piece_unfull(struct piece *pc); | |||||
void dl_on_piece(struct piece *pc); | |||||
struct piece *dl_new_piece(struct torrent *tp, uint32_t index); | |||||
struct piece *dl_find_piece(struct torrent *tp, uint32_t index); | |||||
unsigned dl_piece_assign_requests(struct piece *pc, struct peer *p); | |||||
unsigned dl_assign_requests(struct peer *p); | |||||
void dl_assign_requests_eg(struct peer *p); | |||||
void dl_unassign_requests(struct peer *p); | |||||
void dl_unassign_requests_eg(struct peer *p); | |||||
void dl_piece_reorder_eg(struct piece *pc); | |||||
// policy_if.c | // policy_if.c | ||||
void cm_by_second(struct torrent *tp); | |||||
void cm_on_new_peer(struct peer *p); | |||||
void cm_on_lost_peer(struct peer *p); | |||||
void cm_on_choke(struct peer *p); | |||||
void cm_on_unchoke(struct peer *p); | |||||
void cm_on_upload(struct peer *p); | |||||
void cm_on_unupload(struct peer *p); | |||||
void cm_on_interest(struct peer *p); | |||||
void cm_on_uninterest(struct peer *p); | |||||
void cm_on_download(struct peer *p); | |||||
void cm_on_undownload(struct peer *p); | |||||
void cm_on_piece_ann(struct peer *p, uint32_t index); | |||||
void cm_on_block(struct peer *p, struct block_request *req, | |||||
void dl_by_second(struct torrent *tp); | |||||
void dl_on_new_peer(struct peer *p); | |||||
void dl_on_lost_peer(struct peer *p); | |||||
void dl_on_choke(struct peer *p); | |||||
void dl_on_unchoke(struct peer *p); | |||||
void dl_on_upload(struct peer *p); | |||||
void dl_on_unupload(struct peer *p); | |||||
void dl_on_interest(struct peer *p); | |||||
void dl_on_uninterest(struct peer *p); | |||||
void dl_on_download(struct peer *p); | |||||
void dl_on_undownload(struct peer *p); | |||||
void dl_on_piece_ann(struct peer *p, uint32_t index); | |||||
void dl_on_block(struct peer *p, struct block_request *req, | |||||
uint32_t index, uint32_t begin, uint32_t length, const char *data); | uint32_t index, uint32_t begin, uint32_t length, const char *data); | ||||
void cm_on_ok_piece(struct piece *pc); | |||||
void cm_on_bad_piece(struct piece *pc); | |||||
void dl_on_ok_piece(struct piece *pc); | |||||
void dl_on_bad_piece(struct piece *pc); | |||||
#endif | #endif |
@@ -37,7 +37,7 @@ choke_alg(struct torrent *tp) | |||||
struct peer *psort[tp->npeers]; | struct peer *psort[tp->npeers]; | ||||
i = 0; | i = 0; | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) | |||||
psort[i++] = p; | psort[i++] = p; | ||||
if (tp->have_npieces == tp->meta.npieces) | if (tp->have_npieces == tp->meta.npieces) | ||||
@@ -78,7 +78,7 @@ next_optimistic(struct torrent *tp, struct peer *np) | |||||
else if (tp->optimistic == NULL) | else if (tp->optimistic == NULL) | ||||
tp->optimistic = BTPDQ_FIRST(&tp->peers); | tp->optimistic = BTPDQ_FIRST(&tp->peers); | ||||
else { | else { | ||||
np = BTPDQ_NEXT(tp->optimistic, cm_entry); | |||||
np = BTPDQ_NEXT(tp->optimistic, p_entry); | |||||
if (np != NULL) | if (np != NULL) | ||||
tp->optimistic = np; | tp->optimistic = np; | ||||
else | else | ||||
@@ -5,7 +5,7 @@ | |||||
#include "tracker_req.h" | #include "tracker_req.h" | ||||
void | void | ||||
cm_by_second(struct torrent *tp) | |||||
dl_by_second(struct torrent *tp) | |||||
{ | { | ||||
if (btpd_seconds == tp->tracker_time) | if (btpd_seconds == tp->tracker_time) | ||||
tracker_req(tp, TR_EMPTY); | tracker_req(tp, TR_EMPTY); | ||||
@@ -19,7 +19,7 @@ cm_by_second(struct torrent *tp) | |||||
struct peer *p; | struct peer *p; | ||||
int ri = btpd_seconds % RATEHISTORY; | int ri = btpd_seconds % RATEHISTORY; | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) { | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) { | |||||
p->rate_to_me[ri] = 0; | p->rate_to_me[ri] = 0; | ||||
p->rate_from_me[ri] = 0; | p->rate_from_me[ri] = 0; | ||||
} | } | ||||
@@ -29,103 +29,103 @@ cm_by_second(struct torrent *tp) | |||||
* Called when a peer announces it's got a new piece. | * Called when a peer announces it's got a new piece. | ||||
* | * | ||||
* If the piece is missing or unfull we increase the peer's | * If the piece is missing or unfull we increase the peer's | ||||
* wanted level and if possible call cm_on_download. | |||||
* wanted level and if possible call dl_on_download. | |||||
*/ | */ | ||||
void | void | ||||
cm_on_piece_ann(struct peer *p, uint32_t index) | |||||
dl_on_piece_ann(struct peer *p, uint32_t index) | |||||
{ | { | ||||
struct torrent *tp = p->tp; | struct torrent *tp = p->tp; | ||||
tp->piece_count[index]++; | tp->piece_count[index]++; | ||||
if (has_bit(tp->piece_field, index)) | if (has_bit(tp->piece_field, index)) | ||||
return; | return; | ||||
struct piece *pc = cm_find_piece(tp, index); | |||||
struct piece *pc = dl_find_piece(tp, index); | |||||
if (tp->endgame) { | if (tp->endgame) { | ||||
assert(pc != NULL); | assert(pc != NULL); | ||||
peer_want(p, index); | peer_want(p, index); | ||||
if (!peer_chokes(p) && !peer_laden(p)) | if (!peer_chokes(p) && !peer_laden(p)) | ||||
cm_assign_requests_eg(p); | |||||
dl_assign_requests_eg(p); | |||||
} else if (pc == NULL) { | } else if (pc == NULL) { | ||||
peer_want(p, index); | peer_want(p, index); | ||||
if (!peer_chokes(p) && !peer_laden(p)) { | if (!peer_chokes(p) && !peer_laden(p)) { | ||||
pc = cm_new_piece(tp, index); | |||||
pc = dl_new_piece(tp, index); | |||||
if (pc != NULL) | if (pc != NULL) | ||||
cm_piece_assign_requests(pc, p); | |||||
dl_piece_assign_requests(pc, p); | |||||
} | } | ||||
} else if (!piece_full(pc)) { | } else if (!piece_full(pc)) { | ||||
peer_want(p, index); | peer_want(p, index); | ||||
if (!peer_chokes(p) && !peer_laden(p)) | if (!peer_chokes(p) && !peer_laden(p)) | ||||
cm_piece_assign_requests(pc, p); | |||||
dl_piece_assign_requests(pc, p); | |||||
} | } | ||||
} | } | ||||
void | void | ||||
cm_on_download(struct peer *p) | |||||
dl_on_download(struct peer *p) | |||||
{ | { | ||||
assert(peer_wanted(p)); | assert(peer_wanted(p)); | ||||
struct torrent *tp = p->tp; | struct torrent *tp = p->tp; | ||||
if (tp->endgame) { | if (tp->endgame) { | ||||
cm_assign_requests_eg(p); | |||||
dl_assign_requests_eg(p); | |||||
} else { | } else { | ||||
unsigned count = cm_assign_requests(p); | |||||
unsigned count = dl_assign_requests(p); | |||||
if (count == 0 && !p->tp->endgame) // We may have entered end game. | if (count == 0 && !p->tp->endgame) // We may have entered end game. | ||||
assert(!peer_wanted(p) || peer_laden(p)); | assert(!peer_wanted(p) || peer_laden(p)); | ||||
} | } | ||||
} | } | ||||
void | void | ||||
cm_on_unchoke(struct peer *p) | |||||
dl_on_unchoke(struct peer *p) | |||||
{ | { | ||||
if (peer_wanted(p)) | if (peer_wanted(p)) | ||||
cm_on_download(p); | |||||
dl_on_download(p); | |||||
} | } | ||||
void | void | ||||
cm_on_undownload(struct peer *p) | |||||
dl_on_undownload(struct peer *p) | |||||
{ | { | ||||
if (!p->tp->endgame) | if (!p->tp->endgame) | ||||
cm_unassign_requests(p); | |||||
dl_unassign_requests(p); | |||||
else | else | ||||
cm_unassign_requests_eg(p); | |||||
dl_unassign_requests_eg(p); | |||||
} | } | ||||
void | void | ||||
cm_on_choke(struct peer *p) | |||||
dl_on_choke(struct peer *p) | |||||
{ | { | ||||
if (p->nreqs_out > 0) | if (p->nreqs_out > 0) | ||||
cm_on_undownload(p); | |||||
dl_on_undownload(p); | |||||
} | } | ||||
void | void | ||||
cm_on_upload(struct peer *p) | |||||
dl_on_upload(struct peer *p) | |||||
{ | { | ||||
choke_alg(p->tp); | choke_alg(p->tp); | ||||
} | } | ||||
void | void | ||||
cm_on_interest(struct peer *p) | |||||
dl_on_interest(struct peer *p) | |||||
{ | { | ||||
if ((p->flags & PF_I_CHOKE) == 0) | if ((p->flags & PF_I_CHOKE) == 0) | ||||
cm_on_upload(p); | |||||
dl_on_upload(p); | |||||
} | } | ||||
void | void | ||||
cm_on_unupload(struct peer *p) | |||||
dl_on_unupload(struct peer *p) | |||||
{ | { | ||||
choke_alg(p->tp); | choke_alg(p->tp); | ||||
} | } | ||||
void | void | ||||
cm_on_uninterest(struct peer *p) | |||||
dl_on_uninterest(struct peer *p) | |||||
{ | { | ||||
if ((p->flags & PF_I_CHOKE) == 0) | if ((p->flags & PF_I_CHOKE) == 0) | ||||
cm_on_unupload(p); | |||||
dl_on_unupload(p); | |||||
} | } | ||||
/** | /** | ||||
* Called when a piece has been tested positively. | * Called when a piece has been tested positively. | ||||
*/ | */ | ||||
void | void | ||||
cm_on_ok_piece(struct piece *pc) | |||||
dl_on_ok_piece(struct piece *pc) | |||||
{ | { | ||||
struct peer *p; | struct peer *p; | ||||
struct torrent *tp = pc->tp; | struct torrent *tp = pc->tp; | ||||
@@ -137,11 +137,11 @@ cm_on_ok_piece(struct piece *pc) | |||||
msync(tp->imem, tp->isiz, MS_ASYNC); | msync(tp->imem, tp->isiz, MS_ASYNC); | ||||
struct net_buf *have = nb_create_have(pc->index); | struct net_buf *have = nb_create_have(pc->index); | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) | |||||
peer_send(p, have); | peer_send(p, have); | ||||
if (tp->endgame) | if (tp->endgame) | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) | |||||
if (peer_has(p, pc->index)) | if (peer_has(p, pc->index)) | ||||
peer_unwant(p, pc->index); | peer_unwant(p, pc->index); | ||||
@@ -151,7 +151,7 @@ cm_on_ok_piece(struct piece *pc) | |||||
if (torrent_has_all(tp)) { | if (torrent_has_all(tp)) { | ||||
btpd_log(BTPD_L_BTPD, "Finished: %s.\n", tp->relpath); | btpd_log(BTPD_L_BTPD, "Finished: %s.\n", tp->relpath); | ||||
tracker_req(tp, TR_COMPLETED); | tracker_req(tp, TR_COMPLETED); | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) | |||||
assert(p->nwant == 0); | assert(p->nwant == 0); | ||||
} | } | ||||
} | } | ||||
@@ -160,7 +160,7 @@ cm_on_ok_piece(struct piece *pc) | |||||
* Called when a piece has been tested negatively. | * Called when a piece has been tested negatively. | ||||
*/ | */ | ||||
void | void | ||||
cm_on_bad_piece(struct piece *pc) | |||||
dl_on_bad_piece(struct piece *pc) | |||||
{ | { | ||||
struct torrent *tp = pc->tp; | struct torrent *tp = pc->tp; | ||||
@@ -177,54 +177,54 @@ cm_on_bad_piece(struct piece *pc) | |||||
if (tp->endgame) { | if (tp->endgame) { | ||||
struct peer *p; | struct peer *p; | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) { | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) { | |||||
if (peer_has(p, pc->index) && peer_leech_ok(p) && !peer_laden(p)) | if (peer_has(p, pc->index) && peer_leech_ok(p) && !peer_laden(p)) | ||||
cm_assign_requests_eg(p); | |||||
dl_assign_requests_eg(p); | |||||
} | } | ||||
} else | } else | ||||
cm_on_piece_unfull(pc); // XXX: May get bad data again. | |||||
dl_on_piece_unfull(pc); // XXX: May get bad data again. | |||||
} | } | ||||
void | void | ||||
cm_on_new_peer(struct peer *p) | |||||
dl_on_new_peer(struct peer *p) | |||||
{ | { | ||||
struct torrent *tp = p->tp; | struct torrent *tp = p->tp; | ||||
tp->npeers++; | tp->npeers++; | ||||
p->flags |= PF_ATTACHED; | p->flags |= PF_ATTACHED; | ||||
BTPDQ_REMOVE(&net_unattached, p, cm_entry); | |||||
BTPDQ_REMOVE(&net_unattached, p, p_entry); | |||||
if (tp->npeers == 1) { | if (tp->npeers == 1) { | ||||
BTPDQ_INSERT_HEAD(&tp->peers, p, cm_entry); | |||||
BTPDQ_INSERT_HEAD(&tp->peers, p, p_entry); | |||||
next_optimistic(tp, p); | next_optimistic(tp, p); | ||||
} else { | } else { | ||||
if (random() > RAND_MAX / 3) | if (random() > RAND_MAX / 3) | ||||
BTPDQ_INSERT_AFTER(&tp->peers, tp->optimistic, p, cm_entry); | |||||
BTPDQ_INSERT_AFTER(&tp->peers, tp->optimistic, p, p_entry); | |||||
else | else | ||||
BTPDQ_INSERT_TAIL(&tp->peers, p, cm_entry); | |||||
BTPDQ_INSERT_TAIL(&tp->peers, p, p_entry); | |||||
} | } | ||||
} | } | ||||
void | void | ||||
cm_on_lost_peer(struct peer *p) | |||||
dl_on_lost_peer(struct peer *p) | |||||
{ | { | ||||
struct torrent *tp = p->tp; | struct torrent *tp = p->tp; | ||||
tp->npeers--; | tp->npeers--; | ||||
p->flags &= ~PF_ATTACHED; | p->flags &= ~PF_ATTACHED; | ||||
if (tp->npeers == 0) { | if (tp->npeers == 0) { | ||||
BTPDQ_REMOVE(&tp->peers, p, cm_entry); | |||||
BTPDQ_REMOVE(&tp->peers, p, p_entry); | |||||
tp->optimistic = NULL; | tp->optimistic = NULL; | ||||
tp->choke_time = tp->opt_time = 0; | tp->choke_time = tp->opt_time = 0; | ||||
} else if (tp->optimistic == p) { | } else if (tp->optimistic == p) { | ||||
struct peer *next = BTPDQ_NEXT(p, cm_entry); | |||||
BTPDQ_REMOVE(&tp->peers, p, cm_entry); | |||||
struct peer *next = BTPDQ_NEXT(p, p_entry); | |||||
BTPDQ_REMOVE(&tp->peers, p, p_entry); | |||||
next_optimistic(tp, next); | next_optimistic(tp, next); | ||||
} else if ((p->flags & (PF_P_WANT|PF_I_CHOKE)) == PF_P_WANT) { | } else if ((p->flags & (PF_P_WANT|PF_I_CHOKE)) == PF_P_WANT) { | ||||
BTPDQ_REMOVE(&tp->peers, p, cm_entry); | |||||
cm_on_unupload(p); | |||||
BTPDQ_REMOVE(&tp->peers, p, p_entry); | |||||
dl_on_unupload(p); | |||||
} else { | } else { | ||||
BTPDQ_REMOVE(&tp->peers, p, cm_entry); | |||||
BTPDQ_REMOVE(&tp->peers, p, p_entry); | |||||
} | } | ||||
for (uint32_t i = 0; i < tp->meta.npieces; i++) | for (uint32_t i = 0; i < tp->meta.npieces; i++) | ||||
@@ -232,20 +232,20 @@ cm_on_lost_peer(struct peer *p) | |||||
tp->piece_count[i]--; | tp->piece_count[i]--; | ||||
if (p->nreqs_out > 0) | if (p->nreqs_out > 0) | ||||
cm_on_undownload(p); | |||||
dl_on_undownload(p); | |||||
#if 0 | #if 0 | ||||
struct piece *pc = BTPDQ_FIRST(&tp->getlst); | struct piece *pc = BTPDQ_FIRST(&tp->getlst); | ||||
while (pc != NULL) { | while (pc != NULL) { | ||||
struct piece *next = BTPDQ_NEXT(pc, entry); | struct piece *next = BTPDQ_NEXT(pc, entry); | ||||
if (peer_has(p, pc->index) && tp->piece_count[pc->index] == 0) | if (peer_has(p, pc->index) && tp->piece_count[pc->index] == 0) | ||||
cm_on_peerless_piece(pc); | |||||
dl_on_peerless_piece(pc); | |||||
pc = next; | pc = next; | ||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
void | void | ||||
cm_on_block(struct peer *p, struct block_request *req, | |||||
dl_on_block(struct peer *p, struct block_request *req, | |||||
uint32_t index, uint32_t begin, uint32_t length, const char *data) | uint32_t index, uint32_t begin, uint32_t length, const char *data) | ||||
{ | { | ||||
struct torrent *tp = p->tp; | struct torrent *tp = p->tp; | ||||
@@ -268,18 +268,18 @@ cm_on_block(struct peer *p, struct block_request *req, | |||||
pc->nreqs--; | pc->nreqs--; | ||||
} | } | ||||
nb_drop(cancel); | nb_drop(cancel); | ||||
cm_piece_reorder_eg(pc); | |||||
dl_piece_reorder_eg(pc); | |||||
req = BTPDQ_FIRST(&blk->reqs); | req = BTPDQ_FIRST(&blk->reqs); | ||||
while (req != NULL) { | while (req != NULL) { | ||||
struct block_request *next = BTPDQ_NEXT(req, blk_entry); | struct block_request *next = BTPDQ_NEXT(req, blk_entry); | ||||
if (peer_leech_ok(req->p) && !peer_laden(req->p)) | if (peer_leech_ok(req->p) && !peer_laden(req->p)) | ||||
cm_assign_requests_eg(req->p); | |||||
dl_assign_requests_eg(req->p); | |||||
free(req); | free(req); | ||||
req = next; | req = next; | ||||
} | } | ||||
BTPDQ_INIT(&blk->reqs); | BTPDQ_INIT(&blk->reqs); | ||||
if (pc->ngot == pc->nblocks) | if (pc->ngot == pc->nblocks) | ||||
cm_on_piece(pc); | |||||
dl_on_piece(pc); | |||||
} else { | } else { | ||||
BTPDQ_REMOVE(&blk->reqs, req, blk_entry); | BTPDQ_REMOVE(&blk->reqs, req, blk_entry); | ||||
free(req); | free(req); | ||||
@@ -288,8 +288,8 @@ cm_on_block(struct peer *p, struct block_request *req, | |||||
clear_bit(pc->down_field, begin / PIECE_BLOCKLEN); | clear_bit(pc->down_field, begin / PIECE_BLOCKLEN); | ||||
pc->nbusy--; | pc->nbusy--; | ||||
if (pc->ngot == pc->nblocks) | if (pc->ngot == pc->nblocks) | ||||
cm_on_piece(pc); | |||||
dl_on_piece(pc); | |||||
if (peer_leech_ok(p) && !peer_laden(p)) | if (peer_leech_ok(p) && !peer_laden(p)) | ||||
cm_assign_requests(p); | |||||
dl_assign_requests(p); | |||||
} | } | ||||
} | } |
@@ -105,7 +105,7 @@ piece_full(struct piece *pc) | |||||
} | } | ||||
static int | static int | ||||
cm_should_enter_endgame(struct torrent *tp) | |||||
dl_should_enter_endgame(struct torrent *tp) | |||||
{ | { | ||||
int should; | int should; | ||||
if (tp->have_npieces + tp->npcs_busy == tp->meta.npieces) { | if (tp->have_npieces + tp->npcs_busy == tp->meta.npieces) { | ||||
@@ -123,7 +123,7 @@ cm_should_enter_endgame(struct torrent *tp) | |||||
} | } | ||||
static void | static void | ||||
cm_piece_insert_eg(struct piece *pc) | |||||
dl_piece_insert_eg(struct piece *pc) | |||||
{ | { | ||||
struct piece_tq *getlst = &pc->tp->getlst; | struct piece_tq *getlst = &pc->tp->getlst; | ||||
if (pc->nblocks == pc->ngot) | if (pc->nblocks == pc->ngot) | ||||
@@ -144,14 +144,14 @@ cm_piece_insert_eg(struct piece *pc) | |||||
} | } | ||||
void | void | ||||
cm_piece_reorder_eg(struct piece *pc) | |||||
dl_piece_reorder_eg(struct piece *pc) | |||||
{ | { | ||||
BTPDQ_REMOVE(&pc->tp->getlst, pc, entry); | BTPDQ_REMOVE(&pc->tp->getlst, pc, entry); | ||||
cm_piece_insert_eg(pc); | |||||
dl_piece_insert_eg(pc); | |||||
} | } | ||||
static void | static void | ||||
cm_enter_endgame(struct torrent *tp) | |||||
dl_enter_endgame(struct torrent *tp) | |||||
{ | { | ||||
struct peer *p; | struct peer *p; | ||||
struct piece *pc; | struct piece *pc; | ||||
@@ -172,21 +172,21 @@ cm_enter_endgame(struct torrent *tp) | |||||
BTPDQ_INIT(&tp->getlst); | BTPDQ_INIT(&tp->getlst); | ||||
while (pi > 0) { | while (pi > 0) { | ||||
pi--; | pi--; | ||||
cm_piece_insert_eg(pcs[pi]); | |||||
dl_piece_insert_eg(pcs[pi]); | |||||
} | } | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) { | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) { | |||||
assert(p->nwant == 0); | assert(p->nwant == 0); | ||||
BTPDQ_FOREACH(pc, &tp->getlst, entry) { | BTPDQ_FOREACH(pc, &tp->getlst, entry) { | ||||
if (peer_has(p, pc->index)) | if (peer_has(p, pc->index)) | ||||
peer_want(p, pc->index); | peer_want(p, pc->index); | ||||
} | } | ||||
if (p->nwant > 0 && peer_leech_ok(p) && !peer_laden(p)) | if (p->nwant > 0 && peer_leech_ok(p) && !peer_laden(p)) | ||||
cm_assign_requests_eg(p); | |||||
dl_assign_requests_eg(p); | |||||
} | } | ||||
} | } | ||||
struct piece * | struct piece * | ||||
cm_find_piece(struct torrent *tp, uint32_t index) | |||||
dl_find_piece(struct torrent *tp, uint32_t index) | |||||
{ | { | ||||
struct piece *pc; | struct piece *pc; | ||||
BTPDQ_FOREACH(pc, &tp->getlst, entry) | BTPDQ_FOREACH(pc, &tp->getlst, entry) | ||||
@@ -253,19 +253,19 @@ torrent_test_piece(struct piece *pc) | |||||
bts_close_ro(bts); | bts_close_ro(bts); | ||||
if (test_hash(tp, hash, pc->index) == 0) | if (test_hash(tp, hash, pc->index) == 0) | ||||
cm_on_ok_piece(pc); | |||||
dl_on_ok_piece(pc); | |||||
else | else | ||||
cm_on_bad_piece(pc); | |||||
dl_on_bad_piece(pc); | |||||
} | } | ||||
void | void | ||||
cm_on_piece(struct piece *pc) | |||||
dl_on_piece(struct piece *pc) | |||||
{ | { | ||||
torrent_test_piece(pc); | torrent_test_piece(pc); | ||||
} | } | ||||
static int | static int | ||||
cm_piece_startable(struct peer *p, uint32_t index) | |||||
dl_piece_startable(struct peer *p, uint32_t index) | |||||
{ | { | ||||
return peer_has(p, index) && !has_bit(p->tp->piece_field, index) | return peer_has(p, index) && !has_bit(p->tp->piece_field, index) | ||||
&& !has_bit(p->tp->busy_field, index); | && !has_bit(p->tp->busy_field, index); | ||||
@@ -279,14 +279,14 @@ cm_piece_startable(struct peer *p, uint32_t index) | |||||
* Return 0 or ENOENT, index in res. | * Return 0 or ENOENT, index in res. | ||||
*/ | */ | ||||
static int | static int | ||||
cm_choose_rarest(struct peer *p, uint32_t *res) | |||||
dl_choose_rarest(struct peer *p, uint32_t *res) | |||||
{ | { | ||||
uint32_t i; | uint32_t i; | ||||
struct torrent *tp = p->tp; | struct torrent *tp = p->tp; | ||||
assert(tp->endgame == 0); | assert(tp->endgame == 0); | ||||
for (i = 0; i < tp->meta.npieces && !cm_piece_startable(p, i); i++) | |||||
for (i = 0; i < tp->meta.npieces && !dl_piece_startable(p, i); i++) | |||||
; | ; | ||||
if (i == tp->meta.npieces) | if (i == tp->meta.npieces) | ||||
@@ -295,7 +295,7 @@ cm_choose_rarest(struct peer *p, uint32_t *res) | |||||
uint32_t min_i = i; | uint32_t min_i = i; | ||||
uint32_t min_c = 1; | uint32_t min_c = 1; | ||||
for(i++; i < tp->meta.npieces; i++) { | for(i++; i < tp->meta.npieces; i++) { | ||||
if (cm_piece_startable(p, i)) { | |||||
if (dl_piece_startable(p, i)) { | |||||
if (tp->piece_count[i] == tp->piece_count[min_i]) | if (tp->piece_count[i] == tp->piece_count[min_i]) | ||||
min_c++; | min_c++; | ||||
else if (tp->piece_count[i] < tp->piece_count[min_i]) { | else if (tp->piece_count[i] < tp->piece_count[min_i]) { | ||||
@@ -307,7 +307,7 @@ cm_choose_rarest(struct peer *p, uint32_t *res) | |||||
if (min_c > 1) { | if (min_c > 1) { | ||||
min_c = 1 + rint((double)random() * (min_c - 1) / RAND_MAX); | min_c = 1 + rint((double)random() * (min_c - 1) / RAND_MAX); | ||||
for (i = min_i; min_c > 0; i++) { | for (i = min_i; min_c > 0; i++) { | ||||
if (cm_piece_startable(p, i) | |||||
if (dl_piece_startable(p, i) | |||||
&& tp->piece_count[i] == tp->piece_count[min_i]) { | && tp->piece_count[i] == tp->piece_count[min_i]) { | ||||
min_c--; | min_c--; | ||||
min_i = i; | min_i = i; | ||||
@@ -319,21 +319,21 @@ cm_choose_rarest(struct peer *p, uint32_t *res) | |||||
} | } | ||||
/* | /* | ||||
* Called from either cm_piece_assign_requests or cm_new_piece, | |||||
* Called from either dl_piece_assign_requests or dl_new_piece, | |||||
* when a pice becomes full. The wanted level of the peers | * when a pice becomes full. The wanted level of the peers | ||||
* that has this piece will be decreased. This function is | * that has this piece will be decreased. This function is | ||||
* the only one that may trigger end game. | * the only one that may trigger end game. | ||||
*/ | */ | ||||
static void | static void | ||||
cm_on_piece_full(struct piece *pc) | |||||
dl_on_piece_full(struct piece *pc) | |||||
{ | { | ||||
struct peer *p; | struct peer *p; | ||||
BTPDQ_FOREACH(p, &pc->tp->peers, cm_entry) { | |||||
BTPDQ_FOREACH(p, &pc->tp->peers, p_entry) { | |||||
if (peer_has(p, pc->index)) | if (peer_has(p, pc->index)) | ||||
peer_unwant(p, pc->index); | peer_unwant(p, pc->index); | ||||
} | } | ||||
if (cm_should_enter_endgame(pc->tp)) | |||||
cm_enter_endgame(pc->tp); | |||||
if (dl_should_enter_endgame(pc->tp)) | |||||
dl_enter_endgame(pc->tp); | |||||
} | } | ||||
/* | /* | ||||
@@ -346,15 +346,15 @@ cm_on_piece_full(struct piece *pc) | |||||
* Return the piece or NULL. | * Return the piece or NULL. | ||||
*/ | */ | ||||
struct piece * | struct piece * | ||||
cm_new_piece(struct torrent *tp, uint32_t index) | |||||
dl_new_piece(struct torrent *tp, uint32_t index) | |||||
{ | { | ||||
btpd_log(BTPD_L_POL, "Started on piece %u.\n", index); | btpd_log(BTPD_L_POL, "Started on piece %u.\n", index); | ||||
struct piece *pc = piece_alloc(tp, index); | struct piece *pc = piece_alloc(tp, index); | ||||
if (pc->ngot == pc->nblocks) { | if (pc->ngot == pc->nblocks) { | ||||
cm_on_piece_full(pc); | |||||
cm_on_piece(pc); | |||||
if (cm_should_enter_endgame(tp)) | |||||
cm_enter_endgame(tp); | |||||
dl_on_piece_full(pc); | |||||
dl_on_piece(pc); | |||||
if (dl_should_enter_endgame(tp)) | |||||
dl_enter_endgame(tp); | |||||
return NULL; | return NULL; | ||||
} else | } else | ||||
return pc; | return pc; | ||||
@@ -368,19 +368,19 @@ cm_new_piece(struct torrent *tp, uint32_t index) | |||||
* try to assign requests for this piece. | * try to assign requests for this piece. | ||||
*/ | */ | ||||
void | void | ||||
cm_on_piece_unfull(struct piece *pc) | |||||
dl_on_piece_unfull(struct piece *pc) | |||||
{ | { | ||||
struct torrent *tp = pc->tp; | struct torrent *tp = pc->tp; | ||||
struct peer *p; | struct peer *p; | ||||
assert(!piece_full(pc) && tp->endgame == 0); | assert(!piece_full(pc) && tp->endgame == 0); | ||||
BTPDQ_FOREACH(p, &tp->peers, cm_entry) | |||||
BTPDQ_FOREACH(p, &tp->peers, p_entry) | |||||
if (peer_has(p, pc->index)) | if (peer_has(p, pc->index)) | ||||
peer_want(p, pc->index); | peer_want(p, pc->index); | ||||
p = BTPDQ_FIRST(&tp->peers); | p = BTPDQ_FIRST(&tp->peers); | ||||
while (p != NULL && !piece_full(pc)) { | while (p != NULL && !piece_full(pc)) { | ||||
if (peer_leech_ok(p) && !peer_laden(p)) | if (peer_leech_ok(p) && !peer_laden(p)) | ||||
cm_piece_assign_requests(pc, p); // Cannot provoke end game here. | |||||
p = BTPDQ_NEXT(p, cm_entry); | |||||
dl_piece_assign_requests(pc, p); // Cannot provoke end game here. | |||||
p = BTPDQ_NEXT(p, p_entry); | |||||
} | } | ||||
} | } | ||||
@@ -390,12 +390,12 @@ cm_on_piece_unfull(struct piece *pc) | |||||
/* | /* | ||||
* Request as many blocks as possible on this piece from | * Request as many blocks as possible on this piece from | ||||
* the peer. If the piece becomes full we call cm_on_piece_full. | |||||
* the peer. If the piece becomes full we call dl_on_piece_full. | |||||
* | * | ||||
* Return the number of requests sent. | * Return the number of requests sent. | ||||
*/ | */ | ||||
unsigned | unsigned | ||||
cm_piece_assign_requests(struct piece *pc, struct peer *p) | |||||
dl_piece_assign_requests(struct piece *pc, struct peer *p) | |||||
{ | { | ||||
assert(!piece_full(pc) && !peer_laden(p)); | assert(!piece_full(pc) && !peer_laden(p)); | ||||
unsigned count = 0; | unsigned count = 0; | ||||
@@ -420,7 +420,7 @@ cm_piece_assign_requests(struct piece *pc, struct peer *p) | |||||
} while (!piece_full(pc) && !peer_laden(p)); | } while (!piece_full(pc) && !peer_laden(p)); | ||||
if (piece_full(pc)) | if (piece_full(pc)) | ||||
cm_on_piece_full(pc); | |||||
dl_on_piece_full(pc); | |||||
return count; | return count; | ||||
} | } | ||||
@@ -429,7 +429,7 @@ cm_piece_assign_requests(struct piece *pc, struct peer *p) | |||||
* Request as many blocks as possible from the peer. Puts | * Request as many blocks as possible from the peer. Puts | ||||
* requests on already active pieces before starting on new | * requests on already active pieces before starting on new | ||||
* ones. Care must be taken since end game mode may be triggered | * ones. Care must be taken since end game mode may be triggered | ||||
* by the calls to cm_piece_assign_requests. | |||||
* by the calls to dl_piece_assign_requests. | |||||
* | * | ||||
* Returns number of requests sent. | * Returns number of requests sent. | ||||
* | * | ||||
@@ -437,7 +437,7 @@ cm_piece_assign_requests(struct piece *pc, struct peer *p) | |||||
* already started piece to put requests on. | * already started piece to put requests on. | ||||
*/ | */ | ||||
unsigned | unsigned | ||||
cm_assign_requests(struct peer *p) | |||||
dl_assign_requests(struct peer *p) | |||||
{ | { | ||||
assert(!p->tp->endgame && !peer_laden(p)); | assert(!p->tp->endgame && !peer_laden(p)); | ||||
struct piece *pc; | struct piece *pc; | ||||
@@ -446,7 +446,7 @@ cm_assign_requests(struct peer *p) | |||||
BTPDQ_FOREACH(pc, &tp->getlst, entry) { | BTPDQ_FOREACH(pc, &tp->getlst, entry) { | ||||
if (piece_full(pc) || !peer_has(p, pc->index)) | if (piece_full(pc) || !peer_has(p, pc->index)) | ||||
continue; | continue; | ||||
count += cm_piece_assign_requests(pc, p); | |||||
count += dl_piece_assign_requests(pc, p); | |||||
if (tp->endgame) | if (tp->endgame) | ||||
break; | break; | ||||
if (!piece_full(pc)) | if (!piece_full(pc)) | ||||
@@ -456,10 +456,10 @@ cm_assign_requests(struct peer *p) | |||||
} | } | ||||
while (!peer_laden(p) && !tp->endgame) { | while (!peer_laden(p) && !tp->endgame) { | ||||
uint32_t index; | uint32_t index; | ||||
if (cm_choose_rarest(p, &index) == 0) { | |||||
pc = cm_new_piece(tp, index); | |||||
if (dl_choose_rarest(p, &index) == 0) { | |||||
pc = dl_new_piece(tp, index); | |||||
if (pc != NULL) | if (pc != NULL) | ||||
count += cm_piece_assign_requests(pc, p); | |||||
count += dl_piece_assign_requests(pc, p); | |||||
} else | } else | ||||
break; | break; | ||||
} | } | ||||
@@ -467,7 +467,7 @@ cm_assign_requests(struct peer *p) | |||||
} | } | ||||
void | void | ||||
cm_unassign_requests(struct peer *p) | |||||
dl_unassign_requests(struct peer *p) | |||||
{ | { | ||||
while (p->nreqs_out > 0) { | while (p->nreqs_out > 0) { | ||||
struct block_request *req = BTPDQ_FIRST(&p->my_reqs); | struct block_request *req = BTPDQ_FIRST(&p->my_reqs); | ||||
@@ -495,13 +495,13 @@ cm_unassign_requests(struct peer *p) | |||||
} | } | ||||
if (was_full && !piece_full(pc)) | if (was_full && !piece_full(pc)) | ||||
cm_on_piece_unfull(pc); | |||||
dl_on_piece_unfull(pc); | |||||
} | } | ||||
assert(BTPDQ_EMPTY(&p->my_reqs)); | assert(BTPDQ_EMPTY(&p->my_reqs)); | ||||
} | } | ||||
static void | static void | ||||
cm_piece_assign_requests_eg(struct piece *pc, struct peer *p) | |||||
dl_piece_assign_requests_eg(struct piece *pc, struct peer *p) | |||||
{ | { | ||||
unsigned first_block = pc->next_block; | unsigned first_block = pc->next_block; | ||||
do { | do { | ||||
@@ -521,7 +521,7 @@ cm_piece_assign_requests_eg(struct piece *pc, struct peer *p) | |||||
} | } | ||||
void | void | ||||
cm_assign_requests_eg(struct peer *p) | |||||
dl_assign_requests_eg(struct peer *p) | |||||
{ | { | ||||
assert(!peer_laden(p)); | assert(!peer_laden(p)); | ||||
struct torrent *tp = p->tp; | struct torrent *tp = p->tp; | ||||
@@ -532,7 +532,7 @@ cm_assign_requests_eg(struct peer *p) | |||||
while (!peer_laden(p) && pc != NULL) { | while (!peer_laden(p) && pc != NULL) { | ||||
struct piece *next = BTPDQ_NEXT(pc, entry); | struct piece *next = BTPDQ_NEXT(pc, entry); | ||||
if (peer_has(p, pc->index) && pc->nblocks != pc->ngot) { | if (peer_has(p, pc->index) && pc->nblocks != pc->ngot) { | ||||
cm_piece_assign_requests_eg(pc, p); | |||||
dl_piece_assign_requests_eg(pc, p); | |||||
BTPDQ_REMOVE(&tp->getlst, pc, entry); | BTPDQ_REMOVE(&tp->getlst, pc, entry); | ||||
BTPDQ_INSERT_HEAD(&tmp, pc, entry); | BTPDQ_INSERT_HEAD(&tmp, pc, entry); | ||||
} | } | ||||
@@ -542,13 +542,13 @@ cm_assign_requests_eg(struct peer *p) | |||||
pc = BTPDQ_FIRST(&tmp); | pc = BTPDQ_FIRST(&tmp); | ||||
while (pc != NULL) { | while (pc != NULL) { | ||||
struct piece *next = BTPDQ_NEXT(pc, entry); | struct piece *next = BTPDQ_NEXT(pc, entry); | ||||
cm_piece_insert_eg(pc); | |||||
dl_piece_insert_eg(pc); | |||||
pc = next; | pc = next; | ||||
} | } | ||||
} | } | ||||
void | void | ||||
cm_unassign_requests_eg(struct peer *p) | |||||
dl_unassign_requests_eg(struct peer *p) | |||||
{ | { | ||||
struct block_request *req; | struct block_request *req; | ||||
struct piece *pc; | struct piece *pc; | ||||
@@ -580,7 +580,7 @@ cm_unassign_requests_eg(struct peer *p) | |||||
pc = BTPDQ_FIRST(&tmp); | pc = BTPDQ_FIRST(&tmp); | ||||
while (pc != NULL) { | while (pc != NULL) { | ||||
struct piece *next = BTPDQ_NEXT(pc, entry); | struct piece *next = BTPDQ_NEXT(pc, entry); | ||||
cm_piece_insert_eg(pc); | |||||
dl_piece_insert_eg(pc); | |||||
pc = next; | pc = next; | ||||
} | } | ||||
} | } |
@@ -158,16 +158,16 @@ torrent_unload(struct torrent *tp) | |||||
peer = BTPDQ_FIRST(&tp->peers); | peer = BTPDQ_FIRST(&tp->peers); | ||||
while (peer != NULL) { | while (peer != NULL) { | ||||
struct peer *next = BTPDQ_NEXT(peer, cm_entry); | |||||
BTPDQ_REMOVE(&tp->peers, peer, cm_entry); | |||||
BTPDQ_INSERT_TAIL(&net_unattached, peer, cm_entry); | |||||
struct peer *next = BTPDQ_NEXT(peer, p_entry); | |||||
BTPDQ_REMOVE(&tp->peers, peer, p_entry); | |||||
BTPDQ_INSERT_TAIL(&net_unattached, peer, p_entry); | |||||
peer->flags &= ~PF_ATTACHED; | peer->flags &= ~PF_ATTACHED; | ||||
peer = next; | peer = next; | ||||
} | } | ||||
peer = BTPDQ_FIRST(&net_unattached); | peer = BTPDQ_FIRST(&net_unattached); | ||||
while (peer != NULL) { | while (peer != NULL) { | ||||
struct peer *next = BTPDQ_NEXT(peer, cm_entry); | |||||
struct peer *next = BTPDQ_NEXT(peer, p_entry); | |||||
if (peer->tp == tp) | if (peer->tp == tp) | ||||
peer_kill(peer); | peer_kill(peer); | ||||
peer = next; | peer = next; | ||||
@@ -237,7 +237,7 @@ torrent_has_peer(struct torrent *tp, const uint8_t *id) | |||||
has = 1; | has = 1; | ||||
break; | break; | ||||
} | } | ||||
p = BTPDQ_NEXT(p, cm_entry); | |||||
p = BTPDQ_NEXT(p, p_entry); | |||||
} | } | ||||
return has; | return has; | ||||
} | } | ||||