Skip to content

Commit

Permalink
moved lsd.hpp to aux
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml authored and arvidn committed Jan 17, 2021
1 parent 8ef08d2 commit 985fc00
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 91 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ set(libtorrent_include_files
index_range
io_service
ip_filter
lsd
magnet_uri
mmap_disk_io
natpmp
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ HEADERS = \
io_context.hpp \
io_service.hpp \
ip_filter.hpp \
lsd.hpp \
magnet_uri.hpp \
mmap_disk_io.hpp \
natpmp.hpp \
Expand Down
78 changes: 65 additions & 13 deletions include/libtorrent/aux_/lsd.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright (c) 2007, 2009, 2012, 2014-2015, 2017, 2019-2020, Arvid Norberg
Copyright (c) 2016, Alden Torres
Copyright (c) 2017, 2019-2020, Arvid Norberg
All rights reserved.
You may use, distribute and modify this code under the terms of the BSD license,
Expand All @@ -12,21 +12,73 @@ see LICENSE file.
#define LIBTORRENT_LSD_HPP

#include "libtorrent/config.hpp"
#include "libtorrent/socket.hpp" // for tcp::endpoint
#include "libtorrent/socket.hpp"
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/aux_/deadline_timer.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/io_context.hpp"
#include "libtorrent/address.hpp"

namespace libtorrent::aux {

struct TORRENT_EXTRA_EXPORT lsd_callback
{
virtual void on_lsd_peer(tcp::endpoint const& peer, sha1_hash const& ih) = 0;
#ifndef TORRENT_DISABLE_LOGGING
virtual bool should_log_lsd() const = 0;
virtual void log_lsd(char const* msg) const = 0;
#endif

protected:
~lsd_callback() {}
};

struct lsd : std::enable_shared_from_this<lsd>
{
lsd(io_context& ios, lsd_callback& cb
, address listen_address, address netmask);
~lsd();

void start(error_code& ec);

void announce(sha1_hash const& ih, int listen_port);
void close();

private:

std::shared_ptr<lsd> self() { return shared_from_this(); }

void announce_impl(sha1_hash const& ih, int listen_port, int retry_count);
void resend_announce(error_code const& e, sha1_hash const& info_hash
, int listen_port, int retry_count);
void on_announce(error_code const& ec);

lsd_callback& m_callback;

address m_listen_address;
address m_netmask;

udp::socket m_socket;

namespace libtorrent { namespace aux {
struct TORRENT_EXTRA_EXPORT lsd_callback
{
virtual void on_lsd_peer(tcp::endpoint const& peer, sha1_hash const& ih) = 0;
#ifndef TORRENT_DISABLE_LOGGING
virtual bool should_log_lsd() const = 0;
virtual void log_lsd(char const* msg) const = 0;
bool should_log() const;
void debug_log(char const* fmt, ...) const TORRENT_FORMAT(2, 3);
#endif

protected:
~lsd_callback() {}
};
}}
// used to resend udp packets in case
// they time out
aux::deadline_timer m_broadcast_timer;

#endif // LIBTORRENT_LSD_HPP
// this is a random (presumably unique)
// ID for this LSD node. It is used to
// ignore our own broadcast messages.
// There's no point in adding ourselves
// as a peer
int m_cookie;

bool m_disabled = false;
};

}

#endif
72 changes: 0 additions & 72 deletions include/libtorrent/lsd.hpp

This file was deleted.

6 changes: 3 additions & 3 deletions src/lsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ see LICENSE file.
#include <functional>
#include <cstdio> // for vsnprintf

#include "libtorrent/lsd.hpp"
#include "libtorrent/aux_/lsd.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/aux_/random.hpp"
#include "libtorrent/aux_/http_parser.hpp"
Expand All @@ -30,7 +30,7 @@ see LICENSE file.

using namespace std::placeholders;

namespace libtorrent {
namespace libtorrent::aux {

namespace {

Expand Down Expand Up @@ -314,4 +314,4 @@ void lsd::close()
m_disabled = true;
}

} // libtorrent namespace
} // libtorrent::aux namespace
2 changes: 1 addition & 1 deletion src/session_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ see LICENSE file.
#include "libtorrent/aux_/enum_net.hpp"
#include "libtorrent/upnp.hpp"
#include "libtorrent/natpmp.hpp"
#include "libtorrent/lsd.hpp"
#include "libtorrent/aux_/lsd.hpp"
#include "libtorrent/aux_/instantiate_connection.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/aux_/random.hpp"
Expand Down

0 comments on commit 985fc00

Please sign in to comment.