<commit_before>/**
 * Copyright (c) 2011-2015 libbitcoin developers (see AUTHORS)
 *
 * This file is part of libbitcoin.
 *
 * libbitcoin is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License with
 * additional permissions to the one published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * any later version. For more information see LICENSE.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <bitcoin/bitcoin/network/proxy.hpp>

#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <memory>
#include <boost/date_time.hpp>
#include <boost/format.hpp>
#include <boost/iostreams/stream.hpp>
#include <bitcoin/bitcoin/config/authority.hpp>
#include <bitcoin/bitcoin/error.hpp>
#include <bitcoin/bitcoin/math/checksum.hpp>
#include <bitcoin/bitcoin/messages.hpp>
#include <bitcoin/bitcoin/network/asio.hpp>
#include <bitcoin/bitcoin/network/loader.hpp>
#include <bitcoin/bitcoin/network/shared_const_buffer.hpp>
#include <bitcoin/bitcoin/network/timeout.hpp>
#include <bitcoin/bitcoin/utility/assert.hpp>
#include <bitcoin/bitcoin/utility/container_source.hpp>
#include <bitcoin/bitcoin/utility/data.hpp>
#include <bitcoin/bitcoin/utility/deadline.hpp>
#include <bitcoin/bitcoin/utility/endian.hpp>
#include <bitcoin/bitcoin/utility/logger.hpp>
#include <bitcoin/bitcoin/utility/random.hpp>
#include <bitcoin/bitcoin/utility/dispatcher.hpp>
#include <bitcoin/bitcoin/utility/serializer.hpp>
#include <bitcoin/bitcoin/utility/string.hpp>

// These must be declared in the global namespace.
INITIALIZE_PROXY_MESSAGE_SUBSCRIBER_TRACKS()
INITIALIZE_TRACK(bc::network::proxy)

namespace libbitcoin {
namespace network {

using namespace chain;
using namespace message;
using std::placeholders::_1;
using std::placeholders::_2;
using boost::format;
using boost::posix_time::time_duration;

// The proxy will have no config with timers moved to channel.
proxy::proxy(asio::socket_ptr socket, threadpool& pool,
    const timeout& timeouts)
  : socket_(socket),
    dispatch_(pool),
    timeouts_(timeouts),
    expiration_(std::make_shared<deadline>(pool, timeouts.expiration)),
    inactivity_(std::make_shared<deadline>(pool, timeouts.inactivity)),
    revival_(std::make_shared<deadline>(pool, timeouts.revival)),
    revival_handler_(nullptr),
    stopped_(false),
    INITIALIZE_PROXY_MESSAGE_SUBSCRIBERS(),
    CONSTRUCT_TRACK(proxy, LOG_NETWORK)
{
    ESTABLISH_PROXY_MESSAGE_RELAYS();
}

// This implements the set of proxy messsage handler methods.
DEFINE_PROXY_MESSAGE_SUBSCRIBERS()

proxy::~proxy()
{
    BITCOIN_ASSERT_MSG(stopped_, "The channel is not stopped.");
}

template<typename Message, class Subscriber>
void proxy::establish_relay(Subscriber subscriber)
{
    const auto handler = [subscriber](const code& ec, const Message& message)
    {
        subscriber->relay(ec, message);<commit_msg>Restore lost raw/stop subscriber initializations.<commit_after>/**
 * Copyright (c) 2011-2015 libbitcoin developers (see AUTHORS)
 *
 * This file is part of libbitcoin.
 *
 * libbitcoin is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License with
 * additional permissions to the one published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * any later version. For more information see LICENSE.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <bitcoin/bitcoin/network/proxy.hpp>

#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <memory>
#include <boost/date_time.hpp>
#include <boost/format.hpp>
#include <boost/iostreams/stream.hpp>
#include <bitcoin/bitcoin/config/authority.hpp>
#include <bitcoin/bitcoin/error.hpp>
#include <bitcoin/bitcoin/math/checksum.hpp>
#include <bitcoin/bitcoin/messages.hpp>
#include <bitcoin/bitcoin/network/asio.hpp>
#include <bitcoin/bitcoin/network/loader.hpp>
#include <bitcoin/bitcoin/network/shared_const_buffer.hpp>
#include <bitcoin/bitcoin/network/timeout.hpp>
#include <bitcoin/bitcoin/utility/assert.hpp>
#include <bitcoin/bitcoin/utility/container_source.hpp>
#include <bitcoin/bitcoin/utility/data.hpp>
#include <bitcoin/bitcoin/utility/deadline.hpp>
#include <bitcoin/bitcoin/utility/endian.hpp>
#include <bitcoin/bitcoin/utility/logger.hpp>
#include <bitcoin/bitcoin/utility/random.hpp>
#include <bitcoin/bitcoin/utility/dispatcher.hpp>
#include <bitcoin/bitcoin/utility/serializer.hpp>
#include <bitcoin/bitcoin/utility/string.hpp>

// These must be declared in the global namespace.
INITIALIZE_PROXY_MESSAGE_SUBSCRIBER_TRACKS()
INITIALIZE_TRACK(bc::network::proxy::stop_subscriber)
INITIALIZE_TRACK(bc::network::proxy::raw_subscriber)
INITIALIZE_TRACK(bc::network::proxy)

namespace libbitcoin {
namespace network {

using namespace chain;
using namespace message;
using std::placeholders::_1;
using std::placeholders::_2;
using boost::format;
using boost::posix_time::time_duration;

// The proxy will have no config with timers moved to channel.
proxy::proxy(asio::socket_ptr socket, threadpool& pool,
    const timeout& timeouts)
  : socket_(socket),
    dispatch_(pool),
    timeouts_(timeouts),
    expiration_(std::make_shared<deadline>(pool, timeouts.expiration)),
    inactivity_(std::make_shared<deadline>(pool, timeouts.inactivity)),
    revival_(std::make_shared<deadline>(pool, timeouts.revival)),
    revival_handler_(nullptr),
    stopped_(false),
    INITIALIZE_PROXY_MESSAGE_SUBSCRIBERS(),
    stop_subscriber_(MAKE_SUBSCRIBER(stop, pool, LOG_NETWORK)),
    raw_subscriber_(MAKE_SUBSCRIBER(raw, pool, LOG_NETWORK)),
    CONSTRUCT_TRACK(proxy, LOG_NETWORK)
{
    ESTABLISH_PROXY_MESSAGE_RELAYS();
}

// This implements the set of proxy messsage handler methods.
DEFINE_PROXY_MESSAGE_SUBSCRIBERS()

proxy::~proxy()
{
    BITCOIN_ASSERT_MSG(stopped_, "The channel is not stopped.");
}

template<typename Message, class Subscriber>
void proxy::establish_relay(Subscriber subscriber)
{
    const auto handler = [subscriber](const code& ec, const Message& message)
    {
        subscriber->relay(ec, message);
{'fraction_non_alphanumeric': 0.11038678835289005, 'fraction_numerical': 0.0031870201361726786, 'mean_word_length': 5.619367209971236, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7210263', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2166, 'n_words': 561}