mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Basic P2P functionality.
This commit is contained in:
parent
5afc641ea9
commit
3b9040b4a1
85
peer.cpp
85
peer.cpp
@ -27,72 +27,33 @@ using boost::asio::ip::tcp;
|
|||||||
|
|
||||||
int peerTest(int argc, char** argv)
|
int peerTest(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int port = 30303;
|
short listenPort = 30303;
|
||||||
PeerServer s(0, port);
|
string remoteHost;
|
||||||
s.run();
|
short remotePort = 30303;
|
||||||
/*
|
|
||||||
if (argc == 1)
|
|
||||||
{
|
|
||||||
boost::asio::io_service io_service;
|
|
||||||
tcp::acceptor acceptor_(io_service, tcp::endpoint(tcp::v4(), port));
|
|
||||||
tcp::socket socket_(io_service);
|
|
||||||
function<void()> do_accept;
|
|
||||||
do_accept = [&]()
|
|
||||||
{
|
|
||||||
acceptor_.async_accept(socket_, [&](boost::system::error_code ec)
|
|
||||||
{
|
|
||||||
if (!ec)
|
|
||||||
{
|
|
||||||
auto s = move(socket_);
|
|
||||||
enum { max_length = 1024 };
|
|
||||||
char data_[max_length];
|
|
||||||
|
|
||||||
function<void()> do_read;
|
for (int i = 1; i < argc; ++i)
|
||||||
do_read = [&]()
|
{
|
||||||
{
|
string arg = argv[i];
|
||||||
s.async_read_some(boost::asio::buffer(data_, max_length), [&](boost::system::error_code ec, std::size_t length)
|
if (arg == "-l" && i + 1 < argc)
|
||||||
{
|
listenPort = atoi(argv[++i]);
|
||||||
if (!ec)
|
else if (arg == "-r" && i + 1 < argc)
|
||||||
boost::asio::async_write(s, boost::asio::buffer(data_, length), [&](boost::system::error_code ec, std::size_t)
|
remoteHost = argv[++i];
|
||||||
{
|
else if (arg == "-p" && i + 1 < argc)
|
||||||
if (!ec)
|
remotePort = atoi(argv[++i]);
|
||||||
do_read();
|
else
|
||||||
});
|
remoteHost = argv[i];
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
do_accept();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
io_service.run();
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
PeerServer pn(0, listenPort);
|
||||||
|
|
||||||
|
if (!remoteHost.empty())
|
||||||
|
pn.connect(remoteHost, remotePort);
|
||||||
|
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
|
usleep(100000);
|
||||||
}*/
|
pn.process();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* if (argc == 1)
|
|
||||||
{
|
|
||||||
PeerNetwork pn(0, 30303);
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
usleep(100000);
|
|
||||||
pn.process();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
PeerNetwork pn(0);
|
|
||||||
if (pn.connect("127.0.0.1", 30303))
|
|
||||||
cout << "CONNECTED" << endl;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
usleep(100000);
|
|
||||||
pn.process();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user