Merge branch 'phoenix' into tcp_rate_limiting
This commit is contained in:
commit
b9050b589d
35 changed files with 560 additions and 300 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -15,7 +15,6 @@
|
|||
*.a
|
||||
*.lib
|
||||
|
||||
|
||||
#CMake->MSVC artifacts
|
||||
*.sln
|
||||
*.vcxproj
|
||||
|
|
@ -41,5 +40,7 @@ libfc.a
|
|||
libfc_debug.a
|
||||
|
||||
fc_automoc.cpp
|
||||
*.swp
|
||||
git_revision.cpp
|
||||
GitSHA3.cpp
|
||||
|
||||
*.sw*
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ INCLUDE( VersionMacros )
|
|||
INCLUDE( SetupTargetMacros )
|
||||
INCLUDE(GetGitRevisionDescription)
|
||||
|
||||
get_git_head_revision(GIT_REFSPEC GIT_SHA3)
|
||||
get_git_unix_timestamp(GIT_UNIX_TIMESTAMP3)
|
||||
get_git_head_revision(GIT_REFSPEC FC_GIT_REVISION_SHA)
|
||||
get_git_unix_timestamp(FC_GIT_REVISION_UNIX_TIMESTAMP)
|
||||
|
||||
SET( DEFAULT_HEADER_INSTALL_DIR include/\${target} )
|
||||
SET( DEFAULT_LIBRARY_INSTALL_DIR lib/ )
|
||||
|
|
@ -38,10 +38,6 @@ LIST(APPEND BOOST_COMPONENTS thread date_time system filesystem program_options
|
|||
IF( WIN32 )
|
||||
MESSAGE(STATUS "Configuring fc to build on Win32")
|
||||
|
||||
#You need to set OPENSSL_ROOT environment variable for your system on WIN32
|
||||
message(STATUS "Setting up OpenSSL root and include vars on Win32 platform")
|
||||
set( OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT} )
|
||||
|
||||
set( RPCRT4 Rpcrt4 )
|
||||
|
||||
#boost
|
||||
|
|
@ -77,6 +73,12 @@ ELSE(WIN32)
|
|||
ENDIF(NOT APPLE)
|
||||
ENDIF(WIN32)
|
||||
|
||||
#IF($ENV{OPENSSL_ROOT_DIR})
|
||||
set(OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT_DIR} )
|
||||
set(OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR}/include)
|
||||
message(STATUS "Setting up OpenSSL root and include vars to ${OPENSSL_ROOT_DIR}, ${OPENSSL_INCLUDE_DIR}")
|
||||
#ENDIF()
|
||||
|
||||
find_package(OpenSSL)
|
||||
|
||||
set( CMAKE_FIND_LIBRARY_SUFFIXES ${ORIGINAL_LIB_SUFFIXES} )
|
||||
|
|
@ -169,8 +171,8 @@ set( sources
|
|||
${fc_sources}
|
||||
)
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GitSHA3.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/GitSHA3.cpp" @ONLY)
|
||||
list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/GitSHA3.cpp" GitSHA3.h)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/git_revision.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp" @ONLY)
|
||||
list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp")
|
||||
list(APPEND sources ${fc_headers})
|
||||
|
||||
add_subdirectory( vendor/easylzma )
|
||||
|
|
@ -192,8 +194,8 @@ ELSE()
|
|||
IF(APPLE)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall")
|
||||
ELSE()
|
||||
target_compile_options(fc PUBLIC -std=c++11 -Wall -fnon-call-exceptions -Wno-unused-local-typedefs -fmax-errors=3)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-local-typedefs -fmax-errors=3 ")
|
||||
target_compile_options(fc PUBLIC -std=c++11 -Wall -fnon-call-exceptions)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#include <stdint.h>
|
||||
#include "GitSHA3.h"
|
||||
|
||||
#define GIT_SHA3 "@GIT_SHA3@"
|
||||
const char* const g_GIT_SHA3 = GIT_SHA3;
|
||||
#define GIT_UNIX_TIMESTAMP3 @GIT_UNIX_TIMESTAMP3@
|
||||
const uint32_t g_GIT_UNIX_TIMESTAMP3 = GIT_UNIX_TIMESTAMP3;
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#ifndef __GITSHA3_H
|
||||
#define __GITSHA3_H
|
||||
|
||||
extern const char* const g_GIT_SHA3;
|
||||
extern const uint32_t g_GIT_UNIX_TIMESTAMP3;
|
||||
|
||||
#define APPLICATION_VERSION "1.0 Beta1"
|
||||
|
||||
#endif ///__GITSHA3_H
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <fc/crypto/base64.hpp>
|
||||
#include <fc/variant.hpp>
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
|
|
@ -112,6 +113,14 @@ namespace fc {
|
|||
}
|
||||
|
||||
|
||||
template<typename T,size_t N> struct get_typename< fc::array<T,N> >
|
||||
{
|
||||
static const char* name()
|
||||
{
|
||||
static std::string _name = std::string("fc::array<")+std::string(fc::get_typename<T>::name())+","+ fc::to_string(N) + ">";
|
||||
return _name.c_str();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <unordered_map>
|
||||
|
|
@ -123,7 +132,8 @@ namespace std
|
|||
{
|
||||
size_t operator()( const fc::array<T,N>& e )const
|
||||
{
|
||||
return fc::city_hash64( (char*)&e, sizeof(e) );
|
||||
return fc::city_hash_size_t( (char*)&e, sizeof(e) );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,14 @@ namespace fc {
|
|||
// Hash function for a byte array.
|
||||
uint64_t city_hash64(const char *buf, size_t len);
|
||||
|
||||
uint32_t city_hash32(const char *buf, size_t len);
|
||||
|
||||
#if SIZE_MAX > UINT32_MAX
|
||||
inline size_t city_hash_size_t(const char *buf, size_t len) { return city_hash64(buf, len); }
|
||||
#else
|
||||
inline size_t city_hash_size_t(const char *buf, size_t len) { return city_hash32(buf, len); }
|
||||
#endif
|
||||
|
||||
// Hash function for a byte array.
|
||||
uint128 city_hash128(const char *s, size_t len);
|
||||
|
||||
|
|
@ -60,6 +68,6 @@ uint64_t city_hash_crc_64(const char *buf, size_t len);
|
|||
|
||||
// Hash function for a byte array.
|
||||
uint128 city_hash_crc_128(const char *s, size_t len);
|
||||
fc::array<uint64_t,4> city_hash_crc_256(const char *s, size_t len);
|
||||
array<uint64_t,4> city_hash_crc_256(const char *s, size_t len);
|
||||
|
||||
} // namespace fc
|
||||
|
|
|
|||
|
|
@ -153,3 +153,7 @@ namespace fc {
|
|||
} // namespace raw
|
||||
|
||||
} // namespace fc
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
|
||||
FC_REFLECT_TYPENAME( fc::ecc::private_key )
|
||||
FC_REFLECT_TYPENAME( fc::ecc::public_key )
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class ripemd160
|
|||
typedef ripemd160 uint160_t;
|
||||
typedef ripemd160 uint160;
|
||||
|
||||
template<> struct get_typename<uint160> { static const char* name() { return "uint160"; } };
|
||||
template<> struct get_typename<uint160_t> { static const char* name() { return "uint160_t"; } };
|
||||
|
||||
} // namespace fc
|
||||
|
||||
|
|
|
|||
|
|
@ -95,3 +95,5 @@ namespace std
|
|||
}
|
||||
};
|
||||
}
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
FC_REFLECT_TYPENAME( fc::sha256 )
|
||||
|
|
|
|||
|
|
@ -72,3 +72,6 @@ class sha512
|
|||
void from_variant( const variant& v, sha512& bi );
|
||||
|
||||
} // fc
|
||||
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
FC_REFLECT_TYPENAME( fc::sha512 )
|
||||
|
|
|
|||
|
|
@ -239,10 +239,10 @@ do { if( !(TEST) ) { FC_THROW_EXCEPTION( assert_exception, #TEST ": " __VA_ARGS
|
|||
catch( fc::exception& er ) { \
|
||||
FC_RETHROW_EXCEPTION( er, LOG_LEVEL, FORMAT, __VA_ARGS__ ); \
|
||||
} catch( const std::exception& e ) { \
|
||||
throw fc::std_exception( \
|
||||
FC_LOG_MESSAGE( LOG_LEVEL, FORMAT,__VA_ARGS__), \
|
||||
fc::std_exception fce( \
|
||||
FC_LOG_MESSAGE( LOG_LEVEL, "what: ${what} - " FORMAT,__VA_ARGS__("what",e.what())), \
|
||||
std::current_exception(), \
|
||||
e.what() ) ; \
|
||||
e.what() ) ; throw fce;\
|
||||
} catch( ... ) { \
|
||||
throw fc::unhandled_exception( \
|
||||
FC_LOG_MESSAGE( LOG_LEVEL, FORMAT,__VA_ARGS__), \
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ namespace fc {
|
|||
{
|
||||
public:
|
||||
inline ~temp_file_base() { remove(); }
|
||||
inline operator bool() const { return _path; }
|
||||
inline operator bool() const { return _path.valid(); }
|
||||
inline bool operator!() const { return !_path; }
|
||||
const fc::path& path() const;
|
||||
void remove();
|
||||
|
|
|
|||
9
include/fc/git_revision.hpp
Normal file
9
include/fc/git_revision.hpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
namespace fc {
|
||||
|
||||
extern const char* const git_revision_sha;
|
||||
extern const uint32_t git_revision_unix_timestamp;
|
||||
|
||||
} // end namespace fc
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/utility.hpp>
|
||||
|
||||
namespace fc {
|
||||
uint8_t from_hex( char c );
|
||||
fc::string to_hex( const char* d, uint32_t s );
|
||||
|
||||
/**
|
||||
* @return the number of bytes decoded
|
||||
*/
|
||||
size_t from_hex( const fc::string& hex_str, char* out_data, size_t out_data_len );
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
fc::string to_base58( const char* d, size_t s );
|
||||
fc::vector<char> from_base58( const fc::string& base58_str );
|
||||
size_t from_base58( const fc::string& base58_str, char* out_data, size_t out_data_len );
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#ifndef _FC_BASE64_HPP
|
||||
#define _FC_BASE64_HPP
|
||||
#include <string>
|
||||
|
||||
namespace fc {
|
||||
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len);
|
||||
std::string base64_encode( const std::string& enc );
|
||||
std::string base64_decode( const std::string& encoded_string);
|
||||
} // namespace fc
|
||||
#endif // _FC_BASE64_HPP
|
||||
|
|
@ -29,7 +29,7 @@ namespace fc {
|
|||
enum seekdir { beg, cur, end };
|
||||
|
||||
ifstream();
|
||||
ifstream( const fc::path& file, int m );
|
||||
ifstream( const fc::path& file, int m = binary);
|
||||
~ifstream();
|
||||
|
||||
void open( const fc::path& file, int m );
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <fc/io/raw_fwd.hpp>
|
||||
#include <fc/filesystem.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
#include <map>
|
||||
|
||||
#define MAX_ARRAY_ALLOC_SIZE (1024*1024*10)
|
||||
|
||||
|
|
@ -37,11 +38,11 @@ namespace fc {
|
|||
|
||||
template<typename Stream>
|
||||
inline void unpack( Stream& s, fc::time_point_sec& tp )
|
||||
{
|
||||
{ try {
|
||||
uint32_t sec;
|
||||
s.read( (char*)&sec, sizeof(sec) );
|
||||
tp = fc::time_point() + fc::seconds(sec);
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
|
||||
|
||||
template<typename Stream>
|
||||
inline void pack( Stream& s, const fc::time_point& tp )
|
||||
|
|
@ -52,11 +53,11 @@ namespace fc {
|
|||
|
||||
template<typename Stream>
|
||||
inline void unpack( Stream& s, fc::time_point& tp )
|
||||
{
|
||||
{ try {
|
||||
uint64_t usec;
|
||||
s.read( (char*)&usec, sizeof(usec) );
|
||||
tp = fc::time_point() + fc::microseconds(usec);
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
|
||||
|
||||
template<typename Stream, typename T, size_t N>
|
||||
inline void pack( Stream& s, const fc::array<T,N>& v) {
|
||||
|
|
@ -64,9 +65,10 @@ namespace fc {
|
|||
}
|
||||
|
||||
template<typename Stream, typename T, size_t N>
|
||||
inline void unpack( Stream& s, fc::array<T,N>& v) {
|
||||
inline void unpack( Stream& s, fc::array<T,N>& v)
|
||||
{ try {
|
||||
s.read((char*)&v.data[0],N*sizeof(T));
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "fc::array<type,length>", ("type",fc::get_typename<T>::name())("length",N) ) }
|
||||
|
||||
template<typename Stream> inline void pack( Stream& s, const signed_int& v ) {
|
||||
uint32_t val = (v.value<<1) ^ (v.value>>31);
|
||||
|
|
@ -119,10 +121,11 @@ namespace fc {
|
|||
}
|
||||
|
||||
template<typename Stream, typename T>
|
||||
void unpack( Stream& s, fc::optional<T>& v ) {
|
||||
void unpack( Stream& s, fc::optional<T>& v )
|
||||
{ try {
|
||||
bool b; unpack( s, b );
|
||||
if( b ) { v = T(); unpack( s, *v ); }
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "optional<${type}>", ("type",fc::get_typename<T>::name() ) ) }
|
||||
|
||||
// std::vector<char>
|
||||
template<typename Stream> inline void pack( Stream& s, const std::vector<char>& value ) {
|
||||
|
|
@ -177,9 +180,10 @@ namespace fc {
|
|||
:c(_c),s(_s){}
|
||||
|
||||
template<typename T, typename C, T(C::*p)>
|
||||
inline void operator()( const char* name )const {
|
||||
inline void operator()( const char* name )const
|
||||
{ try {
|
||||
raw::unpack( s, c.*p );
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "Error unpacking field ${field}", ("field",name) ) }
|
||||
private:
|
||||
Class& c;
|
||||
Stream& s;
|
||||
|
|
@ -316,6 +320,29 @@ namespace fc {
|
|||
value.insert( std::move(tmp) );
|
||||
}
|
||||
}
|
||||
template<typename Stream, typename K, typename V>
|
||||
inline void pack( Stream& s, const std::map<K,V>& value ) {
|
||||
pack( s, unsigned_int(value.size()) );
|
||||
auto itr = value.begin();
|
||||
auto end = value.end();
|
||||
while( itr != end ) {
|
||||
fc::raw::pack( s, *itr );
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
template<typename Stream, typename K, typename V>
|
||||
inline void unpack( Stream& s, std::map<K,V>& value )
|
||||
{
|
||||
unsigned_int size; unpack( s, size );
|
||||
value.clear();
|
||||
FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE );
|
||||
for( uint32_t i = 0; i < size.value; ++i )
|
||||
{
|
||||
std::pair<K,V> tmp;
|
||||
fc::raw::unpack( s, tmp );
|
||||
value.insert( std::move(tmp) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename Stream, typename T>
|
||||
|
|
@ -371,10 +398,18 @@ namespace fc {
|
|||
fc::raw::detail::if_reflected< typename fc::reflector<T>::is_defined >::pack(s,v);
|
||||
}
|
||||
template<typename Stream, typename T>
|
||||
inline void unpack( Stream& s, T& v ) {
|
||||
inline void unpack( Stream& s, T& v )
|
||||
{ try {
|
||||
fc::raw::detail::if_reflected< typename fc::reflector<T>::is_defined >::unpack(s,v);
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
|
||||
|
||||
template<typename T>
|
||||
inline size_t pack_size( const T& v )
|
||||
{
|
||||
datastream<size_t> ps;
|
||||
raw::pack(ps,v );
|
||||
return ps.tellp();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::vector<char> pack( const T& v ) {
|
||||
|
|
@ -390,14 +425,15 @@ namespace fc {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
inline T unpack( const std::vector<char>& s ) {
|
||||
inline T unpack( const std::vector<char>& s )
|
||||
{ try {
|
||||
T tmp;
|
||||
if( s.size() ) {
|
||||
datastream<const char*> ds( s.data(), size_t(s.size()) );
|
||||
raw::unpack(ds,tmp);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
|
||||
|
||||
template<typename T>
|
||||
inline void pack( char* d, uint32_t s, const T& v ) {
|
||||
|
|
@ -406,18 +442,21 @@ namespace fc {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
inline T unpack( const char* d, uint32_t s ) {
|
||||
inline T unpack( const char* d, uint32_t s )
|
||||
{ try {
|
||||
T v;
|
||||
datastream<const char*> ds( d, s );
|
||||
raw::unpack(ds,v);
|
||||
return v;
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
|
||||
|
||||
template<typename T>
|
||||
inline void unpack( const char* d, uint32_t s, T& v ) {
|
||||
inline void unpack( const char* d, uint32_t s, T& v )
|
||||
{ try {
|
||||
datastream<const char*> ds( d, s );
|
||||
raw::unpack(ds,v);
|
||||
return v;
|
||||
}
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
|
||||
|
||||
} } // namespace fc::raw
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ namespace fc {
|
|||
|
||||
template<typename Stream, typename K, typename V> inline void pack( Stream& s, const std::unordered_map<K,V>& value );
|
||||
template<typename Stream, typename K, typename V> inline void unpack( Stream& s, std::unordered_map<K,V>& value );
|
||||
template<typename Stream, typename K, typename V> inline void pack( Stream& s, const std::map<K,V>& value );
|
||||
template<typename Stream, typename K, typename V> inline void unpack( Stream& s, std::map<K,V>& value );
|
||||
|
||||
template<typename Stream, typename K, typename V> inline void pack( Stream& s, const std::pair<K,V>& value );
|
||||
template<typename Stream, typename K, typename V> inline void unpack( Stream& s, std::pair<K,V>& value );
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ struct unsigned_int {
|
|||
* Uses the google protobuf algorithm for seralizing signed numbers
|
||||
*/
|
||||
struct signed_int {
|
||||
signed_int( int64_t v = 0 ):value(v){}
|
||||
signed_int( int32_t v = 0 ):value(v){}
|
||||
operator int32_t()const { return value; }
|
||||
template<typename T>
|
||||
signed_int& operator=( const T& v ) { value = v; return *this; }
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace std
|
|||
{
|
||||
size_t operator()( const fc::ip::endpoint& e )const
|
||||
{
|
||||
return fc::city_hash64( (char*)&e, sizeof(e) );
|
||||
return fc::city_hash_size_t( (char*)&e, sizeof(e) );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,7 +183,10 @@ namespace fc {
|
|||
|
||||
bool valid()const { return _valid; }
|
||||
bool operator!()const { return !_valid; }
|
||||
operator bool()const { return _valid; }
|
||||
|
||||
// this operation is not safe and can result in unintential
|
||||
// casts and comparisons, use valid() or !!
|
||||
explicit operator bool()const { return _valid; }
|
||||
|
||||
T& operator*() { assert(_valid); return ref(); }
|
||||
const T& operator*()const { assert(_valid); return ref(); }
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ namespace fc
|
|||
fc::string to_string( uint64_t );
|
||||
fc::string to_string( int64_t );
|
||||
fc::string to_string( uint16_t );
|
||||
inline fc::string to_string( int32_t v ) { return to_string( int64_t(v) ); }
|
||||
inline fc::string to_string( uint32_t v ){ return to_string( uint64_t(v) ); }
|
||||
#ifdef __APPLE__
|
||||
inline fc::string to_string( size_t s) { return to_string(uint64_t(s)); }
|
||||
#endif
|
||||
|
||||
typedef fc::optional<fc::string> ostring;
|
||||
class variant_object;
|
||||
|
|
|
|||
|
|
@ -18,12 +18,15 @@ namespace fc {
|
|||
|
||||
|
||||
bool operator==(const microseconds& c)const { return _count == c._count; }
|
||||
bool operator!=(const microseconds& c)const { return _count != c._count; }
|
||||
friend bool operator>(const microseconds& a, const microseconds& b){ return a._count > b._count; }
|
||||
friend bool operator>=(const microseconds& a, const microseconds& b){ return a._count >= b._count; }
|
||||
friend bool operator<(const microseconds& a, const microseconds& b){ return a._count < b._count; }
|
||||
friend bool operator<=(const microseconds& a, const microseconds& b){ return a._count <= b._count; }
|
||||
microseconds& operator+=(const microseconds& c) { _count += c._count; return *this; }
|
||||
microseconds& operator-=(const microseconds& c) { _count -= c._count; return *this; }
|
||||
int64_t count()const { return _count; }
|
||||
int64_t to_seconds()const { return _count/1000000; }
|
||||
private:
|
||||
friend class time_point;
|
||||
int64_t _count;
|
||||
|
|
@ -53,6 +56,7 @@ namespace fc {
|
|||
bool operator ==( const time_point& t )const { return elapsed._count ==t.elapsed._count; }
|
||||
bool operator !=( const time_point& t )const { return elapsed._count !=t.elapsed._count; }
|
||||
time_point& operator += ( const microseconds& m) { elapsed+=m; return *this; }
|
||||
time_point& operator -= ( const microseconds& m) { elapsed-=m; return *this; }
|
||||
time_point operator + (const microseconds& m) const { return time_point(elapsed+m); }
|
||||
time_point operator - (const microseconds& m) const { return time_point(elapsed-m); }
|
||||
microseconds operator - (const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); }
|
||||
|
|
@ -90,6 +94,8 @@ namespace fc {
|
|||
friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; }
|
||||
friend bool operator != ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds != b.utc_seconds; }
|
||||
time_point_sec& operator += ( uint32_t m ) { utc_seconds+=m; return *this; }
|
||||
time_point_sec& operator -= ( uint32_t m ) { utc_seconds-=m; return *this; }
|
||||
time_point_sec operator+( uint32_t offset ) { return time_point_sec(utc_seconds + offset); }
|
||||
|
||||
friend time_point operator - ( const time_point_sec& t, const microseconds& m ) { return time_point(t) - m; }
|
||||
friend microseconds operator - ( const time_point_sec& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
|
||||
|
|
@ -108,6 +114,10 @@ namespace fc {
|
|||
string get_approximate_relative_time_string(const time_point& event_time);
|
||||
}
|
||||
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
FC_REFLECT_TYPENAME( fc::time_point )
|
||||
FC_REFLECT_TYPENAME( fc::time_point_sec )
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif /// #ifdef _MSC_VER
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ namespace fc
|
|||
inline void unpack( Stream& s, uint128& u ) { s.read( (char*)&u, sizeof(u) ); }
|
||||
}
|
||||
|
||||
uint64_t city_hash64(const char *buf, size_t len);
|
||||
size_t city_hash_size_t(const char *buf, size_t len);
|
||||
} // namespace fc
|
||||
|
||||
namespace std
|
||||
|
|
@ -109,7 +109,7 @@ namespace std
|
|||
{
|
||||
size_t operator()( const fc::uint128& s )const
|
||||
{
|
||||
return fc::city_hash64((char*)&s, sizeof(s));
|
||||
return fc::city_hash_size_t((char*)&s, sizeof(s));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ namespace fc
|
|||
variant( const optional<T>& v )
|
||||
{
|
||||
memset( this, 0, sizeof(*this) );
|
||||
if( v ) *this = variant(*v);
|
||||
if( v.valid() ) *this = variant(*v);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
@ -427,3 +427,6 @@ namespace fc
|
|||
}
|
||||
|
||||
} // namespace fc
|
||||
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
FC_REFLECT_TYPENAME( fc::variant )
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ void aes_encoder::init( const fc::sha256& key, const fc::uint128& init_value )
|
|||
* is 128 bits */
|
||||
if(1 != EVP_EncryptInit_ex(my->ctx, EVP_aes_256_cbc(), NULL, (unsigned char*)&key, (unsigned char*)&init_value))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption init",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption init",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
EVP_CIPHER_CTX_set_padding( my->ctx, 0 );
|
||||
|
|
@ -52,7 +52,7 @@ uint32_t aes_encoder::encode( const char* plaintxt, uint32_t plaintext_len, char
|
|||
* */
|
||||
if(1 != EVP_EncryptUpdate(my->ctx, (unsigned char*)ciphertxt, &ciphertext_len, (const unsigned char*)plaintxt, plaintext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption update",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption update",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
FC_ASSERT( ciphertext_len == plaintext_len, "", ("ciphertext_len",ciphertext_len)("plaintext_len",plaintext_len) );
|
||||
|
|
@ -67,7 +67,7 @@ uint32_t aes_encoder::final_encode( char* ciphertxt )
|
|||
* */
|
||||
if(1 != EVP_EncryptFinal_ex(my->ctx, (unsigned char*)ciphertxt, &ciphertext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption final",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption final",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
return ciphertext_len;
|
||||
|
|
@ -98,7 +98,7 @@ void aes_decoder::init( const fc::sha256& key, const fc::uint128& init_value )
|
|||
* is 128 bits */
|
||||
if(1 != EVP_DecryptInit_ex(my->ctx, EVP_aes_256_cbc(), NULL, (unsigned char*)&key, (unsigned char*)&init_value))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption init",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption init",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
EVP_CIPHER_CTX_set_padding( my->ctx, 0 );
|
||||
|
|
@ -115,7 +115,7 @@ uint32_t aes_decoder::decode( const char* ciphertxt, uint32_t plaintext_len, cha
|
|||
* */
|
||||
if(1 != EVP_DecryptUpdate(my->ctx, (unsigned char*)plaintext, &ciphertext_len, (const unsigned char*)ciphertxt, plaintext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption update",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption update",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
FC_ASSERT( ciphertext_len == plaintext_len, "", ("ciphertext_len",ciphertext_len)("plaintext_len",plaintext_len) );
|
||||
|
|
@ -131,7 +131,7 @@ uint32_t aes_decoder::final_decode( char* plaintext )
|
|||
* */
|
||||
if(1 != EVP_DecryptFinal_ex(my->ctx, (unsigned char*)plaintext, &ciphertext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption final",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption final",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
return ciphertext_len;
|
||||
|
|
@ -172,7 +172,7 @@ int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key,
|
|||
* is 128 bits */
|
||||
if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption init",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption init",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +181,7 @@ int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key,
|
|||
* */
|
||||
if(1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption update",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption update",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
ciphertext_len = len;
|
||||
|
|
@ -191,7 +191,7 @@ int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key,
|
|||
* */
|
||||
if(1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc encryption final",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc encryption final",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
ciphertext_len += len;
|
||||
|
|
@ -220,7 +220,7 @@ int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *ke
|
|||
* * is 128 bits */
|
||||
if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt init",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc decrypt init",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +229,7 @@ int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *ke
|
|||
* */
|
||||
if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt update",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc decrypt update",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
|
|
@ -240,7 +240,7 @@ int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *ke
|
|||
* */
|
||||
if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt final",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc decrypt final",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
plaintext_len += len;
|
||||
|
|
@ -269,7 +269,7 @@ int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char
|
|||
* * is 128 bits */
|
||||
if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cfb128(), NULL, key, iv))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt init",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc decrypt init",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char
|
|||
* */
|
||||
if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt update",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc decrypt update",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
|
|
@ -289,7 +289,7 @@ int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char
|
|||
* */
|
||||
if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt final",
|
||||
FC_THROW_EXCEPTION( exception, "error during aes 256 cbc decrypt final",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
plaintext_len += len;
|
||||
|
|
|
|||
|
|
@ -28,11 +28,12 @@
|
|||
// compromising on hash quality.
|
||||
|
||||
//#include "config.h"
|
||||
//#include "city.h"
|
||||
//#include <city.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string.h> // for memcpy and memset
|
||||
#include <fc/crypto/city.hpp>
|
||||
|
||||
#if defined(__SSE4_2__) && defined(__x86_64__)
|
||||
#include <nmmintrin.h>
|
||||
#else
|
||||
|
|
@ -41,6 +42,9 @@ uint64_t _mm_crc32_u64(uint64_t a, uint64_t b );
|
|||
|
||||
namespace fc {
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
inline uint64_t Uint128Low64(const uint128& x) { return x.low_bits(); }
|
||||
inline uint64_t Uint128High64(const uint128& x) { return x.high_bits(); }
|
||||
|
||||
|
|
@ -56,17 +60,6 @@ inline uint64_t Hash128to64(const uint128& x) {
|
|||
b *= kMul;
|
||||
return b;
|
||||
}
|
||||
// Hash function for a byte array. For convenience, a 64-bit seed is also
|
||||
// hashed into the result.
|
||||
uint64_t CityHash64WithSeed(const char *buf, size_t len, uint64_t seed);
|
||||
|
||||
// Hash function for a byte array. For convenience, two seeds are also
|
||||
// hashed into the result.
|
||||
uint64_t CityHash64WithSeeds(const char *buf, size_t len,
|
||||
uint64_t seed0, uint64_t seed1);
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
static uint64_t UNALIGNED_LOAD64(const char *p) {
|
||||
uint64_t result;
|
||||
|
|
@ -80,32 +73,59 @@ static uint32_t UNALIGNED_LOAD32(const char *p) {
|
|||
return result;
|
||||
}
|
||||
|
||||
#if !defined(WORDS_BIGENDIAN)
|
||||
|
||||
#define uint32_in_expected_order(x) (x)
|
||||
#define uint64_in_expected_order(x) (x)
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#include <stdlib.h>
|
||||
#define bswap_32(x) _byteswap_ulong(x)
|
||||
#define bswap_64(x) _byteswap_uint64(x)
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
// Mac OS X / Darwin features
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#define bswap_32(x) OSSwapInt32(x)
|
||||
#define bswap_64(x) OSSwapInt64(x)
|
||||
|
||||
#else
|
||||
#include <byteswap.h>
|
||||
#elif defined(__sun) || defined(sun)
|
||||
|
||||
#include <sys/byteorder.h>
|
||||
#define bswap_32(x) BSWAP_32(x)
|
||||
#define bswap_64(x) BSWAP_64(x)
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
#include <sys/endian.h>
|
||||
#define bswap_32(x) bswap32(x)
|
||||
#define bswap_64(x) bswap64(x)
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
#include <sys/types.h>
|
||||
#define bswap_32(x) swap32(x)
|
||||
#define bswap_64(x) swap64(x)
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/bswap.h>
|
||||
#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
|
||||
#define bswap_32(x) bswap32(x)
|
||||
#define bswap_64(x) bswap64(x)
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include <byteswap.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define uint32_in_expected_order(x) (bswap_32(x))
|
||||
#define uint64_in_expected_order(x) (bswap_64(x))
|
||||
|
||||
#endif // WORDS_BIGENDIAN
|
||||
#else
|
||||
#define uint32_in_expected_order(x) (x)
|
||||
#define uint64_in_expected_order(x) (x)
|
||||
#endif
|
||||
|
||||
#if !defined(LIKELY)
|
||||
#if HAVE_BUILTIN_EXPECT
|
||||
|
|
@ -127,7 +147,139 @@ static uint32_t Fetch32(const char *p) {
|
|||
static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
|
||||
static const uint64_t k1 = 0xb492b66fbe98f273ULL;
|
||||
static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
|
||||
static const uint64_t k3 = 0xc949d7c7509e6557ULL;
|
||||
|
||||
// Magic numbers for 32-bit hashing. Copied from Murmur3.
|
||||
static const uint32_t c1 = 0xcc9e2d51;
|
||||
static const uint32_t c2 = 0x1b873593;
|
||||
|
||||
// A 32-bit to 32-bit integer hash copied from Murmur3.
|
||||
static uint32_t fmix(uint32_t h)
|
||||
{
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6b;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35;
|
||||
h ^= h >> 16;
|
||||
return h;
|
||||
}
|
||||
|
||||
static uint32_t Rotate32(uint32_t val, int shift) {
|
||||
// Avoid shifting by 32: doing so yields an undefined result.
|
||||
return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
|
||||
}
|
||||
|
||||
#undef PERMUTE3
|
||||
#define PERMUTE3(a, b, c) do { std::swap(a, b); std::swap(a, c); } while (0)
|
||||
|
||||
static uint32_t Mur(uint32_t a, uint32_t h) {
|
||||
// Helper from Murmur3 for combining two 32-bit values.
|
||||
a *= c1;
|
||||
a = Rotate32(a, 17);
|
||||
a *= c2;
|
||||
h ^= a;
|
||||
h = Rotate32(h, 19);
|
||||
return h * 5 + 0xe6546b64;
|
||||
}
|
||||
|
||||
static uint32_t Hash32Len13to24(const char *s, size_t len) {
|
||||
uint32_t a = Fetch32(s - 4 + (len >> 1));
|
||||
uint32_t b = Fetch32(s + 4);
|
||||
uint32_t c = Fetch32(s + len - 8);
|
||||
uint32_t d = Fetch32(s + (len >> 1));
|
||||
uint32_t e = Fetch32(s);
|
||||
uint32_t f = Fetch32(s + len - 4);
|
||||
uint32_t h = len;
|
||||
|
||||
return fmix(Mur(f, Mur(e, Mur(d, Mur(c, Mur(b, Mur(a, h)))))));
|
||||
}
|
||||
|
||||
static uint32_t Hash32Len0to4(const char *s, size_t len) {
|
||||
uint32_t b = 0;
|
||||
uint32_t c = 9;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
signed char v = s[i];
|
||||
b = b * c1 + v;
|
||||
c ^= b;
|
||||
}
|
||||
return fmix(Mur(b, Mur(len, c)));
|
||||
}
|
||||
|
||||
static uint32_t Hash32Len5to12(const char *s, size_t len) {
|
||||
uint32_t a = len, b = len * 5, c = 9, d = b;
|
||||
a += Fetch32(s);
|
||||
b += Fetch32(s + len - 4);
|
||||
c += Fetch32(s + ((len >> 1) & 4));
|
||||
return fmix(Mur(c, Mur(b, Mur(a, d))));
|
||||
}
|
||||
|
||||
uint32_t city_hash32(const char *s, size_t len) {
|
||||
if (len <= 24) {
|
||||
return len <= 12 ?
|
||||
(len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len)) :
|
||||
Hash32Len13to24(s, len);
|
||||
}
|
||||
|
||||
// len > 24
|
||||
uint32_t h = len, g = c1 * len, f = g;
|
||||
uint32_t a0 = Rotate32(Fetch32(s + len - 4) * c1, 17) * c2;
|
||||
uint32_t a1 = Rotate32(Fetch32(s + len - 8) * c1, 17) * c2;
|
||||
uint32_t a2 = Rotate32(Fetch32(s + len - 16) * c1, 17) * c2;
|
||||
uint32_t a3 = Rotate32(Fetch32(s + len - 12) * c1, 17) * c2;
|
||||
uint32_t a4 = Rotate32(Fetch32(s + len - 20) * c1, 17) * c2;
|
||||
h ^= a0;
|
||||
h = Rotate32(h, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
h ^= a2;
|
||||
h = Rotate32(h, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
g ^= a1;
|
||||
g = Rotate32(g, 19);
|
||||
g = g * 5 + 0xe6546b64;
|
||||
g ^= a3;
|
||||
g = Rotate32(g, 19);
|
||||
g = g * 5 + 0xe6546b64;
|
||||
f += a4;
|
||||
f = Rotate32(f, 19);
|
||||
f = f * 5 + 0xe6546b64;
|
||||
size_t iters = (len - 1) / 20;
|
||||
do {
|
||||
uint32_t a0 = Rotate32(Fetch32(s) * c1, 17) * c2;
|
||||
uint32_t a1 = Fetch32(s + 4);
|
||||
uint32_t a2 = Rotate32(Fetch32(s + 8) * c1, 17) * c2;
|
||||
uint32_t a3 = Rotate32(Fetch32(s + 12) * c1, 17) * c2;
|
||||
uint32_t a4 = Fetch32(s + 16);
|
||||
h ^= a0;
|
||||
h = Rotate32(h, 18);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
f += a1;
|
||||
f = Rotate32(f, 19);
|
||||
f = f * c1;
|
||||
g += a2;
|
||||
g = Rotate32(g, 18);
|
||||
g = g * 5 + 0xe6546b64;
|
||||
h ^= a3 + a1;
|
||||
h = Rotate32(h, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
g ^= a4;
|
||||
g = bswap_32(g) * 5;
|
||||
h += a4 * 5;
|
||||
h = bswap_32(h);
|
||||
f += a0;
|
||||
PERMUTE3(f, h, g);
|
||||
s += 20;
|
||||
} while (--iters != 0);
|
||||
g = Rotate32(g, 11) * c1;
|
||||
g = Rotate32(g, 17) * c1;
|
||||
f = Rotate32(f, 11) * c1;
|
||||
f = Rotate32(f, 17) * c1;
|
||||
h = Rotate32(h + g, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
h = Rotate32(h, 17) * c1;
|
||||
h = Rotate32(h + f, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
h = Rotate32(h, 17) * c1;
|
||||
return h;
|
||||
}
|
||||
|
||||
// Bitwise right rotate. Normally this will compile to a single
|
||||
// instruction, especially if the shift is a manifest constant.
|
||||
|
|
@ -136,13 +288,6 @@ static uint64_t Rotate(uint64_t val, int shift) {
|
|||
return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
|
||||
}
|
||||
|
||||
// Equivalent to Rotate(), but requires the second arg to be non-zero.
|
||||
// On x86-64, and probably others, it's possible for this to compile
|
||||
// to a single instruction if both args are already in registers.
|
||||
static uint64_t RotateByAtLeast1(uint64_t val, int shift) {
|
||||
return (val >> shift) | (val << (64 - shift));
|
||||
}
|
||||
|
||||
static uint64_t ShiftMix(uint64_t val) {
|
||||
return val ^ (val >> 47);
|
||||
}
|
||||
|
|
@ -151,15 +296,29 @@ static uint64_t HashLen16(uint64_t u, uint64_t v) {
|
|||
return Hash128to64(uint128(u, v));
|
||||
}
|
||||
|
||||
static uint64_t HashLen16(uint64_t u, uint64_t v, uint64_t mul) {
|
||||
// Murmur-inspired hashing.
|
||||
uint64_t a = (u ^ v) * mul;
|
||||
a ^= (a >> 47);
|
||||
uint64_t b = (v ^ a) * mul;
|
||||
b ^= (b >> 47);
|
||||
b *= mul;
|
||||
return b;
|
||||
}
|
||||
|
||||
static uint64_t HashLen0to16(const char *s, size_t len) {
|
||||
if (len > 8) {
|
||||
uint64_t a = Fetch64(s);
|
||||
if (len >= 8) {
|
||||
uint64_t mul = k2 + len * 2;
|
||||
uint64_t a = Fetch64(s) + k2;
|
||||
uint64_t b = Fetch64(s + len - 8);
|
||||
return HashLen16(a, RotateByAtLeast1(b + len, len)) ^ b;
|
||||
uint64_t c = Rotate(b, 37) * mul + a;
|
||||
uint64_t d = (Rotate(a, 25) + b) * mul;
|
||||
return HashLen16(c, d, mul);
|
||||
}
|
||||
if (len >= 4) {
|
||||
uint64_t mul = k2 + len * 2;
|
||||
uint64_t a = Fetch32(s);
|
||||
return HashLen16(len + (a << 3), Fetch32(s + len - 4));
|
||||
return HashLen16(len + (a << 3), Fetch32(s + len - 4), mul);
|
||||
}
|
||||
if (len > 0) {
|
||||
uint8_t a = s[0];
|
||||
|
|
@ -167,7 +326,7 @@ static uint64_t HashLen0to16(const char *s, size_t len) {
|
|||
uint8_t c = s[len - 1];
|
||||
uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
|
||||
uint32_t z = len + (static_cast<uint32_t>(c) << 2);
|
||||
return ShiftMix(y * k2 ^ z * k3) * k2;
|
||||
return ShiftMix(y * k2 ^ z * k0) * k2;
|
||||
}
|
||||
return k2;
|
||||
}
|
||||
|
|
@ -175,12 +334,13 @@ static uint64_t HashLen0to16(const char *s, size_t len) {
|
|||
// This probably works well for 16-byte strings as well, but it may be overkill
|
||||
// in that case.
|
||||
static uint64_t HashLen17to32(const char *s, size_t len) {
|
||||
uint64_t mul = k2 + len * 2;
|
||||
uint64_t a = Fetch64(s) * k1;
|
||||
uint64_t b = Fetch64(s + 8);
|
||||
uint64_t c = Fetch64(s + len - 8) * k2;
|
||||
uint64_t d = Fetch64(s + len - 16) * k0;
|
||||
return HashLen16(Rotate(a - b, 43) + Rotate(c, 30) + d,
|
||||
a + Rotate(b ^ k3, 20) - c + len);
|
||||
uint64_t c = Fetch64(s + len - 8) * mul;
|
||||
uint64_t d = Fetch64(s + len - 16) * k2;
|
||||
return HashLen16(Rotate(a + b, 43) + Rotate(c, 30) + d,
|
||||
a + Rotate(b + k2, 18) + c, mul);
|
||||
}
|
||||
|
||||
// Return a 16-byte hash for 48 bytes. Quick and dirty.
|
||||
|
|
@ -209,26 +369,24 @@ static pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
|
|||
|
||||
// Return an 8-byte hash for 33 to 64 bytes.
|
||||
static uint64_t HashLen33to64(const char *s, size_t len) {
|
||||
uint64_t z = Fetch64(s + 24);
|
||||
uint64_t a = Fetch64(s) + (len + Fetch64(s + len - 16)) * k0;
|
||||
uint64_t b = Rotate(a + z, 52);
|
||||
uint64_t c = Rotate(a, 37);
|
||||
a += Fetch64(s + 8);
|
||||
c += Rotate(a, 7);
|
||||
a += Fetch64(s + 16);
|
||||
uint64_t vf = a + z;
|
||||
uint64_t vs = b + Rotate(a, 31) + c;
|
||||
a = Fetch64(s + 16) + Fetch64(s + len - 32);
|
||||
z = Fetch64(s + len - 8);
|
||||
b = Rotate(a + z, 52);
|
||||
c = Rotate(a, 37);
|
||||
a += Fetch64(s + len - 24);
|
||||
c += Rotate(a, 7);
|
||||
a += Fetch64(s + len - 16);
|
||||
uint64_t wf = a + z;
|
||||
uint64_t ws = b + Rotate(a, 31) + c;
|
||||
uint64_t r = ShiftMix((vf + ws) * k2 + (wf + vs) * k0);
|
||||
return ShiftMix(r * k0 + vs) * k2;
|
||||
uint64_t mul = k2 + len * 2;
|
||||
uint64_t a = Fetch64(s) * k2;
|
||||
uint64_t b = Fetch64(s + 8);
|
||||
uint64_t c = Fetch64(s + len - 24);
|
||||
uint64_t d = Fetch64(s + len - 32);
|
||||
uint64_t e = Fetch64(s + 16) * k2;
|
||||
uint64_t f = Fetch64(s + 24) * 9;
|
||||
uint64_t g = Fetch64(s + len - 8);
|
||||
uint64_t h = Fetch64(s + len - 16) * mul;
|
||||
uint64_t u = Rotate(a + g, 43) + (Rotate(b, 30) + c) * 9;
|
||||
uint64_t v = ((a + g) ^ d) + f + 1;
|
||||
uint64_t w = bswap_64((u + v) * mul) + h;
|
||||
uint64_t x = Rotate(e + f, 42) + c;
|
||||
uint64_t y = (bswap_64((v + w) * mul) + g) * mul;
|
||||
uint64_t z = e + f + c;
|
||||
a = bswap_64((x + z) * mul + y) + b;
|
||||
b = ShiftMix((z + a) * mul + d + h) * mul;
|
||||
return b + x;
|
||||
}
|
||||
|
||||
uint64_t city_hash64(const char *s, size_t len) {
|
||||
|
|
@ -269,15 +427,15 @@ uint64_t city_hash64(const char *s, size_t len) {
|
|||
HashLen16(v.second, w.second) + x);
|
||||
}
|
||||
|
||||
uint64_t CityHash64WithSeed(const char *s, size_t len, uint64_t seed) {
|
||||
return CityHash64WithSeeds(s, len, k2, seed);
|
||||
}
|
||||
|
||||
uint64_t CityHash64WithSeeds(const char *s, size_t len,
|
||||
uint64_t seed0, uint64_t seed1) {
|
||||
return HashLen16(city_hash64(s, len) - seed0, seed1);
|
||||
}
|
||||
|
||||
uint64_t CityHash64WithSeed(const char *s, size_t len, uint64_t seed) {
|
||||
return CityHash64WithSeeds(s, len, k2, seed);
|
||||
}
|
||||
|
||||
// A subroutine for CityHash128(). Returns a decent 128-bit hash for strings
|
||||
// of any length representable in signed long. Based on City and Murmur.
|
||||
static uint128 CityMurmur(const char *s, size_t len, uint128 seed) {
|
||||
|
|
@ -349,7 +507,10 @@ uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed) {
|
|||
len -= 128;
|
||||
} while (LIKELY(len >= 128));
|
||||
x += Rotate(v.first + z, 49) * k0;
|
||||
z += Rotate(w.first, 37) * k0;
|
||||
y = y * k0 + Rotate(w.second, 37);
|
||||
z = z * k0 + Rotate(w.first, 27);
|
||||
w.first *= 9;
|
||||
v.first *= k0;
|
||||
// If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s.
|
||||
for (size_t tail_done = 0; tail_done < len; ) {
|
||||
tail_done += 32;
|
||||
|
|
@ -359,6 +520,7 @@ uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed) {
|
|||
z += w.second + Fetch64(s + len - tail_done);
|
||||
w.second += v.first;
|
||||
v = WeakHashLen32WithSeeds(s + len - tail_done, v.first + z, v.second);
|
||||
v.first *= k0;
|
||||
}
|
||||
// At this point our 56 bytes of state should contain more than
|
||||
// enough information for a strong 128-bit hash. We use two
|
||||
|
|
@ -370,23 +532,14 @@ uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed) {
|
|||
}
|
||||
|
||||
uint128 city_hash128(const char *s, size_t len) {
|
||||
if (len >= 16) {
|
||||
return CityHash128WithSeed(s + 16,
|
||||
len - 16,
|
||||
uint128(Fetch64(s) ^ k3,
|
||||
Fetch64(s + 8)));
|
||||
} else if (len >= 8) {
|
||||
return CityHash128WithSeed(NULL,
|
||||
0,
|
||||
uint128(Fetch64(s) ^ (len * k0),
|
||||
Fetch64(s + len - 8) ^ k1));
|
||||
} else {
|
||||
return CityHash128WithSeed(s, len, uint128(k0, k1));
|
||||
}
|
||||
return len >= 16 ?
|
||||
CityHash128WithSeed(s + 16, len - 16,
|
||||
uint128(Fetch64(s), Fetch64(s + 8) + k0)) :
|
||||
CityHash128WithSeed(s, len, uint128(k0, k1));
|
||||
}
|
||||
|
||||
//#ifdef __SSE4_2__
|
||||
//#include "citycrc.h"
|
||||
//#include <citycrc.h>
|
||||
//#include <nmmintrin.h>
|
||||
|
||||
// Requires len >= 240.
|
||||
|
|
@ -397,60 +550,79 @@ static void CityHashCrc256Long(const char *s, size_t len,
|
|||
uint64_t c = result[0] = HashLen16(b, len);
|
||||
uint64_t d = result[1] = Fetch64(s + 120) * k0 + len;
|
||||
uint64_t e = Fetch64(s + 184) + seed;
|
||||
uint64_t f = seed;
|
||||
uint64_t f = 0;
|
||||
uint64_t g = 0;
|
||||
uint64_t h = 0;
|
||||
uint64_t i = 0;
|
||||
uint64_t j = 0;
|
||||
uint64_t t = c + d;
|
||||
uint64_t h = c + d;
|
||||
uint64_t x = seed;
|
||||
uint64_t y = 0;
|
||||
uint64_t z = 0;
|
||||
|
||||
// 240 bytes of input per iter.
|
||||
size_t iters = len / 240;
|
||||
len -= iters * 240;
|
||||
do {
|
||||
#define CHUNK(multiplier, z) \
|
||||
{ \
|
||||
uint64_t old_a = a; \
|
||||
a = Rotate(b, 41 ^ z) * multiplier + Fetch64(s); \
|
||||
b = Rotate(c, 27 ^ z) * multiplier + Fetch64(s + 8); \
|
||||
c = Rotate(d, 41 ^ z) * multiplier + Fetch64(s + 16); \
|
||||
d = Rotate(e, 33 ^ z) * multiplier + Fetch64(s + 24); \
|
||||
e = Rotate(t, 25 ^ z) * multiplier + Fetch64(s + 32); \
|
||||
t = old_a; \
|
||||
} \
|
||||
f = _mm_crc32_u64(f, a); \
|
||||
g = _mm_crc32_u64(g, b); \
|
||||
h = _mm_crc32_u64(h, c); \
|
||||
i = _mm_crc32_u64(i, d); \
|
||||
j = _mm_crc32_u64(j, e); \
|
||||
#undef CHUNK
|
||||
#define CHUNK(r) \
|
||||
PERMUTE3(x, z, y); \
|
||||
b += Fetch64(s); \
|
||||
c += Fetch64(s + 8); \
|
||||
d += Fetch64(s + 16); \
|
||||
e += Fetch64(s + 24); \
|
||||
f += Fetch64(s + 32); \
|
||||
a += b; \
|
||||
h += f; \
|
||||
b += c; \
|
||||
f += d; \
|
||||
g += e; \
|
||||
e += z; \
|
||||
g += x; \
|
||||
z = _mm_crc32_u64(z, b + g); \
|
||||
y = _mm_crc32_u64(y, e + h); \
|
||||
x = _mm_crc32_u64(x, f + a); \
|
||||
e = Rotate(e, r); \
|
||||
c += e; \
|
||||
s += 40
|
||||
|
||||
CHUNK(1, 1); CHUNK(k0, 0);
|
||||
CHUNK(1, 1); CHUNK(k0, 0);
|
||||
CHUNK(1, 1); CHUNK(k0, 0);
|
||||
CHUNK(0); PERMUTE3(a, h, c);
|
||||
CHUNK(33); PERMUTE3(a, h, f);
|
||||
CHUNK(0); PERMUTE3(b, h, f);
|
||||
CHUNK(42); PERMUTE3(b, h, d);
|
||||
CHUNK(0); PERMUTE3(b, h, e);
|
||||
CHUNK(33); PERMUTE3(a, h, e);
|
||||
} while (--iters > 0);
|
||||
|
||||
while (len >= 40) {
|
||||
CHUNK(k0, 0);
|
||||
CHUNK(29);
|
||||
e ^= Rotate(a, 20);
|
||||
h += Rotate(b, 30);
|
||||
g ^= Rotate(c, 40);
|
||||
f += Rotate(d, 34);
|
||||
PERMUTE3(c, h, g);
|
||||
len -= 40;
|
||||
}
|
||||
if (len > 0) {
|
||||
s = s + len - 40;
|
||||
CHUNK(k0, 0);
|
||||
CHUNK(33);
|
||||
e ^= Rotate(a, 43);
|
||||
h += Rotate(b, 42);
|
||||
g ^= Rotate(c, 41);
|
||||
f += Rotate(d, 40);
|
||||
}
|
||||
j += i << 32;
|
||||
a = HashLen16(a, j);
|
||||
h += g << 32;
|
||||
b += h;
|
||||
c = HashLen16(c, f) + i;
|
||||
result[0] ^= h;
|
||||
result[1] ^= g;
|
||||
g += h;
|
||||
a = HashLen16(a, g + z);
|
||||
x += y << 32;
|
||||
b += x;
|
||||
c = HashLen16(c, z) + h;
|
||||
d = HashLen16(d, e + result[0]);
|
||||
j += e;
|
||||
i += HashLen16(h, t);
|
||||
e = HashLen16(a, d) + j;
|
||||
f = HashLen16(b, c) + a;
|
||||
g = HashLen16(j, i) + c;
|
||||
result[0] = e + f + g + h;
|
||||
a = ShiftMix((a + g) * k0) * k0 + b;
|
||||
g += e;
|
||||
h += HashLen16(x, f);
|
||||
e = HashLen16(a, d) + g;
|
||||
z = HashLen16(b, c) + a;
|
||||
y = HashLen16(g, h) + c;
|
||||
result[0] = e + z + y + x;
|
||||
a = ShiftMix((a + y) * k0) * k0 + b;
|
||||
result[1] += a + result[0];
|
||||
a = ShiftMix(a * k0) * k0 + c;
|
||||
result[2] = a + result[1];
|
||||
|
|
@ -473,9 +645,10 @@ void CityHashCrc256(const char *s, size_t len, uint64_t *result) {
|
|||
CityHashCrc256Short(s, len, result);
|
||||
}
|
||||
}
|
||||
fc::array<uint64_t,4> city_hash_crc_256(const char *s, size_t len)
|
||||
|
||||
array<uint64_t,4> city_hash_crc_256(const char *s, size_t len)
|
||||
{
|
||||
fc::array<uint64_t,4> buf;
|
||||
array<uint64_t,4> buf;
|
||||
CityHashCrc256( s, len, (uint64_t*)&buf );
|
||||
return buf;
|
||||
}
|
||||
|
|
@ -502,6 +675,7 @@ uint128 city_hash_crc_128(const char *s, size_t len) {
|
|||
return uint128(result[2], result[3]);
|
||||
}
|
||||
}
|
||||
} // namespace fc
|
||||
|
||||
} // end namespace fc
|
||||
|
||||
//#endif
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ namespace fc {
|
|||
|
||||
void temp_file_base::remove()
|
||||
{
|
||||
if (_path)
|
||||
if (_path.valid())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
11
src/git_revision.cpp.in
Normal file
11
src/git_revision.cpp.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <fc/git_revision.hpp>
|
||||
|
||||
#define FC_GIT_REVISION_SHA "@FC_GIT_REVISION_SHA@"
|
||||
#define FC_GIT_REVISION_UNIX_TIMESTAMP @FC_GIT_REVISION_UNIX_TIMESTAMP@
|
||||
|
||||
namespace fc {
|
||||
|
||||
const char* const git_revision_sha = FC_GIT_REVISION_SHA;
|
||||
const uint32_t git_revision_unix_timestamp = FC_GIT_REVISION_UNIX_TIMESTAMP;
|
||||
|
||||
} // end namespace fc
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
//#include <utfcpp/utf8.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
|
@ -42,7 +43,6 @@ namespace fc
|
|||
FC_THROW_EXCEPTION( parse_error_exception, "Expected '\\'" );
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void skip_white_space( T& in )
|
||||
{
|
||||
|
|
@ -104,11 +104,6 @@ namespace fc
|
|||
{
|
||||
char c = in.peek();
|
||||
|
||||
// if( c != ' ' )
|
||||
// FC_THROW_EXCEPTION( parse_error_exception,
|
||||
// "Expected '\"' but read '${char}'",
|
||||
// ("char", string(&c, (&c) + 1) ) );
|
||||
// in.get();
|
||||
while( true )
|
||||
{
|
||||
switch( c = in.peek() )
|
||||
|
|
@ -118,15 +113,20 @@ namespace fc
|
|||
break;
|
||||
case '\t':
|
||||
case ' ':
|
||||
case '\0':
|
||||
case '\n':
|
||||
in.get();
|
||||
return token.str();
|
||||
default:
|
||||
if( isalnum( c ) || c == '_' || c == '-' || c == '.' || c == ':' || c == '/' )
|
||||
{
|
||||
token << c;
|
||||
in.get();
|
||||
}
|
||||
else return token.str();
|
||||
}
|
||||
// FC_THROW_EXCEPTION( parse_error_exception, "EOF before closing '\"' in string '${token}'",
|
||||
// ("token", token.str() ) );
|
||||
}
|
||||
return token.str();
|
||||
}
|
||||
catch( const fc::eof_exception& eof )
|
||||
{
|
||||
|
|
@ -175,8 +175,10 @@ namespace fc
|
|||
return obj;
|
||||
}
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "Expected '}' after ${variant}", ("variant", obj ) );
|
||||
|
||||
|
||||
}
|
||||
catch( const fc::eof_exception& e )
|
||||
{
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.to_detail_string() ) );
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" );
|
||||
}
|
||||
|
||||
|
|
@ -247,6 +249,10 @@ namespace fc
|
|||
ss.put( in.get() );
|
||||
break;
|
||||
default:
|
||||
if( isalnum( c ) )
|
||||
{
|
||||
return ss.str() + stringFromToken( in );
|
||||
}
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -267,13 +273,15 @@ namespace fc
|
|||
template<typename T>
|
||||
variant token_from_stream( T& in )
|
||||
{
|
||||
fc::stringstream ss;
|
||||
bool parsed_unexpected_character = false;
|
||||
std::stringstream ss;
|
||||
ss.exceptions( std::ifstream::badbit );
|
||||
bool received_eof = false;
|
||||
bool done = false;
|
||||
|
||||
try
|
||||
{
|
||||
char c;
|
||||
while((c = in.peek()) && !parsed_unexpected_character)
|
||||
while((c = in.peek()) && !done)
|
||||
{
|
||||
switch( c )
|
||||
{
|
||||
|
|
@ -289,7 +297,7 @@ namespace fc
|
|||
ss.put( in.get() );
|
||||
break;
|
||||
default:
|
||||
parsed_unexpected_character = true;
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -302,22 +310,29 @@ namespace fc
|
|||
// we can get here either by processing a delimiter as in "null,"
|
||||
// an EOF like "null<EOF>", or an invalid token like "nullZ"
|
||||
fc::string str = ss.str();
|
||||
if( str == "null" ) return variant();
|
||||
if( str == "true" ) return true;
|
||||
if( str == "false" ) return false;
|
||||
if( str == "null" )
|
||||
return variant();
|
||||
if( str == "true" )
|
||||
return true;
|
||||
if( str == "false" )
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if (received_eof)
|
||||
{
|
||||
if (str.empty())
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF" );
|
||||
else
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
// I'm not sure why we do this, a comment would be helpful.
|
||||
// if we've reached this point, we've either seen a partial
|
||||
// token ("tru<EOF>") or something our simple parser couldn't
|
||||
// make out ("falfe")
|
||||
return str;
|
||||
// FC_THROW_EXCEPTION( parse_error_exception, "Invalid token '${token}'",
|
||||
// ("token",str) );
|
||||
// A strict JSON parser would signal this as an error, but we
|
||||
// will just treat the malformed token as an un-quoted string.
|
||||
return str + stringFromToken(in);;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -375,9 +390,10 @@ namespace fc
|
|||
}
|
||||
return variant();
|
||||
}
|
||||
variant json::from_string( const fc::string& utf8_str )
|
||||
variant json::from_string( const std::string& utf8_str )
|
||||
{
|
||||
fc::stringstream in( utf8_str );
|
||||
std::stringstream in( utf8_str );
|
||||
in.exceptions( std::ifstream::eofbit );
|
||||
return variant_from_stream( in );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ namespace fc {
|
|||
public:
|
||||
impl( fc::string&s )
|
||||
:ss( s )
|
||||
{ }
|
||||
{ ss.exceptions( std::stringstream::badbit ); }
|
||||
|
||||
impl( const fc::string&s )
|
||||
:ss( s )
|
||||
{ }
|
||||
impl(){}
|
||||
{ ss.exceptions( std::stringstream::badbit ); }
|
||||
|
||||
impl(){ss.exceptions( std::stringstream::badbit ); }
|
||||
|
||||
std::stringstream ss;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <fc/reflect/variant.hpp>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <fc/filesystem.hpp>
|
||||
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -25,8 +26,10 @@ namespace fc {
|
|||
{
|
||||
try {
|
||||
my->cfg = args.as<config>();
|
||||
fc::create_directories( fc::path( my->cfg.filename.string() ).parent_path() );
|
||||
my->out.open( my->cfg.filename.string().c_str() );
|
||||
} catch ( ... ) {
|
||||
std::cerr << "error opening log file: " << my->cfg.filename.string() << "\n";
|
||||
//elog( "%s", fc::except_str().c_str() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ namespace fc {
|
|||
auto lgr = logger::get( cfg.loggers[i].name );
|
||||
|
||||
// TODO: finish configure logger here...
|
||||
if( cfg.loggers[i].parent ) {
|
||||
if( cfg.loggers[i].parent.valid() ) {
|
||||
lgr.set_parent( logger::get( *cfg.loggers[i].parent ) );
|
||||
}
|
||||
lgr.set_name(cfg.loggers[i].name);
|
||||
if( cfg.loggers[i].level ) lgr.set_log_level( *cfg.loggers[i].level );
|
||||
if( cfg.loggers[i].level.valid() ) lgr.set_log_level( *cfg.loggers[i].level );
|
||||
|
||||
|
||||
for( auto a = cfg.loggers[i].appenders.begin(); a != cfg.loggers[i].appenders.end(); ++a ){
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace fc
|
|||
_path = fc::path( "/" ) / _lpath;
|
||||
#endif
|
||||
fc::getline( ss, _largs );
|
||||
if( _args && _args->size() )
|
||||
if( _args.valid() && _args->size() )
|
||||
{
|
||||
// TODO: args = fc::move(_args);
|
||||
}
|
||||
|
|
@ -88,16 +88,16 @@ namespace fc
|
|||
{
|
||||
fc::stringstream ss;
|
||||
ss<<my->_proto<<"://";
|
||||
if( my->_user ) {
|
||||
if( my->_user.valid() ) {
|
||||
ss << *my->_user;
|
||||
if( my->_pass ) {
|
||||
if( my->_pass.valid() ) {
|
||||
ss<<":"<<*my->_pass;
|
||||
}
|
||||
ss<<"@";
|
||||
}
|
||||
if( my->_host ) ss<<*my->_host;
|
||||
if( my->_port ) ss<<":"<<*my->_port;
|
||||
if( my->_path ) ss<<my->_path->generic_string();
|
||||
if( my->_host.valid() ) ss<<*my->_host;
|
||||
if( my->_port.valid() ) ss<<":"<<*my->_port;
|
||||
if( my->_path.valid() ) ss<<my->_path->generic_string();
|
||||
// if( my->_args ) ss<<"?"<<*my->_args;
|
||||
return ss.str();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue