瀏覽代碼

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 年之前
父節點
當前提交
4b9aa9c042
共有 5 個檔案被更改,包括 18 行新增1 行删除
  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 查看文件

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

BTPDQ_INIT(&btpd.unattached);

btpd.port = 6881;

btpd.obwlim = 0;


+ 2
- 0
btpd/btpd.h 查看文件

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

struct peer_tq unattached;

int port;
int peer4_sd;
int ipc_sd;


+ 3
- 0
btpd/peer.c 查看文件

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

if (p->flags & PF_ATTACHED)
cm_on_lost_peer(p);
else
BTPDQ_REMOVE(&btpd.unattached, p, cm_entry);
if (p->flags & PF_ON_READQ)
BTPDQ_REMOVE(&btpd.readq, p, rq_entry);
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_add(&p->in_ev, NULL);

BTPDQ_INSERT_TAIL(&btpd.unattached, p, cm_entry);
btpd.npeers++;
return p;
}


+ 1
- 0
btpd/policy.c 查看文件

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

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

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


+ 10
- 1
btpd/torrent.c 查看文件

@@ -156,11 +156,20 @@ torrent_unload(struct torrent *tp)
peer = BTPDQ_FIRST(&tp->peers);
while (peer != NULL) {
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_kill(peer);
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);
while (piece != NULL) {
struct piece *next = BTPDQ_NEXT(piece, entry);


Loading…
取消
儲存