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