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

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

(trunk) update the copyright notices

  • Property svn:keywords set to Date Rev Author Id
File size: 6.2 KB
Line 
1/*
2 * This file Copyright (C) 2007-2009 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 9671 2009-12-05 02:19:24Z 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;
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    struct tr_peerIo       * io;
94    struct peer_atom       * atom;
95
96    struct tr_bitfield     * blame;
97    struct tr_bitset         have;
98
99    /** how complete the peer's copy of the torrent is. [0.0...1.0] */
100    float                    progress;
101
102    /* the client name from the `v' string in LTEP's handshake dictionary */
103    char                   * client;
104
105    time_t                   chokeChangedAt;
106
107    struct tr_peermsgs     * msgs;
108    tr_publisher_tag         msgsTag;
109}
110tr_peer;
111
112const tr_address * tr_peerAddress( const tr_peer * );
113
114int tr_pexCompare( const void * a, const void * b );
115
116tr_peerMgr* tr_peerMgrNew( tr_session * );
117
118void tr_peerMgrFree( tr_peerMgr * manager );
119
120tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor,
121                              const tr_address * addr );
122
123void tr_peerMgrGetNextRequests( tr_torrent          * torrent,
124                                tr_peer             * peer,
125                                int                   numwant,
126                                tr_block_index_t    * setme,
127                                int                 * numgot );
128
129tr_bool tr_peerMgrDidPeerRequest( const tr_torrent  * torrent,
130                                  const tr_peer     * peer,
131                                  tr_block_index_t    block );
132
133void tr_peerMgrRebuildRequests( tr_torrent * torrent );
134
135void tr_peerMgrAddIncoming( tr_peerMgr  * manager,
136                            tr_address  * addr,
137                            tr_port       port,
138                            int           socket );
139
140tr_pex * tr_peerMgrCompactToPex( const void    * compact,
141                                 size_t          compactLen,
142                                 const uint8_t * added_f,
143                                 size_t          added_f_len,
144                                 size_t        * setme_pex_count );
145
146tr_pex * tr_peerMgrCompact6ToPex( const void    * compact,
147                                  size_t          compactLen,
148                                  const uint8_t * added_f,
149                                  size_t          added_f_len,
150                                  size_t        * pexCount );
151
152tr_pex * tr_peerMgrArrayToPex( const void * array,
153                               size_t       arrayLen,
154                               size_t      * setme_pex_count );
155
156void tr_peerMgrAddPex( tr_torrent     * tor,
157                       uint8_t          from,
158                       const tr_pex   * pex );
159
160void tr_peerMgrSetBlame( tr_torrent        * tor,
161                         tr_piece_index_t    pieceIndex,
162                         int                 success );
163
164enum 
165{
166    TR_PEERS_CONNECTED,
167    TR_PEERS_ALL
168};
169
170int  tr_peerMgrGetPeers( tr_torrent      * tor,
171                         tr_pex         ** setme_pex,
172                         uint8_t           address_type,
173                         uint8_t           peer_list_mode,
174                         int               max_peer_count );
175
176void tr_peerMgrStartTorrent( tr_torrent * tor );
177
178void tr_peerMgrStopTorrent( tr_torrent * tor );
179
180void tr_peerMgrAddTorrent( tr_peerMgr         * manager,
181                           struct tr_torrent  * tor );
182
183void tr_peerMgrRemoveTorrent( tr_torrent * tor );
184
185void tr_peerMgrTorrentAvailability( const tr_torrent * tor,
186                                    int8_t           * tab,
187                                    unsigned int       tabCount );
188
189struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor );
190
191void tr_peerMgrTorrentStats( tr_torrent * tor,
192                             int * setmePeersKnown,
193                             int * setmePeersConnected,
194                             int * setmeSeedsConnected,
195                             int * setmeWebseedsSendingToUs,
196                             int * setmePeersSendingToUs,
197                             int * setmePeersGettingFromUs,
198                             int * setmePeersFrom ); /* TR_PEER_FROM__MAX */
199
200struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
201                                          int              * setmeCount );
202
203float tr_peerMgrGetWebseedSpeed( const tr_torrent * tor, uint64_t now );
204
205float* tr_peerMgrWebSpeeds( const tr_torrent * tor );
206
207
208double tr_peerGetPieceSpeed( const tr_peer    * peer,
209                             uint64_t           now,
210                             tr_direction       direction );
211
212/* @} */
213
214#endif
Note: See TracBrowser for help on using the repository browser.