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

Last change on this file since 11709 was 11709, checked in by jordan, 11 years ago

Update the copyright year in the source code comments.

The Berne Convention says that the copyright year is moot, so instead of adding another year to each file as in previous years, I've removed the year altogether from the source code comments in libtransmission, gtk, qt, utils, daemon, and cli.

Juliusz's copyright notice in tr-dht and Johannes' copyright notice in tr-lpd have been left alone; it didn't seem appropriate to modify them.

  • Property svn:keywords set to Date Rev Author Id
File size: 7.4 KB
Line 
1/*
2 * This file Copyright (C) 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 11709 2011-01-19 13:48:47Z jordan $
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 "history.h"
29#include "net.h"
30#include "peer-common.h" /* struct peer_request */
31
32/**
33 * @addtogroup peers Peers
34 * @{
35 */
36
37struct tr_peer_stat;
38struct tr_torrent;
39typedef struct tr_peerMgr tr_peerMgr;
40
41/* added_f's bitwise-or'ed flags */
42enum
43{
44    /* true if the peer supports encryption */
45    ADDED_F_ENCRYPTION_FLAG = 1,
46
47    /* true if the peer is a seed or partial seed */
48    ADDED_F_SEED_FLAG = 2,
49
50    /* true if the peer supports uTP */
51    ADDED_F_UTP_FLAGS = 4,
52
53    /* true if the peer has holepunch support */
54    ADDED_F_HOLEPUNCH = 8,
55
56    /* true if the peer telling us about this peer
57     * initiated the connection (implying that it is connectible) */ 
58   ADDED_F_CONNECTABLE = 16 
59};
60
61typedef struct tr_pex
62{
63    tr_address addr;
64    tr_port    port; /* this field is in network byte order */
65    uint8_t    flags;
66}
67tr_pex;
68
69
70struct tr_bandwidth;
71struct tr_peerIo;
72struct tr_peermsgs;
73
74enum
75{
76    ENCRYPTION_PREFERENCE_UNKNOWN,
77    ENCRYPTION_PREFERENCE_YES,
78    ENCRYPTION_PREFERENCE_NO
79};
80
81/* opaque forward declaration */
82struct peer_atom;
83
84/**
85 * State information about a connected peer.
86 *
87 * @see struct peer_atom
88 * @see tr_peermsgs
89 */
90typedef struct tr_peer
91{
92    tr_bool                  peerIsChoked;
93    tr_bool                  peerIsInterested;
94    tr_bool                  clientIsChoked;
95    tr_bool                  clientIsInterested;
96    tr_bool                  doPurge;
97
98    /* number of bad pieces they've contributed to */
99    uint8_t                  strikes;
100
101    uint8_t                  encryption_preference;
102    tr_port                  dht_port;
103
104    /* how many requests the peer has made that we haven't responded to yet */
105    int                      pendingReqsToClient;
106
107    /* how many requests we've made and are currently awaiting a response for */
108    int                      pendingReqsToPeer;
109
110    struct tr_peerIo       * io;
111    struct peer_atom       * atom;
112
113    struct tr_bitfield     * blame;
114    struct tr_bitset         have;
115
116    /** how complete the peer's copy of the torrent is. [0.0...1.0] */
117    float                    progress;
118
119    /* the client name from the `v' string in LTEP's handshake dictionary */
120    char                   * client;
121
122    time_t                   chokeChangedAt;
123
124    tr_recentHistory       * blocksSentToClient;
125    tr_recentHistory       * blocksSentToPeer;
126
127    tr_recentHistory       * cancelsSentToClient;
128    tr_recentHistory       * cancelsSentToPeer;
129
130    struct tr_peermsgs     * msgs;
131}
132tr_peer;
133
134static inline tr_bool
135tr_isPex( const tr_pex * pex )
136{
137    return pex && tr_isAddress( &pex->addr );
138}
139
140const tr_address * tr_peerAddress( const tr_peer * );
141
142int tr_pexCompare( const void * a, const void * b );
143
144tr_peerMgr* tr_peerMgrNew( tr_session * );
145
146void tr_peerMgrFree( tr_peerMgr * manager );
147
148tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor,
149                              const tr_address * addr );
150
151void tr_peerMgrGetNextRequests( tr_torrent          * torrent,
152                                tr_peer             * peer,
153                                int                   numwant,
154                                tr_block_index_t    * setme,
155                                int                 * numgot );
156
157tr_bool tr_peerMgrDidPeerRequest( const tr_torrent  * torrent,
158                                  const tr_peer     * peer,
159                                  tr_block_index_t    block );
160
161void tr_peerMgrRebuildRequests( tr_torrent * torrent );
162
163void tr_peerMgrAddIncoming( tr_peerMgr  * manager,
164                            tr_address  * addr,
165                            tr_port       port,
166                            int           socket );
167
168tr_pex * tr_peerMgrCompactToPex( const void    * compact,
169                                 size_t          compactLen,
170                                 const uint8_t * added_f,
171                                 size_t          added_f_len,
172                                 size_t        * setme_pex_count );
173
174tr_pex * tr_peerMgrCompact6ToPex( const void    * compact,
175                                  size_t          compactLen,
176                                  const uint8_t * added_f,
177                                  size_t          added_f_len,
178                                  size_t        * pexCount );
179
180tr_pex * tr_peerMgrArrayToPex( const void * array,
181                               size_t       arrayLen,
182                               size_t      * setme_pex_count );
183
184/**
185 * @param seedProbability [0..100] for likelihood that the peer is a seed; -1 for unknown
186 */
187void tr_peerMgrAddPex( tr_torrent     * tor,
188                       uint8_t          from,
189                       const tr_pex   * pex,
190                       int8_t           seedProbability );
191
192void tr_peerMgrMarkAllAsSeeds( tr_torrent * tor );
193
194void tr_peerMgrSetBlame( tr_torrent        * tor,
195                         tr_piece_index_t    pieceIndex,
196                         int                 success );
197
198enum
199{
200    TR_PEERS_CONNECTED,
201    TR_PEERS_ALL
202};
203
204int  tr_peerMgrGetPeers( tr_torrent      * tor,
205                         tr_pex         ** setme_pex,
206                         uint8_t           address_type,
207                         uint8_t           peer_list_mode,
208                         int               max_peer_count );
209
210void tr_peerMgrStartTorrent( tr_torrent * tor );
211
212void tr_peerMgrStopTorrent( tr_torrent * tor );
213
214void tr_peerMgrAddTorrent( tr_peerMgr         * manager,
215                           struct tr_torrent  * tor );
216
217void tr_peerMgrRemoveTorrent( tr_torrent * tor );
218
219void tr_peerMgrTorrentAvailability( const tr_torrent * tor,
220                                    int8_t           * tab,
221                                    unsigned int       tabCount );
222
223struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor );
224
225void tr_peerMgrOnBlocklistChanged( tr_peerMgr * manager );
226
227void tr_peerMgrTorrentStats( tr_torrent * tor,
228                             int * setmePeersKnown,
229                             int * setmePeersConnected,
230                             int * setmeSeedsConnected,
231                             int * setmeWebseedsSendingToUs,
232                             int * setmePeersSendingToUs,
233                             int * setmePeersGettingFromUs,
234                             int * setmePeersFrom ); /* TR_PEER_FROM__MAX */
235
236struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
237                                          int              * setmeCount );
238
239int tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now );
240
241double* tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor );
242
243
244int tr_peerGetPieceSpeed_Bps( const tr_peer    * peer,
245                              uint64_t           now,
246                              tr_direction       direction );
247
248void tr_peerMgrClearInterest( tr_torrent * tor );
249
250/* @} */
251
252#endif
Note: See TracBrowser for help on using the repository browser.