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