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 7224 2008-12-01 20:51:01Z 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 | #else |
---|
25 | #include <netinet/in.h> /* struct in_addr */ |
---|
26 | #endif |
---|
27 | |
---|
28 | struct in_addr; |
---|
29 | struct tr_handle; |
---|
30 | struct tr_peer_stat; |
---|
31 | struct tr_torrent; |
---|
32 | typedef struct tr_peerMgr tr_peerMgr; |
---|
33 | |
---|
34 | enum |
---|
35 | { |
---|
36 | /* corresponds to ut_pex's added.f flags */ |
---|
37 | ADDED_F_ENCRYPTION_FLAG = 1, |
---|
38 | |
---|
39 | /* corresponds to ut_pex's added.f flags */ |
---|
40 | ADDED_F_SEED_FLAG = 2, |
---|
41 | }; |
---|
42 | |
---|
43 | typedef struct tr_pex |
---|
44 | { |
---|
45 | struct in_addr in_addr; |
---|
46 | tr_port port; |
---|
47 | uint8_t flags; |
---|
48 | } |
---|
49 | tr_pex; |
---|
50 | |
---|
51 | int tr_pexCompare( const void * a, const void * b ); |
---|
52 | |
---|
53 | tr_peerMgr* tr_peerMgrNew( struct tr_handle * ); |
---|
54 | |
---|
55 | void tr_peerMgrFree( tr_peerMgr * manager ); |
---|
56 | |
---|
57 | int tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, |
---|
58 | const uint8_t * torrentHash, |
---|
59 | const struct in_addr * addr ); |
---|
60 | |
---|
61 | void tr_peerMgrAddIncoming( tr_peerMgr * manager, |
---|
62 | struct in_addr * addr, |
---|
63 | tr_port port, |
---|
64 | int socket ); |
---|
65 | |
---|
66 | tr_pex * tr_peerMgrCompactToPex( const void * compact, |
---|
67 | size_t compactLen, |
---|
68 | const uint8_t * added_f, |
---|
69 | size_t added_f_len, |
---|
70 | size_t * setme_pex_count ); |
---|
71 | |
---|
72 | void tr_peerMgrAddPex( tr_peerMgr * manager, |
---|
73 | const uint8_t * torrentHash, |
---|
74 | uint8_t from, |
---|
75 | const tr_pex * pex ); |
---|
76 | |
---|
77 | void tr_peerMgrSetBlame( tr_peerMgr * manager, |
---|
78 | const uint8_t * torrentHash, |
---|
79 | tr_piece_index_t pieceIndex, |
---|
80 | int success ); |
---|
81 | |
---|
82 | int tr_peerMgrGetPeers( tr_peerMgr * manager, |
---|
83 | const uint8_t * torrentHash, |
---|
84 | tr_pex ** setme_pex ); |
---|
85 | |
---|
86 | void tr_peerMgrStartTorrent( tr_peerMgr * manager, |
---|
87 | const uint8_t * torrentHash ); |
---|
88 | |
---|
89 | void tr_peerMgrStopTorrent( tr_peerMgr * manager, |
---|
90 | const uint8_t * torrentHash ); |
---|
91 | |
---|
92 | void tr_peerMgrAddTorrent( tr_peerMgr * manager, |
---|
93 | struct tr_torrent * tor ); |
---|
94 | |
---|
95 | void tr_peerMgrRemoveTorrent( tr_peerMgr * manager, |
---|
96 | const uint8_t * torrentHash ); |
---|
97 | |
---|
98 | void tr_peerMgrTorrentAvailability( const tr_peerMgr * manager, |
---|
99 | const uint8_t * torrentHash, |
---|
100 | int8_t * tab, |
---|
101 | unsigned int tabCount ); |
---|
102 | |
---|
103 | struct tr_bitfield* tr_peerMgrGetAvailable( const tr_peerMgr * manager, |
---|
104 | const uint8_t * torrentHash ); |
---|
105 | |
---|
106 | int tr_peerMgrHasConnections( const tr_peerMgr * manager, |
---|
107 | const uint8_t * torrentHash ); |
---|
108 | |
---|
109 | void tr_peerMgrTorrentStats( const tr_peerMgr * manager, |
---|
110 | const uint8_t * torrentHash, |
---|
111 | int * setmePeersKnown, |
---|
112 | int * setmePeersConnected, |
---|
113 | int * setmeSeedsConnected, |
---|
114 | int * setmeWebseedsSendingToUs, |
---|
115 | int * setmePeersSendingToUs, |
---|
116 | int * setmePeersGettingFromUs, |
---|
117 | int * setmePeersFrom ); /* TR_PEER_FROM__MAX */ |
---|
118 | |
---|
119 | struct tr_peer_stat* tr_peerMgrPeerStats( const tr_peerMgr * manager, |
---|
120 | const uint8_t * torrentHash, |
---|
121 | int * setmeCount ); |
---|
122 | |
---|
123 | float* tr_peerMgrWebSpeeds( const tr_peerMgr * manager, |
---|
124 | const uint8_t * torrentHash ); |
---|
125 | |
---|
126 | |
---|
127 | #endif |
---|