1 /*
2 
3 Copyright (c) 2012-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 DHT_OBSERVER_HPP
34 #define DHT_OBSERVER_HPP
35 
36 #include "libtorrent/config.hpp"
37 #include "libtorrent/address.hpp"
38 #include "libtorrent/string_view.hpp"
39 #include "libtorrent/kademlia/msg.hpp"
40 #include "libtorrent/aux_/session_udp_sockets.hpp" // for transport
41 
42 namespace libtorrent {
43 
44 class entry;
45 
46 namespace aux { struct listen_socket_handle; }
47 
48 namespace dht {
49 
50 	struct TORRENT_EXTRA_EXPORT dht_logger
51 	{
52 #ifndef TORRENT_DISABLE_LOGGING
53 		enum module_t
54 		{
55 			tracker,
56 			node,
57 			routing_table,
58 			rpc_manager,
59 			traversal
60 		};
61 
62 		enum message_direction_t
63 		{
64 			incoming_message,
65 			outgoing_message
66 		};
67 
68 		virtual bool should_log(module_t m) const = 0;
69 		virtual void log(module_t m, char const* fmt, ...) TORRENT_FORMAT(3,4) = 0;
70 		virtual void log_packet(message_direction_t dir, span<char const> pkt
71 			, udp::endpoint const& node) = 0;
72 #endif
73 
74 	protected:
75 		~dht_logger() = default;
76 	};
77 
78 	struct TORRENT_EXTRA_EXPORT dht_observer : dht_logger
79 	{
80 		virtual void set_external_address(aux::listen_socket_handle const& iface
81 			, address const& addr, address const& source) = 0;
82 		virtual int get_listen_port(aux::transport ssl, aux::listen_socket_handle const& s) = 0;
83 		virtual void get_peers(sha1_hash const& ih) = 0;
84 		virtual void outgoing_get_peers(sha1_hash const& target
85 			, sha1_hash const& sent_target, udp::endpoint const& ep) = 0;
86 		virtual void announce(sha1_hash const& ih, address const& addr, int port) = 0;
87 		virtual bool on_dht_request(string_view query
88 			, dht::msg const& request, entry& response) = 0;
89 
90 	protected:
91 		~dht_observer() = default;
92 	};
93 }}
94 
95 #endif
96