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

Last change on this file since 6468 was 6468, checked in by charles, 15 years ago

#1168: reading past the end of KTorrent's pex added.f strings

  • Property svn:keywords set to Date Rev Author Id
File size: 4.6 KB
Line 
1/*
2 * This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.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 6468 2008-08-10 14:58:11Z charles $
11 */
12
13#ifndef TR_PEER_MGR_H
14#define TR_PEER_MGR_H
15
16#include <inttypes.h> /* uint16_t */
17
18#ifdef WIN32
19#include <winsock2.h> /* struct in_addr */
20#else
21#include <netinet/in.h> /* struct in_addr */
22#endif
23
24struct in_addr;
25struct tr_handle;
26struct tr_peer_stat;
27struct tr_torrent;
28typedef struct tr_peerMgr tr_peerMgr;
29
30enum
31{
32    /* corresponds to ut_pex's added.f flags */
33    ADDED_F_ENCRYPTION_FLAG = 1,
34
35    /* corresponds to ut_pex's added.f flags */
36    ADDED_F_SEED_FLAG = 2,
37};
38
39typedef struct tr_pex
40{
41    struct in_addr in_addr;
42    uint16_t port;
43    uint8_t flags;
44}
45tr_pex;
46
47int tr_pexCompare( const void * a, const void * b );
48
49tr_peerMgr* tr_peerMgrNew( struct tr_handle * );
50
51void tr_peerMgrFree( tr_peerMgr * manager );
52
53int tr_peerMgrPeerIsSeed( const tr_peerMgr      * mgr,
54                          const uint8_t         * torrentHash,
55                          const struct in_addr  * addr );
56
57void tr_peerMgrAddIncoming( tr_peerMgr      * manager,
58                            struct in_addr  * addr,
59                            uint16_t          port,
60                            int               socket );
61
62tr_pex * tr_peerMgrCompactToPex( const void     * compact,
63                                 size_t           compactLen,
64                                 const uint8_t  * added_f,
65                                 size_t           added_f_len,
66                                 size_t         * setme_pex_count );
67                             
68void tr_peerMgrAddPex( tr_peerMgr     * manager,
69                       const uint8_t  * torrentHash,
70                       uint8_t          from,
71                       const tr_pex   * pex );
72
73void tr_peerMgrSetBlame( tr_peerMgr     * manager,
74                         const uint8_t  * torrentHash,
75                         int              pieceIndex,
76                         int              success );
77
78int tr_peerMgrGetPeers( tr_peerMgr      * manager,
79                        const uint8_t   * torrentHash,
80                        tr_pex         ** setme_pex );
81
82void tr_peerMgrStartTorrent( tr_peerMgr     * manager,
83                             const uint8_t  * torrentHash );
84
85void tr_peerMgrStopTorrent( tr_peerMgr     * manager,
86                            const uint8_t  * torrentHash );
87
88void tr_peerMgrAddTorrent( tr_peerMgr         * manager,
89                           struct tr_torrent  * tor );
90
91void tr_peerMgrRemoveTorrent( tr_peerMgr     * manager,
92                               const uint8_t  * torrentHash );
93
94void tr_peerMgrTorrentAvailability( const tr_peerMgr * manager,
95                                    const uint8_t    * torrentHash,
96                                    int8_t           * tab,
97                                    int                tabCount );
98
99struct tr_bitfield* tr_peerMgrGetAvailable( const tr_peerMgr * manager,
100                                            const uint8_t    * torrentHash );
101
102int tr_peerMgrHasConnections( const tr_peerMgr * manager,
103                              const uint8_t    * torrentHash );
104
105void tr_peerMgrTorrentStats( const tr_peerMgr * manager,
106                             const uint8_t    * torrentHash,
107                             int              * setmePeersKnown,
108                             int              * setmePeersConnected,
109                             int              * setmeSeedsConnected,
110                             int              * setmeWebseedsSendingToUs,
111                             int              * setmePeersSendingToUs,
112                             int              * setmePeersGettingFromUs,
113                             int              * setmePeersFrom ); /* <-- array of TR_PEER_FROM__MAX */
114
115struct tr_peer_stat * tr_peerMgrPeerStats( const tr_peerMgr  * manager,
116                                           const uint8_t     * torrentHash,
117                                           int               * setmeCount );
118
119float* tr_peerMgrWebSpeeds( const tr_peerMgr * manager,
120                            const uint8_t    * torrentHash );
121
122                             
123struct tr_bitfield *
124tr_peerMgrGenerateAllowedSet( const uint32_t         setCount,
125                              const uint32_t         pieceCount,
126                              const uint8_t          infohash[20],
127                              const struct in_addr * ip );
128
129
130
131#endif
Note: See TracBrowser for help on using the repository browser.