1 /*
2 
3 Copyright (c) 2015-2018, Arvid Norberg
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 
10     * Redistributions of source code must retain the above copyright
11       notice, this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in
14       the documentation and/or other materials provided with the distribution.
15     * Neither the name of the author nor the names of its
16       contributors may be used to endorse or promote products derived
17       from this software without specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
30 
31 */
32 
33 #ifndef TORRENT_OPERATIONS_HPP_INCLUDED
34 #define TORRENT_OPERATIONS_HPP_INCLUDED
35 
36 #include "libtorrent/config.hpp"
37 #include <cstdint>
38 
39 namespace libtorrent {
40 
41 	// these constants are used to identify the operation that failed, causing a
42 	// peer to disconnect
43 	enum class operation_t : std::uint8_t
44 	{
45 		// the error was unexpected and it is unknown which operation caused it
46 		unknown,
47 
48 		// this is used when the bittorrent logic
49 		// determines to disconnect
50 		bittorrent,
51 
52 		// a call to iocontrol failed
53 		iocontrol,
54 
55 		// a call to ``getpeername()`` failed (querying the remote IP of a
56 		// connection)
57 		getpeername,
58 
59 		// a call to getname failed (querying the local IP of a
60 		// connection)
61 		getname,
62 
63 		// an attempt to allocate a receive buffer failed
64 		alloc_recvbuf,
65 
66 		// an attempt to allocate a send buffer failed
67 		alloc_sndbuf,
68 
69 		// writing to a file failed
70 		file_write,
71 
72 		// reading from a file failed
73 		file_read,
74 
75 		// a non-read and non-write file operation failed
76 		file,
77 
78 		// a socket write operation failed
79 		sock_write,
80 
81 		// a socket read operation failed
82 		sock_read,
83 
84 		// a call to open(), to create a socket socket failed
85 		sock_open,
86 
87 		// a call to bind() on a socket failed
88 		sock_bind,
89 
90 		// an attempt to query the number of bytes available to read from a socket
91 		// failed
92 		available,
93 
94 		// a call related to bittorrent protocol encryption failed
95 		encryption,
96 
97 		// an attempt to connect a socket failed
98 		connect,
99 
100 		// establishing an SSL connection failed
101 		ssl_handshake,
102 
103 		// a connection failed to satisfy the bind interface setting
104 		get_interface,
105 
106 		// a call to listen() on a socket
107 		sock_listen,
108 
109 		// a call to the ioctl to bind a socket to a specific network device or
110 		// adapter
111 		sock_bind_to_device,
112 
113 		// a call to accept() on a socket
114 		sock_accept,
115 
116 		// convert a string into a valid network address
117 		parse_address,
118 
119 		// enumeration network devices or adapters
120 		enum_if,
121 
122 		// invoking stat() on a file
123 		file_stat,
124 
125 		// copying a file
126 		file_copy,
127 
128 		// allocating storage for a file
129 		file_fallocate,
130 
131 		// creating a hard link
132 		file_hard_link,
133 
134 		// removing a file
135 		file_remove,
136 
137 		// renaming a file
138 		file_rename,
139 
140 		// opening a file
141 		file_open,
142 
143 		// creating a directory
144 		mkdir,
145 
146 		// check fast resume data against files on disk
147 		check_resume,
148 
149 		// an unknown exception
150 		exception,
151 
152 		// allocate space for a piece in the cache
153 		alloc_cache_piece,
154 
155 		// move a part-file
156 		partfile_move,
157 
158 		// read from a part file
159 		partfile_read,
160 
161 		// write to a part-file
162 		partfile_write,
163 
164 		// a hostname lookup
165 		hostname_lookup,
166 
167 		// create or read a symlink
168 		symlink,
169 
170 		// handshake with a peer or server
171 		handshake,
172 
173 		// set socket option
174 		sock_option,
175 
176 		// enumeration network routes
177 		enum_route,
178 	};
179 
180 	// maps an operation id (from peer_error_alert and peer_disconnected_alert)
181 	// to its name. See operation_t for the constants
182 	TORRENT_EXPORT char const* operation_name(operation_t op);
183 
184 #if TORRENT_ABI_VERSION == 1
185 	enum deprecated_operation_t : std::uint8_t
186 	{
187 		// the error was unexpected and it is unknown which operation caused it
188 		op_unknown TORRENT_DEPRECATED_ENUM,
189 
190 		// this is used when the bittorrent logic
191 		// determines to disconnect
192 		op_bittorrent TORRENT_DEPRECATED_ENUM ,
193 
194 		// a call to ``iocontrol()`` failed
195 		op_iocontrol TORRENT_DEPRECATED_ENUM,
196 
197 		// a call to ``getpeername()`` failed (querying the remote IP of a
198 		// connection)
199 		op_getpeername TORRENT_DEPRECATED_ENUM,
200 
201 		// a call to ``getsockname()`` failed (querying the local IP of a
202 		// connection)
203 		op_getname TORRENT_DEPRECATED_ENUM,
204 
205 		// an attempt to allocate a receive buffer failed
206 		op_alloc_recvbuf TORRENT_DEPRECATED_ENUM,
207 
208 		// an attempt to allocate a send buffer failed
209 		op_alloc_sndbuf TORRENT_DEPRECATED_ENUM,
210 
211 		// writing to a file failed
212 		op_file_write TORRENT_DEPRECATED_ENUM,
213 
214 		// reading from a file failed
215 		op_file_read TORRENT_DEPRECATED_ENUM,
216 
217 		// a non-read and non-write file operation failed
218 		op_file TORRENT_DEPRECATED_ENUM,
219 
220 		// a socket write operation failed
221 		op_sock_write TORRENT_DEPRECATED_ENUM,
222 
223 		// a socket read operation failed
224 		op_sock_read TORRENT_DEPRECATED_ENUM,
225 
226 		// a call to open(), to create a socket socket failed
227 		op_sock_open TORRENT_DEPRECATED_ENUM,
228 
229 		// a call to bind() on a socket failed
230 		op_sock_bind TORRENT_DEPRECATED_ENUM,
231 
232 		// an attempt to query the number of bytes available to read from a socket
233 		// failed
234 		op_available TORRENT_DEPRECATED_ENUM,
235 
236 		// a call related to bittorrent protocol encryption failed
237 		op_encryption TORRENT_DEPRECATED_ENUM,
238 
239 		// an attempt to connect a socket failed
240 		op_connect TORRENT_DEPRECATED_ENUM,
241 
242 		// establishing an SSL connection failed
243 		op_ssl_handshake TORRENT_DEPRECATED_ENUM,
244 
245 		// a connection failed to satisfy the bind interface setting
246 		op_get_interface TORRENT_DEPRECATED_ENUM,
247 	};
248 #endif
249 
250 }
251 
252 #endif // TORRENT_OPERATIONS_HPP_INCLUDED
253