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

Last change on this file since 9470 was 9470, checked in by charles, 12 years ago

(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...(trunk libT) undo r9465 + r9466, which was the experimental new request manager. It still still needs some tinkering before it's ready for the nightlies...

  • Property svn:keywords set to Date Rev Author Id
File size: 5.5 KB
Line 
1/*
2 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
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 9470 2009-11-02 00:17:30Z 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 "net.h"
28#include "publish.h" /* tr_publisher_tag */
29#include "utils.h"
30
31/**
32 * @addtogroup peers Peers
33 * @{
34 */
35
36struct tr_peer_stat;
37struct tr_torrent;
38typedef struct tr_peerMgr tr_peerMgr;
39
40enum
41{
42    /* corresponds to ut_pex's added.f flags */
43    ADDED_F_ENCRYPTION_FLAG = 1,
44
45    /* corresponds to ut_pex's added.f flags */
46    ADDED_F_SEED_FLAG = 2,
47};
48
49typedef struct tr_pex
50{
51    tr_address addr;
52    tr_port    port;
53    uint8_t    flags;
54}
55tr_pex;
56
57
58struct tr_bandwidth;
59struct tr_peerIo;
60struct tr_peermsgs;
61
62enum
63{
64    ENCRYPTION_PREFERENCE_UNKNOWN,
65    ENCRYPTION_PREFERENCE_YES,
66    ENCRYPTION_PREFERENCE_NO
67};
68
69/* opaque forward declaration */
70struct peer_atom;
71
72/**
73 * State information about a connected peer.
74 *
75 * @see struct peer_atom
76 * @see tr_peermsgs
77 */
78typedef struct tr_peer
79{
80    tr_bool                  peerIsChoked;
81    tr_bool                  peerIsInterested;
82    tr_bool                  clientIsChoked;
83    tr_bool                  clientIsInterested;
84    tr_bool                  doPurge;
85
86    /* number of bad pieces they've contributed to */
87    uint8_t                  strikes;
88
89    uint8_t                  encryption_preference;
90    tr_port                  dht_port;
91    struct tr_peerIo       * io;
92    struct peer_atom       * atom;
93
94    struct tr_bitfield     * blame;
95    struct tr_bitfield     * have;
96
97    /** how complete the peer's copy of the torrent is. [0.0...1.0] */
98    float                    progress;
99
100    /* the client name from the `v' string in LTEP's handshake dictionary */
101    char                   * client;
102
103    time_t                   chokeChangedAt;
104
105    struct tr_peermsgs     * msgs;
106    tr_publisher_tag         msgsTag;
107}
108tr_peer;
109
110const tr_address * tr_peerAddress( const tr_peer * );
111
112int tr_pexCompare( const void * a, const void * b );
113
114tr_peerMgr* tr_peerMgrNew( tr_session * );
115
116void tr_peerMgrFree( tr_peerMgr * manager );
117
118tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor,
119                              const tr_address * addr );
120
121void tr_peerMgrAddIncoming( tr_peerMgr  * manager,
122                            tr_address  * addr,
123                            tr_port       port,
124                            int           socket );
125
126tr_pex * tr_peerMgrCompactToPex( const void    * compact,
127                                 size_t          compactLen,
128                                 const uint8_t * added_f,
129                                 size_t          added_f_len,
130                                 size_t        * setme_pex_count );
131
132tr_pex * tr_peerMgrCompact6ToPex( const void    * compact,
133                                  size_t          compactLen,
134                                  const uint8_t * added_f,
135                                  size_t          added_f_len,
136                                  size_t        * pexCount );
137
138tr_pex * tr_peerMgrArrayToPex( const void * array,
139                               size_t       arrayLen,
140                               size_t      * setme_pex_count );
141
142void tr_peerMgrAddPex( tr_torrent     * tor,
143                       uint8_t          from,
144                       const tr_pex   * pex );
145
146void tr_peerMgrSetBlame( tr_torrent        * tor,
147                         tr_piece_index_t    pieceIndex,
148                         int                 success );
149
150int  tr_peerMgrGetPeers( tr_torrent      * tor,
151                         tr_pex         ** setme_pex,
152                         uint8_t           af,
153                         int               maxPeerCount );
154
155void tr_peerMgrStartTorrent( tr_torrent * tor );
156
157void tr_peerMgrStopTorrent( tr_torrent * tor );
158
159void tr_peerMgrAddTorrent( tr_peerMgr         * manager,
160                           struct tr_torrent  * tor );
161
162void tr_peerMgrRemoveTorrent( tr_torrent * tor );
163
164void tr_peerMgrTorrentAvailability( const tr_torrent * tor,
165                                    int8_t           * tab,
166                                    unsigned int       tabCount );
167
168struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor );
169
170void tr_peerMgrTorrentStats( tr_torrent * tor,
171                             int * setmePeersKnown,
172                             int * setmePeersConnected,
173                             int * setmeSeedsConnected,
174                             int * setmeWebseedsSendingToUs,
175                             int * setmePeersSendingToUs,
176                             int * setmePeersGettingFromUs,
177                             int * setmePeersFrom ); /* TR_PEER_FROM__MAX */
178
179struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
180                                          int              * setmeCount );
181
182float tr_peerMgrGetWebseedSpeed( const tr_torrent * tor, uint64_t now );
183
184float* tr_peerMgrWebSpeeds( const tr_torrent * tor );
185
186
187double tr_peerGetPieceSpeed( const tr_peer    * peer,
188                             uint64_t           now,
189                             tr_direction       direction );
190
191/* @} */
192
193#endif
Note: See TracBrowser for help on using the repository browser.