/* Copyright (c) 2015, Arvid Norberg, Steven Siloti All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/peer_connection_handle.hpp" #include "libtorrent/peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp" #ifndef TORRENT_DISABLE_LOGGING #include // for va_start, va_end #endif namespace libtorrent { int peer_connection_handle::type() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->type(); } void peer_connection_handle::add_extension(boost::shared_ptr ext) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->add_extension(ext); } peer_plugin const* peer_connection_handle::find_plugin(char const* type) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->find_plugin(type); } bool peer_connection_handle::no_download() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->no_download(); } bool peer_connection_handle::ignore_stats() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->ignore_stats(); } boost::uint32_t peer_connection_handle::peer_rank() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->peer_rank(); } bool peer_connection_handle::can_write() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->can_write(); } bool peer_connection_handle::is_seed() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->is_seed(); } bool peer_connection_handle::share_mode() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->share_mode(); } void peer_connection_handle::set_upload_only(bool u) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->set_upload_only(u); } bool peer_connection_handle::has_piece(int i) const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->has_piece(i); } bool peer_connection_handle::is_interesting() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->is_interesting(); } bool peer_connection_handle::is_choked() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->is_choked(); } bool peer_connection_handle::is_peer_interested() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->is_peer_interested(); } bool peer_connection_handle::has_peer_choked() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->has_peer_choked(); } void peer_connection_handle::choke_this_peer() { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->choke_this_peer(); } void peer_connection_handle::maybe_unchoke_this_peer() { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->maybe_unchoke_this_peer(); } void peer_connection_handle::get_peer_info(peer_info& p) const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->get_peer_info(p); } torrent_handle peer_connection_handle::associated_torrent() const { boost::shared_ptr pc = native_handle(); if (!pc) return torrent_handle(); boost::shared_ptr t = pc->associated_torrent().lock(); if (!t) return torrent_handle(); return t->get_handle(); } tcp::endpoint const& peer_connection_handle::remote() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->remote(); } tcp::endpoint peer_connection_handle::local_endpoint() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->local_endpoint(); } void peer_connection_handle::disconnect(error_code const& ec, operation_t op, int error) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->disconnect(ec, op, error); } bool peer_connection_handle::is_disconnecting() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->is_disconnecting(); } bool peer_connection_handle::is_connecting() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->is_connecting(); } bool peer_connection_handle::is_outgoing() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->is_outgoing(); } bool peer_connection_handle::received_listen_port() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->received_listen_port(); } bool peer_connection_handle::on_local_network() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->on_local_network(); } bool peer_connection_handle::ignore_unchoke_slots() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->ignore_unchoke_slots(); } bool peer_connection_handle::failed() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->failed(); } bool peer_connection_handle::disconnect_if_redundant() { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->disconnect_if_redundant(); } #ifndef TORRENT_DISABLE_LOGGING void peer_connection_handle::peer_log(peer_log_alert::direction_t direction , char const* event, char const* fmt, ...) const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); va_list v; va_start(v, fmt); pc->peer_log(direction, event, fmt, v); va_end(v); } #endif bool peer_connection_handle::can_disconnect(error_code const& ec) const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->can_disconnect(ec); } bool peer_connection_handle::has_metadata() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->has_metadata(); } bool peer_connection_handle::send_choke() { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->send_choke(); } bool peer_connection_handle::send_unchoke() { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->send_unchoke(); } void peer_connection_handle::send_interested() { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->send_interested(); } void peer_connection_handle::send_suggest(int piece) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->send_suggest(piece); } bool peer_connection_handle::in_handshake() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->in_handshake(); } void peer_connection_handle::send_buffer(char const* begin, int size, int flags) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->send_buffer(begin, size, flags); } time_t peer_connection_handle::last_seen_complete() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->last_seen_complete(); } time_point peer_connection_handle::time_of_last_unchoke() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->time_of_last_unchoke(); } bool bt_peer_connection_handle::packet_finished() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->packet_finished(); } bool bt_peer_connection_handle::support_extensions() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->support_extensions(); } boost::shared_ptr bt_peer_connection_handle::native_handle() const { return boost::static_pointer_cast( peer_connection_handle::native_handle()); } bool bt_peer_connection_handle::supports_encryption() const { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->supports_encryption(); } void bt_peer_connection_handle::switch_send_crypto(boost::shared_ptr crypto) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->switch_send_crypto(crypto); } void bt_peer_connection_handle::switch_recv_crypto(boost::shared_ptr crypto) { boost::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->switch_recv_crypto(crypto); } } // namespace libtorrent