diff options
author | Gav Wood <i@gavwood.com> | 2014-01-22 22:40:45 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-01-22 22:40:45 +0800 |
commit | 3b9040b4a1696f7841d0b80621e3d0910f0364f8 (patch) | |
tree | 5936f0fcdcb8f6ff12ffff484ceccd5d510ef09c /peer.cpp | |
parent | 5afc641ea90b8ed49f99aa5d5fd40f1d6fb6e873 (diff) | |
download | dexon-solidity-3b9040b4a1696f7841d0b80621e3d0910f0364f8.tar.gz dexon-solidity-3b9040b4a1696f7841d0b80621e3d0910f0364f8.tar.zst dexon-solidity-3b9040b4a1696f7841d0b80621e3d0910f0364f8.zip |
Basic P2P functionality.
Diffstat (limited to 'peer.cpp')
-rw-r--r-- | peer.cpp | 79 |
1 files changed, 20 insertions, 59 deletions
@@ -27,72 +27,33 @@ using boost::asio::ip::tcp; int peerTest(int argc, char** argv) { - int port = 30303; - PeerServer s(0, port); - s.run(); - /* - 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]; + short listenPort = 30303; + string remoteHost; + short remotePort = 30303; - function<void()> do_read; - do_read = [&]() - { - s.async_read_some(boost::asio::buffer(data_, max_length), [&](boost::system::error_code ec, std::size_t length) - { - if (!ec) - boost::asio::async_write(s, boost::asio::buffer(data_, length), [&](boost::system::error_code ec, std::size_t) - { - if (!ec) - do_read(); - }); - }); - }; - } - do_accept(); - }); - }; - io_service.run(); - } - else + for (int i = 1; i < argc; ++i) { + string arg = argv[i]; + if (arg == "-l" && i + 1 < argc) + listenPort = atoi(argv[++i]); + else if (arg == "-r" && i + 1 < argc) + remoteHost = argv[++i]; + else if (arg == "-p" && i + 1 < argc) + remotePort = atoi(argv[++i]); + else + remoteHost = argv[i]; + } - }*/ - + PeerServer pn(0, listenPort); + if (!remoteHost.empty()) + pn.connect(remoteHost, remotePort); -/* if (argc == 1) + while (true) { - PeerNetwork pn(0, 30303); - while (true) - { - usleep(100000); - pn.process(); - } + 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; } |