Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing eth/main.cpp and rip.cpp and peer.cpp
  • Loading branch information
demon1999 committed Oct 10, 2017
commit af0d89af1bc0631cf34e3aa050c0c12a6cda4b2e
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ endif()
# TODO: Split out json_spirit, libscrypt and sec256k1.
add_subdirectory(utils)

add_executable(main ethvm/main.cpp)
add_executable(main rlp/main.cpp)

add_executable(peer test/unittests/libp2p/peer.cpp)
2 changes: 2 additions & 0 deletions eth/AccountManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <libdevcore/FileSystem.h>
#include <libdevcore/CommonIO.h>
#include <libethcore/KeyManager.h>
#include <boost/program_options.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these includes needed? Only includes are added to this file and nothing else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, I don't need it.

#include <boost/program_options/options_description.hpp>
#include "AccountManager.h"
using namespace std;
using namespace dev;
Expand Down
6 changes: 3 additions & 3 deletions eth/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ int main(int argc, char** argv)
;
po::options_description allowedOptions("Allowed options");
allowedOptions.add(clientDefaultMode).add(clientTransacting).add(clientMining).add(clientNetworking).add(importExportMode).add(generalOptions);
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, allowedOptions), vm);
po::notify(vm);
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
Expand Down Expand Up @@ -897,6 +894,9 @@ int main(int argc, char** argv)
exit(-1);
}
}
//po::variables_map vm;
//po::store(po::parse_command_line(argc, argv, allowedOptions), vm);
//po::notify(vm);

