2010-10-10 04:22:57 +02:00
|
|
|
/*
|
|
|
|
|
2016-01-18 00:57:46 +01:00
|
|
|
Copyright (c) 2003-2016, Arvid Norberg
|
2010-10-10 04:22:57 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_PEER_ALLOCATOR_HPP_INCLUDED
|
|
|
|
#define TORRENT_PEER_ALLOCATOR_HPP_INCLUDED
|
2010-10-10 04:22:57 +02:00
|
|
|
|
|
|
|
#include "libtorrent/config.hpp"
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/torrent_peer.hpp"
|
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
2015-04-19 00:00:27 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#include <boost/pool/pool.hpp>
|
2010-10-10 04:22:57 +02:00
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
2015-04-19 00:00:27 +02:00
|
|
|
|
2017-04-12 19:00:57 +02:00
|
|
|
namespace libtorrent {
|
2010-10-10 04:22:57 +02:00
|
|
|
|
2015-11-19 01:51:17 +01:00
|
|
|
struct TORRENT_EXTRA_EXPORT torrent_peer_allocator_interface
|
2013-11-29 06:29:39 +01:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
enum peer_type_t
|
|
|
|
{
|
|
|
|
ipv4_peer_type,
|
|
|
|
ipv6_peer_type,
|
|
|
|
i2p_peer_type
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual torrent_peer* allocate_peer_entry(int type) = 0;
|
|
|
|
virtual void free_peer_entry(torrent_peer* p) = 0;
|
2015-04-19 08:28:21 +02:00
|
|
|
protected:
|
|
|
|
~torrent_peer_allocator_interface() {}
|
2013-11-29 06:29:39 +01:00
|
|
|
};
|
2010-10-10 04:22:57 +02:00
|
|
|
|
2016-04-30 17:05:54 +02:00
|
|
|
struct TORRENT_EXTRA_EXPORT torrent_peer_allocator final
|
2015-04-19 08:28:21 +02:00
|
|
|
: torrent_peer_allocator_interface
|
2010-10-10 04:22:57 +02:00
|
|
|
{
|
2017-11-08 11:44:56 +01:00
|
|
|
#if TORRENT_USE_ASSERTS
|
|
|
|
~torrent_peer_allocator() {
|
|
|
|
m_in_use = false;
|
|
|
|
}
|
|
|
|
#endif
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
torrent_peer* allocate_peer_entry(int type) override;
|
|
|
|
void free_peer_entry(torrent_peer* p) override;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint64_t total_bytes() const { return m_total_bytes; }
|
|
|
|
std::uint64_t total_allocations() const { return m_total_allocations; }
|
2014-07-06 21:18:00 +02:00
|
|
|
int live_bytes() const { return m_live_bytes; }
|
|
|
|
int live_allocations() const { return m_live_allocations; }
|
2010-10-10 04:22:57 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
private:
|
2016-10-22 17:47:24 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// this is a shared pool where torrent_peer objects
|
|
|
|
// are allocated. It's a pool since we're likely
|
|
|
|
// to have tens of thousands of peers, and a pool
|
|
|
|
// saves significant overhead
|
|
|
|
|
2017-11-08 11:44:56 +01:00
|
|
|
boost::pool<> m_ipv4_peer_pool{sizeof(libtorrent::ipv4_peer), 500};
|
2014-07-06 21:18:00 +02:00
|
|
|
#if TORRENT_USE_IPV6
|
2017-11-08 11:44:56 +01:00
|
|
|
boost::pool<> m_ipv6_peer_pool{sizeof(libtorrent::ipv6_peer), 500};
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
|
|
|
#if TORRENT_USE_I2P
|
2017-11-08 11:44:56 +01:00
|
|
|
boost::pool<> m_i2p_peer_pool{sizeof(libtorrent::i2p_peer), 500};
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// the total number of bytes allocated (cumulative)
|
2017-11-08 11:44:56 +01:00
|
|
|
std::uint64_t m_total_bytes = 0;
|
2014-07-06 21:18:00 +02:00
|
|
|
// the total number of allocations (cumulative)
|
2017-11-08 11:44:56 +01:00
|
|
|
std::uint64_t m_total_allocations = 0;
|
2014-07-06 21:18:00 +02:00
|
|
|
// the number of currently live bytes
|
2017-11-08 11:44:56 +01:00
|
|
|
int m_live_bytes = 0;
|
2014-07-06 21:18:00 +02:00
|
|
|
// the number of currently live allocations
|
2017-11-08 11:44:56 +01:00
|
|
|
int m_live_allocations = 0;
|
|
|
|
#if TORRENT_USE_ASSERTS
|
|
|
|
bool m_in_use = true;
|
|
|
|
#endif
|
2014-07-06 21:18:00 +02:00
|
|
|
};
|
2010-10-10 04:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|