source: trunk/libtransmission/peer-mgr.h @ 9890

Last change on this file since 9890 was 9890, checked in by charles, 13 years ago

(trunk) one of the less-interesting commits in a while: remove trailing spaces from lines

  • Property svn:keywords set to Date Rev Author Id
File size: 6.5 KB
Line 
1/*
2 * This file Copyright (C) 2007-2010 Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: peer-mgr.h 9890 2010-01-05 23:47:50Z charles $
11 */
12
13#ifndef __TRANSMISSION__
14#error only libtransmission should #include this header.
15#endif
16
17#ifndef TR_PEER_MGR_H
18#define TR_PEER_MGR_H
19
20#include <inttypes.h> /* uint16_t */
21
22#ifdef WIN32
23 #include <winsock2.h> /* struct in_addr */
24#endif
25
26#include "bitfield.h"
27#include "bitset.h"
28#include "net.h"
29#include "peer-common.h" /* struct peer_request */
30#include "publish.h" /* tr_publisher_tag */
31#include "utils.h"
32
33/**
34 * @addtogroup peers Peers
35 * @{
36 */
37
38struct tr_peer_stat;
39struct tr_torrent;
40typedef struct tr_peerMgr tr_peerMgr;
41
42enum
43{
44    /* corresponds to ut_pex's added.f flags */
45    ADDED_F_ENCRYPTION_FLAG = 1,
46
47    /* corresponds to ut_pex's added.f flags */
48    ADDED_F_SEED_FLAG = 2,
49};
50
51typedef struct tr_pex
52{
53    tr_address addr;
54    tr_port    port; /* this field is in network byte order */
55    uint8_t    flags;
56}
57tr_pex;
58
59
60struct tr_bandwidth;
61struct tr_peerIo;
62struct tr_peermsgs;
63
64enum
65{
66    ENCRYPTION_PREFERENCE_UNKNOWN,
67    ENCRYPTION_PREFERENCE_YES,
68    ENCRYPTION_PREFERENCE_NO
69};
70
71/* opaque forward declaration */
72struct peer_atom;
73
74/**
75 * State information about a connected peer.
76 *
77 * @see struct peer_atom
78 * @see tr_peermsgs
79 */
80typedef struct tr_peer
81{
82    tr_bool                  peerIsChoked;
83    tr_bool                  peerIsInterested;
84    tr_bool                  clientIsChoked;
85    tr_bool                  clientIsInterested;
86    tr_bool                  doPurge;
87
88    /* number of bad pieces they've contributed to */
89    uint8_t                  strikes;
90
91    uint8_t                  encryption_preference;
92    tr_port                  dht_port;
93
94    /* how many requests the peer has made that we haven't responded to yet */
95    int                      pendingReqsToClient;
96
97    /* how many requests we've made and are currently awaiting a response for */
98    int                      pendingReqsToPeer;
99
100    struct tr_peerIo       * io;
101    struct peer_atom       * atom;
102
103    struct tr_bitfield     * blame;
104    struct tr_bitset         have;
105
106    /** how complete the peer's copy of the torrent is. [0.0...1.0] */
107    float                    progress;
108
109    /* the client name from the `v' string in LTEP's handshake dictionary */
110    char                   * client;
111
112    time_t                   chokeChangedAt;
113
114    struct tr_peermsgs     * msgs;
115    tr_publisher_tag         msgsTag;
116}
117tr_peer;
118
119const tr_address * tr_peerAddress( const tr_peer * );
120
121int tr_pexCompare( const void * a, const void * b );
122
123tr_peerMgr* tr_peerMgrNew( tr_session * );
124
125void tr_peerMgrFree( tr_peerMgr * manager );
126
127tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor,
128                              const tr_address * addr );
129
130void tr_peerMgrGetNextRequests( tr_torrent          * torrent,
131                                tr_peer             * peer,
132                                int                   numwant,
133                                tr_block_index_t    * setme,
134                                int                 * numgot );
135
136tr_bool tr_peerMgrDidPeerRequest( const tr_torrent  * torrent,
137                                  const tr_peer     * peer,
138                                  tr_block_index_t    block );
139
140void tr_peerMgrRebuildRequests( tr_torrent * torrent );
141
142void tr_peerMgrAddIncoming( tr_peerMgr  * manager,
143                            tr_address  * addr,
144                            tr_port       port,
145                            int           socket );
146
147tr_pex * tr_peerMgrCompactToPex( const void    * compact,
148                                 size_t          compactLen,
149                                 const uint8_t * added_f,
150                                 size_t          added_f_len,
151                                 size_t        * setme_pex_count );
152
153tr_pex * tr_peerMgrCompact6ToPex( const void    * compact,
154                                  size_t          compactLen,
155                                  const uint8_t * added_f,
156                                  size_t          added_f_len,
157                                  size_t        * pexCount );
158
159tr_pex * tr_peerMgrArrayToPex( const void * array,
160                               size_t       arrayLen,
161                               size_t      * setme_pex_count );
162
163void tr_peerMgrAddPex( tr_torrent     * tor,
164                       uint8_t          from,
165                       const tr_pex   * pex );
166
167void tr_peerMgrSetBlame( tr_torrent        * tor,
168                         tr_piece_index_t    pieceIndex,
169                         int                 success );
170
171enum
172{
173    TR_PEERS_CONNECTED,
174    TR_PEERS_ALL
175};
176
177int  tr_peerMgrGetPeers( tr_torrent      * tor,
178                         tr_pex         ** setme_pex,
179                         uint8_t           address_type,
180                         uint8_t           peer_list_mode,
181                         int               max_peer_count );
182
183void tr_peerMgrStartTorrent( tr_torrent * tor );
184
185void tr_peerMgrStopTorrent( tr_torrent * tor );
186
187void tr_peerMgrAddTorrent( tr_peerMgr         * manager,
188                           struct tr_torrent  * tor );
189
190void tr_peerMgrRemoveTorrent( tr_torrent * tor );
191
192void tr_peerMgrTorrentAvailability( const tr_torrent * tor,
193                                    int8_t           * tab,
194                                    unsigned int       tabCount );
195
196struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor );
197
198void tr_peerMgrTorrentStats( tr_torrent * tor,
199                             int * setmePeersKnown,
200                             int * setmePeersConnected,
201                             int * setmeSeedsConnected,
202                             int * setmeWebseedsSendingToUs,
203                             int * setmePeersSendingToUs,
204                             int * setmePeersGettingFromUs,
205                             int * setmePeersFrom ); /* TR_PEER_FROM__MAX */
206
207struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
208                                          int              * setmeCount );
209
210float tr_peerMgrGetWebseedSpeed( const tr_torrent * tor, uint64_t now );
211
212float* tr_peerMgrWebSpeeds( const tr_torrent * tor );
213
214
215double tr_peerGetPieceSpeed( const tr_peer    * peer,
216                             uint64_t           now,
217                             tr_direction       direction );
218
219/* @} */
220
221#endif
Note: See TracBrowser for help on using the repository browser.