if (!configJSON.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion rlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_executable(rlp main.cpp)
target_include_directories(rlp PRIVATE ../utils)
target_link_libraries(rlp PRIVATE devcrypto devcore)
target_link_libraries(rlp PRIVATE devcrypto devcore Boost::program_options)
185 changes: 115 additions & 70 deletions rlp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
#include <json_spirit/JsonSpiritHeaders.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/RLP.h>
Expand All @@ -34,39 +36,7 @@
using namespace std;
using namespace dev;
namespace js = json_spirit;

void help()
{
cout
<< "Usage rlp <mode> [OPTIONS]" << endl
<< "Modes:" << endl
<< " create <json> Given a simplified JSON string, output the RLP." << endl
<< " render [ <file> | -- ] Render the given RLP. Options:" << endl
<< " --indent <string> Use string as the level indentation (default ' ')." << endl
<< " --hex-ints Render integers in hex." << endl
<< " --string-ints Render integers in the same way as strings." << endl
<< " --ascii-strings Render data as C-style strings or hex depending on content being ASCII." << endl
<< " --force-string Force all data to be rendered as C-style strings." << endl
<< " --force-escape When rendering as C-style strings, force all characters to be escaped." << endl
<< " --force-hex Force all data to be rendered as raw hex." << endl
<< " list [ <file> | -- ] List the items in the RLP list by hash and size." << endl
<< " extract [ <file> | -- ] Extract all items in the RLP list, named by hash." << endl
<< " assemble [ <manifest> | <base path> ] <file> ... Given a manifest & files, output the RLP." << endl
<< " -D,--dapp Dapp-building mode; equivalent to --encrypt --64." << endl
<< endl
<< "General options:" << endl
<< " -e,--encrypt Encrypt the RLP data prior to output." << endl
<< " -L,--lenience Try not to bomb out early if possible." << endl
<< " -x,--hex,--base-16 Treat input RLP as hex encoded data." << endl
<< " -k,--keccak Output Keccak-256 hash only." << endl
<< " --64,--base-64 Treat input RLP as base-64 encoded data." << endl
<< " -b,--bin,--base-256 Treat input RLP as raw binary data." << endl
<< " -q,--quiet Don't place additional information on stderr." << endl
<< " -h,--help Print this help message and exit." << endl
<< " -V,--version Show the version and exit." << endl
;
exit(0);
}
namespace po = boost::program_options;

void version()
{
Expand Down Expand Up @@ -215,61 +185,136 @@ int main(int argc, char** argv)
bool quiet = false;
bool encrypt = false;
RLPStreamer::Prefs prefs;

po::options_description modesOptions("Modes");
modesOptions.add_options()
("indent,i", po::value<string> (), "<string> Use string as the level indentation (default ' ').")
("hex-ints", "Render integers in hex.")
("string-ints", "Render integers in the same way as strings.")
("ascii-strings", "Render data as C-style strings or hex depending on content being ASCII.")
("force-string", "Force all data to be rendered as C-style strings.")
("force-escape", "When rendering as C-style strings, force all characters to be escaped.")
("force-hex", "Force all data to be rendered as raw hex.")
("dapp,D", "Dapp-building mode; equivalent to --encrypt --64.")
;
po::options_description generalOptions("General options");
generalOptions.add_options()
("encrypt,e", "Encrypt the RLP data prior to output.")
("lenience,L", "Try not to bomb out early if possible.")
("hex,x", "Treat input RLP as hex encoded data.")
("base-16", "Treat input RLP as hex encoded data.")
("keccak,k", "Output Keccak-256 hash only.")
("base-64", "Treat input RLP as base-64 encoded data.")
("64", "Treat input RLP as base-64 encoded data.")
("bin,b", "Treat input RLP as raw binary data.")
("base-256", "Treat input RLP as raw binary data.")
("quiet,q", "Don't place additional information on stderr.")
("help,h", "Print this help message and exit.")
("version,V", "Show the version and exit.")
;
po::options_description allowedOptions("Allowed options");
allowedOptions.add(generalOptions).add(modesOptions);
int ac = 1;
for (int i = 1; i < argc; ++i)
{

string arg = argv[i];
if (arg == "-h" || arg == "--help")
help();
if ((arg == "-i" || arg == "--indent") && i + 1 < argc) {
argv[ac] = argv[i];
ac++;
i++;
argv[ac] = argv[i];
ac++;
continue;
}
else if (arg == "-h" || arg == "--help" || arg == "--hex-ints" || arg == "--ascii-strings" || arg == "-L" || arg == "--lenience" ||
arg == "--force-string" || arg == "--force-hex" || arg == "--force-escape" || arg == "-n" || arg == "--nice" ||
arg == "-D" || arg == "--dapp" || arg == "-V" || arg == "--version" || arg == "-q" || arg == "--quiet" || arg == "-x" ||
arg == "--hex" || arg == "--base-16" || arg == "-k" || arg == "--keccak" || arg == "--64" || arg == "--base-64" ||
arg == "-b" || arg == "--bin" || arg == "--base-256" || arg == "-e" || arg == "--encrypt") {
argv[ac] = argv[i];
ac++;
continue;
}
else if (arg == "render")
mode = Mode::Render;
else if (arg == "create")
mode = Mode::Create;
else if ((arg == "-i" || arg == "--indent") && i + 1 < argc)
prefs.indent = argv[++i];
else if (arg == "--hex-ints")
prefs.hexInts = true;
else if (arg == "--string-ints")
prefs.stringInts = true;
else if (arg == "--ascii-strings")
prefs.forceString = prefs.forceHex = false;
else if (arg == "--force-string")
prefs.forceString = true;
else if (arg == "--force-hex")
prefs.forceHex = true, prefs.forceString = false;
else if (arg == "--force-escape")
prefs.escapeAll = true;
else if (arg == "-n" || arg == "--nice")
prefs.forceString = true, prefs.stringInts = false, prefs.forceHex = false, prefs.indent = " ";
else if (arg == "list")
mode = Mode::ListArchive;
else if (arg == "extract")
mode = Mode::ExtractArchive;
else if (arg == "assemble")
mode = Mode::AssembleArchive;
else if (arg == "-L" || arg == "--lenience")
lenience = true;
else if (arg == "-D" || arg == "--dapp")
encrypt = true, encoding = Encoding::Base64;
else if (arg == "-V" || arg == "--version")
version();
else if (arg == "-q" || arg == "--quiet")
quiet = true;
else if (arg == "-x" || arg == "--hex" || arg == "--base-16")
encoding = Encoding::Hex;
else if (arg == "-k" || arg == "--keccak")
encoding = Encoding::Keccak;
else if (arg == "--64" || arg == "--base-64")
encoding = Encoding::Base64;
else if (arg == "-b" || arg == "--bin" || arg == "--base-256")
encoding = Encoding::Binary;
else if (arg == "-e" || arg == "--encrypt")
encrypt = true;
else if (inputFile.empty())
inputFile = arg;
else
otherInputs.push_back(arg);
}
po::variables_map vm;
po::store(po::parse_command_line(ac, argv, allowedOptions), vm);
po::notify(vm);
if (vm.count("help")) {
cout << "Usage rlp <mode> [OPTIONS]" << endl << modesOptions
<< " create <json> Given a simplified JSON string, output the RLP." << endl
<< " render [ <file> | -- ] Render the given RLP. Options:" << endl
<< " list [ <file> | -- ] List the items in the RLP list by hash and size." << endl
<< " extract [ <file> | -- ] Extract all items in the RLP list, named by hash." << endl
<< " assemble [ <manifest> | <base path> ] <file> ... Given a manifest & files, output the RLP." << endl
<< generalOptions;
exit(0);
}
if (vm.count("lenience"))
lenience = true;
if (vm.count("dapp"))
encrypt = true, encoding = Encoding::Base64;
if (vm.count("version"))
version();
if (vm.count("quiet"))
quiet = true;
if (vm.count("hex") || vm.count("base-16"))
encoding = Encoding::Hex;
if (vm.count("keccak"))
encoding = Encoding::Keccak;
if (vm.count("64") || vm.count("base-64"))
encoding = Encoding::Base64;
if (vm.count("bin") || vm.count("base-256"))
encoding = Encoding::Binary;
if (vm.count("encrypt"))
encrypt = true;
if (vm.count("indent"))
prefs.indent = vm["indent"].as<string>();
if (vm.count("hex-ints"))
prefs.hexInts = true;
if (vm.count("string-ints"))
prefs.stringInts = true;
if (vm.count("ascii-strings"))
prefs.forceString = prefs.forceHex = false;
if (vm.count("force-string"))
prefs.forceString = true;
if (vm.count("force-hex"))
prefs.forceHex = true, prefs.forceString = false;
if (vm.count("force-escape"))
prefs.escapeAll = true;
if (vm.count("nice"))
prefs.forceString = true, prefs.stringInts = false, prefs.forceHex = false, prefs.indent = " ";
if (vm.count("lenience"))
lenience = true;
if (vm.count("dapp"))
encrypt = true, encoding = Encoding::Base64;
if (vm.count("version"))
version();
if (vm.count("quiet"))
quiet = true;
if (vm.count("hex") || vm.count("base-16"))
encoding = Encoding::Hex;
if (vm.count("keccak"))
encoding = Encoding::Keccak;
if (vm.count("64") || vm.count("base-64"))
encoding = Encoding::Base64;
if (vm.count("bin") || vm.count("base-256"))
encoding = Encoding::Binary;
if (vm.count("encrypt"))
encrypt = true;

bytes in;
if (inputFile == "--")
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ endforeach(file)

add_executable(testeth ${sources})
target_include_directories(testeth PRIVATE ../utils)
target_link_libraries(testeth PRIVATE ethereum ethashseal web3jsonrpc devcrypto devcore Cryptopp)
target_link_libraries(testeth PRIVATE ethereum ethashseal web3jsonrpc devcrypto devcore Cryptopp Boost::program_options)

enable_testing()
set(CTEST_OUTPUT_ON_FAILURE TRUE)
Expand Down
43 changes: 33 additions & 10 deletions test/unittests/libp2p/peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
#include <chrono>
#include <thread>
#include <boost/test/unit_test.hpp>
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>

using namespace std;
using namespace dev;
using namespace dev::test;
using namespace dev::p2p;
namespace po = boost::program_options;

struct P2PPeerFixture: public TestOutputHelper
{
Expand Down Expand Up @@ -328,22 +331,42 @@ int peerTest(int argc, char** argv)
short listenPort = 30304;
string remoteHost;
short remotePort = 30304;

po::options_description generalOptions("General options");
generalOptions.add_options()
("listenPort,l", po::value<short>(), " set number of listenPort")
("remoteHost,r", po::value<string>(), " set string to remoteHost")
("remotePort,p", po::value<short>(), " set number to remotePort")
("remoteAlias,ra", po::value<string>(), " set remoteAlias");
;
int ac = 1;
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if (arg == "-l" && i + 1 < argc)
listenPort = (short)atoi(argv[++i]);
else if (arg == "-r" && i + 1 < argc)
remoteHost = argv[++i];
else if (arg == "-p" && i + 1 < argc)
remotePort = (short)atoi(argv[++i]);
else if (arg == "-ra" && i + 1 < argc)
remoteAlias = Public(dev::fromHex(argv[++i]));
if ((arg == "-l" || arg == "-r" || arg == "-p" || arg == "-ra") && i + 1 < argc) {
argv[ac] = argv[i];
ac++;
i++;
argv[ac] = argv[i];
ac++;
}
else
remoteHost = argv[i];
}

po::variables_map vm;
po::store(po::parse_command_line(ac, argv, generalOptions), vm);
po::notify(vm);
if (vm.count("listenPort")) {
listenPort = vm["listenPort"].as<short>();
}
if (vm.count("remoteHost")) {
remoteHost = vm["remoteHost"].as<string>();
}
if (vm.count("remotePort")) {
remotePort = vm["remotePort"].as<short>();
}
if (vm.count("remoteAlias")) {
remoteAlias = Public(dev::fromHex(vm["remoteAlias"].as<string>()));
}
Host ph("Test", NetworkPreferences(listenPort));

if (!remoteHost.empty() && !remoteAlias)
Expand Down