From 3cb7595b8579448f4dda4b7cb6061ae8a5bd4c7a Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sun, 3 Feb 2013 22:40:00 +0000 Subject: [PATCH] (libT) move the tr_peer declaration from peer-mgr.h to peer-common.h --- libtransmission/peer-common.h | 69 +++++++++++++++++++++++++++++++++-- libtransmission/peer-mgr.h | 54 +-------------------------- libtransmission/peer-msgs.c | 8 ++-- 3 files changed, 72 insertions(+), 59 deletions(-) diff --git a/libtransmission/peer-common.h b/libtransmission/peer-common.h index 93c01c942..ffa6e0333 100644 --- a/libtransmission/peer-common.h +++ b/libtransmission/peer-common.h @@ -27,8 +27,9 @@ **/ #include "transmission.h" - -struct tr_bitfield; +#include "bitfield.h" +#include "history.h" +#include "quark.h" enum { @@ -80,7 +81,69 @@ tr_peer_event; extern const tr_peer_event TR_PEER_EVENT_INIT; -struct tr_peer; +/** + * State information about a connected peer. + * + * @see struct peer_atom + * @see tr_peermsgs + */ +typedef struct tr_peer +{ + /* whether or not we should free this peer soon. + NOTE: private to peer-mgr.c */ + bool doPurge; + + /* Whether or not we've choked this peer. + Only applies to BitTorrent peers */ + bool peerIsChoked; + + /* whether or not the peer has indicated it will download from us. + Only applies to BitTorrent peers */ + bool peerIsInterested; + + /* whether or the peer is choking us. + Only applies to BitTorrent peers */ + bool clientIsChoked; + + /* whether or not we've indicated to the peer that we would download from them if unchoked. + Only applies to BitTorrent peers */ + bool clientIsInterested; + + /* number of bad pieces they've contributed to */ + uint8_t strikes; + + uint8_t encryption_preference; + + /* how many requests the peer has made that we haven't responded to yet */ + int pendingReqsToClient; + + /* how many requests we've made and are currently awaiting a response for */ + int pendingReqsToPeer; + + struct tr_peerIo * io; + struct peer_atom * atom; + + /** how complete the peer's copy of the torrent is. [0.0...1.0] */ + float progress; + + struct tr_bitfield blame; + struct tr_bitfield have; + + /* the client name. + For BitTorrent peers, this is the app name derived from the `v' string in LTEP's handshake dictionary */ + tr_quark client; + + time_t chokeChangedAt; + + tr_recentHistory blocksSentToClient; + tr_recentHistory blocksSentToPeer; + + tr_recentHistory cancelsSentToClient; + tr_recentHistory cancelsSentToPeer; + + struct tr_peermsgs * msgs; +} +tr_peer; typedef void tr_peer_callback (struct tr_peer * peer, const tr_peer_event * event, diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h index 7a055da24..12a3039e2 100644 --- a/libtransmission/peer-mgr.h +++ b/libtransmission/peer-mgr.h @@ -23,10 +23,8 @@ #include /* struct in_addr */ #endif -#include "bitfield.h" -#include "history.h" #include "net.h" /* tr_address */ -#include "peer-common.h" /* struct peer_request */ +#include "peer-common.h" #include "quark.h" /** @@ -81,56 +79,6 @@ enum /* opaque forward declaration */ struct peer_atom; -/** - * State information about a connected peer. - * - * @see struct peer_atom - * @see tr_peermsgs - */ -typedef struct tr_peer -{ - bool peerIsChoked; - bool peerIsInterested; - bool clientIsChoked; - bool clientIsInterested; - bool doPurge; - - /* number of bad pieces they've contributed to */ - uint8_t strikes; - - uint8_t encryption_preference; - tr_port dht_port; - - /* how many requests the peer has made that we haven't responded to yet */ - int pendingReqsToClient; - - /* how many requests we've made and are currently awaiting a response for */ - int pendingReqsToPeer; - - struct tr_peerIo * io; - struct peer_atom * atom; - - struct tr_bitfield blame; - struct tr_bitfield have; - - /** how complete the peer's copy of the torrent is. [0.0...1.0] */ - float progress; - - /* the client name from the `v' string in LTEP's handshake dictionary */ - tr_quark client; - - time_t chokeChangedAt; - - tr_recentHistory blocksSentToClient; - tr_recentHistory blocksSentToPeer; - - tr_recentHistory cancelsSentToClient; - tr_recentHistory cancelsSentToPeer; - - struct tr_peermsgs * msgs; -} -tr_peer; - void tr_peerConstruct (struct tr_peer * peer); void tr_peerDestruct (tr_torrent * tor, struct tr_peer * peer); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 0ed529dfe..7e61defb1 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -177,6 +177,8 @@ struct tr_peermsgs uint16_t pexCount; uint16_t pexCount6; + tr_port dht_port; + size_t metadata_size_hint; #if 0 size_t fastsetSize; @@ -1466,11 +1468,11 @@ readBtMessage (tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen) case BT_PORT: dbgmsg (msgs, "Got a BT_PORT"); - tr_peerIoReadUint16 (msgs->peer->io, inbuf, &msgs->peer->dht_port); - if (msgs->peer->dht_port > 0) + tr_peerIoReadUint16 (msgs->peer->io, inbuf, &msgs->dht_port); + if (msgs->dht_port > 0) tr_dhtAddNode (getSession (msgs), tr_peerAddress (msgs->peer), - msgs->peer->dht_port, 0); + msgs->dht_port, 0); break; case BT_FEXT_SUGGEST: