makes all tracker requests 'stopped' when aborting
[libtorrent.git] / include / libtorrent / udp_socket.hpp
blob77eae5050e5b2009db3468544a8c0740dbc756b5
1 /*
3 Copyright (c) 2007, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
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.
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.
33 #ifndef TORRENT_UDP_SOCKET_HPP_INCLUDED
34 #define TORRENT_UDP_SOCKET_HPP_INCLUDED
36 #include "libtorrent/socket.hpp"
37 #include "libtorrent/session_settings.hpp"
39 #include <vector>
40 #include <boost/function.hpp>
42 namespace libtorrent
44 class connection_queue;
46 class udp_socket
48 public:
49 typedef boost::function<void(error_code const& ec
50 , udp::endpoint const&, char const* buf, int size)> callback_t;
52 udp_socket(io_service& ios, callback_t const& c, connection_queue& cc);
54 bool is_open() const { return m_ipv4_sock.is_open() || m_ipv6_sock.is_open(); }
55 io_service& get_io_service() { return m_ipv4_sock.get_io_service(); }
57 void send(udp::endpoint const& ep, char const* p, int len, error_code& ec);
58 void bind(udp::endpoint const& ep, error_code& ec);
59 void bind(int port);
60 void close();
61 int local_port() const { return m_bind_port; }
63 void set_proxy_settings(proxy_settings const& ps);
64 proxy_settings const& get_proxy_settings() { return m_proxy_settings; }
66 private:
68 callback_t m_callback;
70 void on_read(udp::socket* sock, error_code const& e, std::size_t bytes_transferred);
71 void on_name_lookup(error_code const& e, tcp::resolver::iterator i);
72 void on_timeout();
73 void on_connect(int ticket);
74 void on_connected(error_code const& ec);
75 void handshake1(error_code const& e);
76 void handshake2(error_code const& e);
77 void handshake3(error_code const& e);
78 void handshake4(error_code const& e);
79 void socks_forward_udp();
80 void connect1(error_code const& e);
81 void connect2(error_code const& e);
83 void wrap(udp::endpoint const& ep, char const* p, int len, error_code& ec);
84 void unwrap(error_code const& e, char const* buf, int size);
86 udp::socket m_ipv4_sock;
87 udp::socket m_ipv6_sock;
88 udp::endpoint m_v4_ep;
89 udp::endpoint m_v6_ep;
90 char m_v4_buf[1600];
91 char m_v6_buf[1600];
92 int m_bind_port;
94 tcp::socket m_socks5_sock;
95 int m_connection_ticket;
96 proxy_settings m_proxy_settings;
97 connection_queue& m_cc;
98 tcp::resolver m_resolver;
99 char m_tmp_buf[100];
100 bool m_tunnel_packets;
101 udp::endpoint m_proxy_addr;
105 #endif