Browse Source

Keep peers not attached to a torrent on a list,

making it possible to remove peers in mid hand-
shake when removing a torrent.
master
Richard Nyberg 19 years ago
parent
commit
4b9aa9c042
5 changed files with 18 additions and 1 deletions
  1. +2
    -0
      btpd/btpd.c
  2. +2
    -0
      btpd/btpd.h
  3. +3
    -0
      btpd/peer.c
  4. +1
    -0
      btpd/policy.c
  5. +10
    -1
      btpd/torrent.c

+ 2
- 0
btpd/btpd.c View File

@@ -120,6 +120,8 @@ btpd_init(void)
BTPDQ_INIT(&btpd.readq); BTPDQ_INIT(&btpd.readq);
BTPDQ_INIT(&btpd.writeq); BTPDQ_INIT(&btpd.writeq);


BTPDQ_INIT(&btpd.unattached);

btpd.port = 6881; btpd.port = 6881;


btpd.obwlim = 0; btpd.obwlim = 0;


+ 2
- 0
btpd/btpd.h View File

@@ -50,6 +50,8 @@ struct btpd {
struct peer_tq readq; struct peer_tq readq;
struct peer_tq writeq; struct peer_tq writeq;


struct peer_tq unattached;

int port; int port;
int peer4_sd; int peer4_sd;
int ipc_sd; int ipc_sd;


+ 3
- 0
btpd/peer.c View File

@@ -25,6 +25,8 @@ peer_kill(struct peer *p)


if (p->flags & PF_ATTACHED) if (p->flags & PF_ATTACHED)
cm_on_lost_peer(p); cm_on_lost_peer(p);
else
BTPDQ_REMOVE(&btpd.unattached, p, cm_entry);
if (p->flags & PF_ON_READQ) if (p->flags & PF_ON_READQ)
BTPDQ_REMOVE(&btpd.readq, p, rq_entry); BTPDQ_REMOVE(&btpd.readq, p, rq_entry);
if (p->flags & PF_ON_WRITEQ) if (p->flags & PF_ON_WRITEQ)
@@ -151,6 +153,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(&btpd.unattached, p, cm_entry);
btpd.npeers++; btpd.npeers++;
return p; return p;
} }


+ 1
- 0
btpd/policy.c View File

@@ -318,6 +318,7 @@ cm_on_new_peer(struct peer *peer)


tp->npeers++; tp->npeers++;
peer->flags |= PF_ATTACHED; peer->flags |= PF_ATTACHED;
BTPDQ_REMOVE(&btpd.unattached, peer, cm_entry);


if (tp->npeers == 1) { if (tp->npeers == 1) {
BTPDQ_INSERT_HEAD(&tp->peers, peer, cm_entry); BTPDQ_INSERT_HEAD(&tp->peers, peer, cm_entry);


+ 10
- 1
btpd/torrent.c View File

@@ -156,11 +156,20 @@ 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); struct peer *next = BTPDQ_NEXT(peer, cm_entry);
BTPDQ_REMOVE(&tp->peers, peer, cm_entry);
BTPDQ_INSERT_TAIL(&btpd.unattached, peer, cm_entry);
peer->flags &= ~PF_ATTACHED; peer->flags &= ~PF_ATTACHED;
peer_kill(peer);
peer = next; peer = next;
} }


peer = BTPDQ_FIRST(&btpd.unattached);
while (peer != NULL) {
struct peer *next = BTPDQ_NEXT(peer, cm_entry);
if (peer->tp == tp)
peer_kill(peer);
peer = next;
}

piece = BTPDQ_FIRST(&tp->getlst); piece = BTPDQ_FIRST(&tp->getlst);
while (piece != NULL) { while (piece != NULL) {
struct piece *next = BTPDQ_NEXT(piece, entry); struct piece *next = BTPDQ_NEXT(piece, entry);


Loading…
Cancel
Save