1 | /* |
---|
2 | * This file Copyright (C) 2007-2008 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-io.h 7576 2009-01-02 06:28:22Z charles $ |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef __TRANSMISSION__ |
---|
14 | #error only libtransmission should #include this header. |
---|
15 | #endif |
---|
16 | |
---|
17 | #ifndef TR_PEER_IO_H |
---|
18 | #define TR_PEER_IO_H |
---|
19 | |
---|
20 | /** |
---|
21 | *** |
---|
22 | **/ |
---|
23 | |
---|
24 | struct evbuffer; |
---|
25 | struct tr_address; |
---|
26 | struct tr_bandwidth; |
---|
27 | struct tr_crypto; |
---|
28 | typedef struct tr_peerIo tr_peerIo; |
---|
29 | |
---|
30 | /** |
---|
31 | *** |
---|
32 | **/ |
---|
33 | |
---|
34 | tr_peerIo* tr_peerIoNewOutgoing( tr_session * session, |
---|
35 | const struct tr_address * addr, |
---|
36 | tr_port port, |
---|
37 | const uint8_t * torrentHash ); |
---|
38 | |
---|
39 | tr_peerIo* tr_peerIoNewIncoming( tr_session * session, |
---|
40 | const struct tr_address * addr, |
---|
41 | tr_port port, |
---|
42 | int socket ); |
---|
43 | |
---|
44 | void tr_peerIoFree ( tr_peerIo * io ); |
---|
45 | |
---|
46 | tr_bool tr_isPeerIo ( const tr_peerIo * io ); |
---|
47 | |
---|
48 | |
---|
49 | /** |
---|
50 | *** |
---|
51 | **/ |
---|
52 | |
---|
53 | void tr_peerIoEnableLTEP( tr_peerIo * io, tr_bool flag ); |
---|
54 | |
---|
55 | tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io ); |
---|
56 | |
---|
57 | void tr_peerIoEnableFEXT( tr_peerIo * io, tr_bool flag ); |
---|
58 | |
---|
59 | tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io ); |
---|
60 | |
---|
61 | /** |
---|
62 | *** |
---|
63 | **/ |
---|
64 | |
---|
65 | tr_session* tr_peerIoGetSession ( tr_peerIo * io ); |
---|
66 | |
---|
67 | const char* tr_peerIoAddrStr( const struct tr_address * addr, |
---|
68 | tr_port port ); |
---|
69 | |
---|
70 | const char* tr_peerIoGetAddrStr( const tr_peerIo * io ); |
---|
71 | |
---|
72 | const struct tr_address * tr_peerIoGetAddress( const tr_peerIo * io, |
---|
73 | tr_port * port ); |
---|
74 | |
---|
75 | const uint8_t* tr_peerIoGetTorrentHash( tr_peerIo * io ); |
---|
76 | |
---|
77 | int tr_peerIoHasTorrentHash( const tr_peerIo * io ); |
---|
78 | |
---|
79 | void tr_peerIoSetTorrentHash( tr_peerIo * io, |
---|
80 | const uint8_t * hash ); |
---|
81 | |
---|
82 | int tr_peerIoReconnect( tr_peerIo * io ); |
---|
83 | |
---|
84 | tr_bool tr_peerIoIsIncoming( const tr_peerIo * io ); |
---|
85 | |
---|
86 | extern inline int tr_peerIoGetAge( const tr_peerIo * io ); |
---|
87 | |
---|
88 | |
---|
89 | /** |
---|
90 | *** |
---|
91 | **/ |
---|
92 | |
---|
93 | void tr_peerIoSetPeersId( tr_peerIo * io, |
---|
94 | const uint8_t * peer_id ); |
---|
95 | |
---|
96 | const uint8_t* tr_peerIoGetPeersId( const tr_peerIo * io ); |
---|
97 | |
---|
98 | /** |
---|
99 | *** |
---|
100 | **/ |
---|
101 | |
---|
102 | typedef enum |
---|
103 | { |
---|
104 | READ_NOW, |
---|
105 | READ_LATER, |
---|
106 | READ_ERR |
---|
107 | } |
---|
108 | ReadState; |
---|
109 | |
---|
110 | typedef ReadState ( *tr_can_read_cb )( tr_peerIo * io, |
---|
111 | void * user_data, |
---|
112 | size_t * setme_piece_byte_count ); |
---|
113 | |
---|
114 | typedef void ( *tr_did_write_cb )( tr_peerIo * io, |
---|
115 | size_t bytesWritten, |
---|
116 | int wasPieceData, |
---|
117 | void * userData ); |
---|
118 | |
---|
119 | typedef void ( *tr_net_error_cb )( tr_peerIo * io, |
---|
120 | short what, |
---|
121 | void * userData ); |
---|
122 | |
---|
123 | void tr_peerIoSetIOFuncs ( tr_peerIo * io, |
---|
124 | tr_can_read_cb readcb, |
---|
125 | tr_did_write_cb writecb, |
---|
126 | tr_net_error_cb errcb, |
---|
127 | void * user_data ); |
---|
128 | |
---|
129 | /** |
---|
130 | *** |
---|
131 | **/ |
---|
132 | |
---|
133 | void tr_peerIoWrite ( tr_peerIo * io, |
---|
134 | const void * writeme, |
---|
135 | size_t writemeLen, |
---|
136 | int isPieceData ); |
---|
137 | |
---|
138 | void tr_peerIoWriteBuf ( tr_peerIo * io, |
---|
139 | struct evbuffer * buf, |
---|
140 | int isPieceData ); |
---|
141 | |
---|
142 | /** |
---|
143 | *** |
---|
144 | **/ |
---|
145 | |
---|
146 | struct tr_crypto* tr_peerIoGetCrypto( tr_peerIo * io ); |
---|
147 | |
---|
148 | typedef enum |
---|
149 | { |
---|
150 | /* these match the values in MSE's crypto_select */ |
---|
151 | PEER_ENCRYPTION_NONE = ( 1 << 0 ), |
---|
152 | PEER_ENCRYPTION_RC4 = ( 1 << 1 ) |
---|
153 | } |
---|
154 | EncryptionMode; |
---|
155 | |
---|
156 | void tr_peerIoSetEncryption( tr_peerIo * io, |
---|
157 | int encryptionMode ); |
---|
158 | |
---|
159 | int tr_peerIoIsEncrypted( const tr_peerIo * io ); |
---|
160 | |
---|
161 | void tr_peerIoWriteBytes( tr_peerIo * io, |
---|
162 | struct evbuffer * outbuf, |
---|
163 | const void * bytes, |
---|
164 | size_t byteCount ); |
---|
165 | |
---|
166 | void tr_peerIoWriteUint8( tr_peerIo * io, |
---|
167 | struct evbuffer * outbuf, |
---|
168 | uint8_t writeme ); |
---|
169 | |
---|
170 | void tr_peerIoWriteUint16( tr_peerIo * io, |
---|
171 | struct evbuffer * outbuf, |
---|
172 | uint16_t writeme ); |
---|
173 | |
---|
174 | void tr_peerIoWriteUint32( tr_peerIo * io, |
---|
175 | struct evbuffer * outbuf, |
---|
176 | uint32_t writeme ); |
---|
177 | |
---|
178 | void tr_peerIoReadBytes( tr_peerIo * io, |
---|
179 | struct evbuffer * inbuf, |
---|
180 | void * bytes, |
---|
181 | size_t byteCount ); |
---|
182 | |
---|
183 | extern inline void |
---|
184 | tr_peerIoReadUint8( tr_peerIo * io, |
---|
185 | struct evbuffer * inbuf, |
---|
186 | uint8_t * setme ); |
---|
187 | |
---|
188 | extern inline void |
---|
189 | tr_peerIoReadUint16( tr_peerIo * io, |
---|
190 | struct evbuffer * inbuf, |
---|
191 | uint16_t * setme ); |
---|
192 | |
---|
193 | extern inline void |
---|
194 | tr_peerIoReadUint32( tr_peerIo * io, |
---|
195 | struct evbuffer * inbuf, |
---|
196 | uint32_t * setme ); |
---|
197 | |
---|
198 | void tr_peerIoDrain( tr_peerIo * io, |
---|
199 | struct evbuffer * inbuf, |
---|
200 | size_t byteCount ); |
---|
201 | |
---|
202 | /** |
---|
203 | *** |
---|
204 | **/ |
---|
205 | |
---|
206 | size_t tr_peerIoGetWriteBufferSpace( const tr_peerIo * io ); |
---|
207 | |
---|
208 | void tr_peerIoSetBandwidth( tr_peerIo * io, |
---|
209 | struct tr_bandwidth * bandwidth ); |
---|
210 | |
---|
211 | void tr_peerIoBandwidthUsed( tr_peerIo * io, |
---|
212 | tr_direction direction, |
---|
213 | size_t byteCount, |
---|
214 | int isPieceData ); |
---|
215 | |
---|
216 | /** |
---|
217 | *** |
---|
218 | **/ |
---|
219 | |
---|
220 | extern inline tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, |
---|
221 | tr_direction direction ); |
---|
222 | |
---|
223 | void tr_peerIoSetEnabled( tr_peerIo * io, |
---|
224 | tr_direction dir, |
---|
225 | tr_bool isEnabled ); |
---|
226 | |
---|
227 | int tr_peerIoFlush( tr_peerIo * io, |
---|
228 | tr_direction dir, |
---|
229 | size_t byteLimit ); |
---|
230 | |
---|
231 | extern inline struct evbuffer * tr_peerIoGetReadBuffer( tr_peerIo * io ); |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | #endif |
---|