/usr/share/doc/libbitcoin-dev/examples/connect.cpp is in libbitcoin-dev 2.0-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | /*
* Copyright (c) 2011-2013 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/>.
*/
/*
Connect to a Bitcoin node on localhost, port 8333.
*/
#include <bitcoin/bitcoin.hpp>
using namespace bc;
using std::placeholders::_1;
// Connection is established.
// Send version message to remote host.
void connect_started(const std::error_code& ec, channel_ptr node);
// Verson message finished sending.
// Program completed.
void version_sent(const std::error_code& ec, channel_ptr node);
void connect_started(const std::error_code& ec, channel_ptr node)
{
if (ec)
{
log_error() << "Connect: " << ec.message();
return;
}
// Create our version message we want to send.
// Fill in a bunch of fields.
version_type version;
version.version = 60000;
version.services = 1;
version.address_me.services = version.services;
version.address_me.ip =
ip_address_type{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x01};
version.address_me.port = 8333;
version.address_you.services = version.services;
version.address_you.ip =
ip_address_type{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x01};
version.address_you.port = 8333;
// Set the user agent.
version.user_agent = "/libbitcoin/connect-test/";
version.start_height = 0;
version.nonce = rand();
// Begin the send.
// Calls version_sent callback when complete.
node->send(version, std::bind(version_sent, _1, node));
}
void version_sent(const std::error_code& ec, channel_ptr node)
{
if (ec)
log_error() << "Sending version: " << ec.message();
else
log_info() << "Version sent.";
}
int main()
{
threadpool pool(1);
network net(pool);
net.connect("localhost", 8333, connect_started);
std::cin.get();
pool.stop();
pool.join();
return 0;
}
|