14 changed files with 2 additions and 532 deletions
@ -1,146 +0,0 @@ |
|||
/*
|
|||
base64.cpp and base64.h |
|||
|
|||
Copyright (C) 2004-2008 René Nyffenegger |
|||
|
|||
This source code is provided 'as-is', without any express or implied |
|||
warranty. In no event will the author be held liable for any damages |
|||
arising from the use of this software. |
|||
|
|||
Permission is granted to anyone to use this software for any purpose, |
|||
including commercial applications, and to alter it and redistribute it |
|||
freely, subject to the following restrictions: |
|||
|
|||
1. The origin of this source code must not be misrepresented; you must not |
|||
claim that you wrote the original source code. If you use this source code |
|||
in a product, an acknowledgment in the product documentation would be |
|||
appreciated but is not required. |
|||
|
|||
2. Altered source versions must be plainly marked as such, and must not be |
|||
misrepresented as being the original source code. |
|||
|
|||
3. This notice may not be removed or altered from any source distribution. |
|||
|
|||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch |
|||
*/ |
|||
/// Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
|
|||
/// Originally by René Nyffenegger, modified by some other guy and then devified by Gav Wood.
|
|||
|
|||
#include "Base64.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
static inline bool is_base64(byte c) |
|||
{ |
|||
return (isalnum(c) || (c == '+') || (c == '/')); |
|||
} |
|||
|
|||
static inline byte find_base64_char_index(byte c) |
|||
{ |
|||
if ('A' <= c && c <= 'Z') return c - 'A'; |
|||
else if ('a' <= c && c <= 'z') return c - 'a' + 1 + find_base64_char_index('Z'); |
|||
else if ('0' <= c && c <= '9') return c - '0' + 1 + find_base64_char_index('z'); |
|||
else if (c == '+') return 1 + find_base64_char_index('9'); |
|||
else if (c == '/') return 1 + find_base64_char_index('+'); |
|||
else return 1 + find_base64_char_index('/'); |
|||
} |
|||
|
|||
string dev::toBase64(bytesConstRef _in) |
|||
{ |
|||
static const char base64_chars[] = |
|||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|||
"abcdefghijklmnopqrstuvwxyz" |
|||
"0123456789+/"; |
|||
|
|||
string ret; |
|||
int i = 0; |
|||
int j = 0; |
|||
byte char_array_3[3]; |
|||
byte char_array_4[4]; |
|||
|
|||
auto buf = _in.data(); |
|||
auto bufLen = _in.size(); |
|||
|
|||
while (bufLen--) |
|||
{ |
|||
char_array_3[i++] = *(buf++); |
|||
if (i == 3) |
|||
{ |
|||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; |
|||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); |
|||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); |
|||
char_array_4[3] = char_array_3[2] & 0x3f; |
|||
|
|||
for (i = 0; i < 4; i++) |
|||
ret += base64_chars[char_array_4[i]]; |
|||
i = 0; |
|||
} |
|||
} |
|||
|
|||
if (i) |
|||
{ |
|||
for (j = i; j < 3; j++) |
|||
char_array_3[j] = '\0'; |
|||
|
|||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; |
|||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); |
|||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); |
|||
char_array_4[3] = char_array_3[2] & 0x3f; |
|||
|
|||
for (j = 0; j < i + 1; j++) |
|||
ret += base64_chars[char_array_4[j]]; |
|||
|
|||
while (i++ < 3) |
|||
ret += '='; |
|||
} |
|||
|
|||
return ret; |
|||
} |
|||
|
|||
bytes dev::fromBase64(string const& encoded_string) |
|||
{ |
|||
auto in_len = encoded_string.size(); |
|||
int i = 0; |
|||
int j = 0; |
|||
int in_ = 0; |
|||
byte char_array_3[3]; |
|||
byte char_array_4[4]; |
|||
bytes ret; |
|||
|
|||
while (in_len-- && encoded_string[in_] != '=' && is_base64(encoded_string[in_])) |
|||
{ |
|||
char_array_4[i++] = encoded_string[in_]; in_++; |
|||
if (i == 4) |
|||
{ |
|||
for (i = 0; i < 4; i++) |
|||
char_array_4[i] = find_base64_char_index(char_array_4[i]); |
|||
|
|||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); |
|||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); |
|||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; |
|||
|
|||
for (i = 0; (i < 3); i++) |
|||
ret.push_back(char_array_3[i]); |
|||
i = 0; |
|||
} |
|||
} |
|||
|
|||
if (i) |
|||
{ |
|||
for (j = i; j < 4; j++) |
|||
char_array_4[j] = 0; |
|||
|
|||
for (j = 0; j < 4; j++) |
|||
char_array_4[j] = find_base64_char_index(char_array_4[j]); |
|||
|
|||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); |
|||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); |
|||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; |
|||
|
|||
for (j = 0; j < i - 1; j++) |
|||
ret.push_back(char_array_3[j]); |
|||
} |
|||
|
|||
return ret; |
|||
} |
@ -1,73 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file FileSystem.cpp
|
|||
* @authors |
|||
* Eric Lombrozo <elombrozo@gmail.com> |
|||
* Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "FileSystem.h" |
|||
#include "Common.h" |
|||
#include "Log.h" |
|||
|
|||
#if defined(_WIN32) |
|||
#include <shlobj.h> |
|||
#else |
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <pwd.h> |
|||
#include <unistd.h> |
|||
#endif |
|||
#include <boost/filesystem.hpp> |
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
std::string dev::getDataDir(std::string _prefix) |
|||
{ |
|||
if (_prefix.empty()) |
|||
_prefix = "ethereum"; |
|||
#ifdef _WIN32 |
|||
_prefix[0] = toupper(_prefix[0]); |
|||
char path[1024] = ""; |
|||
if (SHGetSpecialFolderPathA(NULL, path, CSIDL_APPDATA, true)) |
|||
return (boost::filesystem::path(path) / _prefix).string(); |
|||
else |
|||
{ |
|||
#ifndef _MSC_VER // todo?
|
|||
cwarn << "getDataDir(): SHGetSpecialFolderPathA() failed."; |
|||
#endif |
|||
BOOST_THROW_EXCEPTION(std::runtime_error("getDataDir() - SHGetSpecialFolderPathA() failed.")); |
|||
} |
|||
#else |
|||
boost::filesystem::path dataDirPath; |
|||
char const* homeDir = getenv("HOME"); |
|||
if (!homeDir || strlen(homeDir) == 0) |
|||
{ |
|||
struct passwd* pwd = getpwuid(getuid()); |
|||
if (pwd) |
|||
homeDir = pwd->pw_dir; |
|||
} |
|||
|
|||
if (!homeDir || strlen(homeDir) == 0) |
|||
dataDirPath = boost::filesystem::path("/"); |
|||
else |
|||
dataDirPath = boost::filesystem::path(homeDir); |
|||
|
|||
return (dataDirPath / ("." + _prefix)).string(); |
|||
#endif |
|||
} |
@ -1,35 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file FileSystem.h
|
|||
* @authors |
|||
* Eric Lombrozo <elombrozo@gmail.com> |
|||
* Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <libdevcore/CommonIO.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
/// @returns the path for user data.
|
|||
std::string getDataDir(std::string _prefix = "ethereum"); |
|||
|
|||
} |
@ -1,111 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file StructuredLogger.h
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
* |
|||
* A simple helper class for the structured logging |
|||
* The spec for the implemented log events is here: |
|||
* https://github.com/ethereum/system-testing/wiki/Log-Events
|
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <fstream> |
|||
#include <string> |
|||
#include <chrono> |
|||
|
|||
namespace Json { class Value; } |
|||
namespace boost { namespace asio { namespace ip { template<class T>class basic_endpoint; class tcp; }}} |
|||
namespace bi = boost::asio::ip; |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
// TODO: Make the output stream configurable. stdout, stderr, file e.t.c.
|
|||
class StructuredLogger |
|||
{ |
|||
public: |
|||
/**
|
|||
* Initializes the structured logger object |
|||
* @param _enabled Whether logging is on or off |
|||
* @param _timeFormat A time format string as described here: |
|||
* http://en.cppreference.com/w/cpp/chrono/c/strftime
|
|||
* with which to display timestamps |
|||
*/ |
|||
void initialize(bool _enabled, std::string const& _timeFormat, std::string const& _destinationURL = ""); |
|||
|
|||
static StructuredLogger& get() |
|||
{ |
|||
static StructuredLogger instance; |
|||
return instance; |
|||
} |
|||
|
|||
static void starting(std::string const& _clientImpl, const char* _ethVersion); |
|||
static void stopping(std::string const& _clientImpl, const char* _ethVersion); |
|||
static void p2pConnected( |
|||
std::string const& _id, |
|||
bi::basic_endpoint<bi::tcp> const& _addr, |
|||
std::chrono::system_clock::time_point const& _ts, |
|||
std::string const& _remoteVersion, |
|||
unsigned int _numConnections |
|||
); |
|||
static void p2pDisconnected( |
|||
std::string const& _id, |
|||
bi::basic_endpoint<bi::tcp> const& _addr, |
|||
unsigned int _numConnections |
|||
); |
|||
static void minedNewBlock( |
|||
std::string const& _hash, |
|||
std::string const& _blockNumber, |
|||
std::string const& _chainHeadHash, |
|||
std::string const& _prevHash |
|||
); |
|||
static void chainReceivedNewBlock( |
|||
std::string const& _hash, |
|||
std::string const& _blockNumber, |
|||
std::string const& _chainHeadHash, |
|||
std::string const& _remoteID, |
|||
std::string const& _prevHash |
|||
); |
|||
static void chainNewHead( |
|||
std::string const& _hash, |
|||
std::string const& _blockNumber, |
|||
std::string const& _chainHeadHash, |
|||
std::string const& _prevHash |
|||
); |
|||
static void transactionReceived(std::string const& _hash, std::string const& _remoteId); |
|||
// TODO: static void pendingQueueChanged(std::vector<h256> const& _hashes);
|
|||
// TODO: static void miningStarted();
|
|||
// TODO: static void stillMining(unsigned _hashrate);
|
|||
// TODO: static void miningStopped();
|
|||
|
|||
private: |
|||
// Singleton class. Private default ctor and no copying
|
|||
StructuredLogger() = default; |
|||
StructuredLogger(StructuredLogger const&) = delete; |
|||
void operator=(StructuredLogger const&) = delete; |
|||
|
|||
void outputJson(Json::Value const& _value, std::string const& _name) const; |
|||
|
|||
bool m_enabled = false; |
|||
std::string m_timeFormat = "%Y-%m-%dT%H:%M:%S"; |
|||
|
|||
mutable std::ofstream m_out; |
|||
}; |
|||
|
|||
} |
@ -1,66 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file TransientDirectory.cpp
|
|||
* @author Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include <thread> |
|||
#include <boost/filesystem.hpp> |
|||
#include "Exceptions.h" |
|||
#include "TransientDirectory.h" |
|||
#include "CommonIO.h" |
|||
#include "Log.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
namespace fs = boost::filesystem; |
|||
|
|||
TransientDirectory::TransientDirectory(): |
|||
TransientDirectory((boost::filesystem::temp_directory_path() / "eth_transient" / toString(FixedHash<4>::random())).string()) |
|||
{} |
|||
|
|||
TransientDirectory::TransientDirectory(std::string const& _path): |
|||
m_path(_path) |
|||
{ |
|||
// we never ever want to delete a directory (including all its contents) that we did not create ourselves.
|
|||
if (boost::filesystem::exists(m_path)) |
|||
BOOST_THROW_EXCEPTION(FileError()); |
|||
|
|||
fs::create_directories(m_path); |
|||
DEV_IGNORE_EXCEPTIONS(fs::permissions(m_path, fs::owner_all)); |
|||
} |
|||
|
|||
TransientDirectory::~TransientDirectory() |
|||
{ |
|||
boost::system::error_code ec; |
|||
fs::remove_all(m_path, ec); |
|||
if (!ec) |
|||
return; |
|||
|
|||
// In some cases, antivirus runnig on Windows will scan all the newly created directories.
|
|||
// As a consequence, directory is locked and can not be deleted immediately.
|
|||
// Retry after 10 milliseconds usually is successful.
|
|||
// This will help our tests run smoothly in such environment.
|
|||
this_thread::sleep_for(chrono::milliseconds(10)); |
|||
|
|||
ec.clear(); |
|||
fs::remove_all(m_path, ec); |
|||
if (!ec) |
|||
{ |
|||
cwarn << "Failed to delete directory '" << m_path << "': " << ec.message(); |
|||
} |
|||
} |
@ -1,47 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file TransientDirectory.h
|
|||
* @author Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
/**
|
|||
* @brief temporary directory implementation |
|||
* It creates temporary directory in the given path. On dealloc it removes the directory |
|||
* @throws if the given path already exists, throws an exception |
|||
*/ |
|||
class TransientDirectory |
|||
{ |
|||
public: |
|||
TransientDirectory(); |
|||
TransientDirectory(std::string const& _path); |
|||
~TransientDirectory(); |
|||
|
|||
std::string const& path() const { return m_path; } |
|||
|
|||
private: |
|||
std::string m_path; |
|||
}; |
|||
|
|||
} |
@ -1,46 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file UndefMacros.h
|
|||
* @author Lefteris <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
* |
|||
* This header should be used to #undef some really evil macros defined by |
|||
* windows.h which result in conflict with our libsolidity/Token.h |
|||
*/ |
|||
#pragma once |
|||
|
|||
#if defined(_MSC_VER) || defined(__MINGW32__) |
|||
|
|||
#undef DELETE |
|||
#undef IN |
|||
#undef VOID |
|||
#undef THIS |
|||
#undef CONST |
|||
|
|||
// Conflicting define on MinGW in windows.h
|
|||
// windows.h(19): #define interface struct
|
|||
#ifdef interface |
|||
#undef interface |
|||
#endif |
|||
|
|||
#elif defined(DELETE) || defined(IN) || defined(VOID) || defined(THIS) || defined(CONST) || defined(interface) |
|||
|
|||
#error "The preceding macros in this header file are reserved for V8's "\ |
|||
"TOKEN_LIST. Please add a platform specific define above to undefine "\ |
|||
"overlapping macros." |
|||
|
|||
#endif |
Loading…
Reference in new issue