3 Copyright (c) 2007, Arvid Norberg
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
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"
40 #include <boost/function.hpp>
44 class connection_queue
;
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
);
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
; }
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
);
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
;
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
;
100 bool m_tunnel_packets
;
101 udp::endpoint m_proxy_addr
;