Skip to content
This repository was archived by the owner on Dec 29, 2018. It is now read-only.

Commit 1f907fe

Browse files
committed
Merge remote-tracking branch 'bts/master'
2 parents 1a27ef3 + 2405081 commit 1f907fe

30 files changed

+344
-417
lines changed

CMakeLists.txt

+7-16
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ set( fc_sources
281281
src/network/rate_limiting.cpp
282282
src/network/resolve.cpp
283283
src/network/url.cpp
284-
src/compress/smaz.cpp
285284
src/compress/zlib.cpp
286285
)
287286

@@ -367,15 +366,6 @@ else()
367366
set( ZLIB_LIBRARIES "" )
368367
endif( ZLIB_FOUND )
369368

370-
find_package( BZip2 )
371-
if( BZIP2_FOUND )
372-
MESSAGE( STATUS "bzip2 found" )
373-
add_definitions( -DHAS_BZIP2 )
374-
else()
375-
MESSAGE( STATUS "bzip2 not found" )
376-
set( BZIP2_LIBRARIES "" )
377-
endif( BZIP2_FOUND )
378-
379369
# This will become unnecessary once we update to websocketpp which fixes upstream issue #395
380370
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWEBSOCKETPP_STRICT_MASKING")
381371

@@ -406,11 +396,10 @@ target_include_directories(fc
406396
${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp
407397
)
408398

409-
#target_link_libraries( fc PUBLIC ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${ECC_LIB} )
410399
IF(NOT WIN32)
411400
set(LINK_USR_LOCAL_LIB -L/usr/local/lib)
412401
ENDIF()
413-
target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${editline_libraries} ${ECC_LIB} )
402+
target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${editline_libraries} ${ECC_LIB} )
414403

415404
if(MSVC)
416405
set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
@@ -522,10 +511,12 @@ ENDIF()
522511
IF("${OPENSSL_ROOT_DIR}" STREQUAL "")
523512
get_filename_component(OPENSSL_ROOT_DIR "${OPENSSL_INCLUDE_DIR}/.." REALPATH)
524513
ENDIF()
525-
SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/ssl/openssl.cnf")
526-
IF(MINGW)
527-
SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/openssl.cnf")
528-
ENDIF(MINGW)
514+
IF("${OPENSSL_CONF_SOURCE}" STREQUAL "")
515+
SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/ssl/openssl.cnf")
516+
IF(MINGW)
517+
SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/openssl.cnf")
518+
ENDIF(MINGW)
519+
ENDIF()
529520
SET(POST_BUILD_STEP_COMMANDS ${POST_BUILD_STEP_COMMANDS}
530521
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENSSL_CONF_SOURCE}" "${OPENSSL_CONF_TARGET}/openssl.cnf")
531522
ENDIF(WIN32)

include/fc/bloom_filter.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ class bloom_parameters
5757
random_seed(0xA5A5A5A55A5A5A5AULL)
5858
{}
5959

60+
bloom_parameters(unsigned long long int projected_element_count,
61+
double false_positive_probability,
62+
unsigned long long int maximum_size) :
63+
minimum_size(1),
64+
maximum_size(maximum_size),
65+
minimum_number_of_hashes(1),
66+
maximum_number_of_hashes(std::numeric_limits<unsigned int>::max()),
67+
projected_element_count(projected_element_count),
68+
false_positive_probability(false_positive_probability),
69+
random_seed(0xA5A5A5A55A5A5A5AULL)
70+
{
71+
compute_optimal_parameters();
72+
}
73+
6074
virtual ~bloom_parameters()
6175
{}
6276

include/fc/compress/smaz.hpp

-9
This file was deleted.

include/fc/container/flat.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace fc {
1111
inline void pack( Stream& s, const flat_set<T>& value, uint32_t _max_depth ) {
1212
FC_ASSERT( _max_depth > 0 );
1313
--_max_depth;
14-
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
14+
pack( s, unsigned_int(value.size()), _max_depth );
1515
auto itr = value.begin();
1616
auto end = value.end();
1717
while( itr != end ) {
@@ -38,7 +38,7 @@ namespace fc {
3838
inline void pack( Stream& s, const flat_map<K,V...>& value, uint32_t _max_depth ) {
3939
FC_ASSERT( _max_depth > 0 );
4040
--_max_depth;
41-
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
41+
pack( s, unsigned_int(value.size()), _max_depth );
4242
auto itr = value.begin();
4343
auto end = value.end();
4444
while( itr != end ) {
@@ -67,7 +67,7 @@ namespace fc {
6767
void pack( Stream& s, const bip::vector<T,A>& value, uint32_t _max_depth ) {
6868
FC_ASSERT( _max_depth > 0 );
6969
--_max_depth;
70-
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
70+
pack( s, unsigned_int(value.size()), _max_depth );
7171
if( !std::is_fundamental<T>::value ) {
7272
auto itr = value.begin();
7373
auto end = value.end();

include/fc/interprocess/container.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace fc {
116116
inline void pack( Stream& s, const bip::vector<T,A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
117117
FC_ASSERT( _max_depth > 0 );
118118
--_max_depth;
119-
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
119+
pack( s, unsigned_int(value.size()), _max_depth );
120120
auto itr = value.begin();
121121
auto end = value.end();
122122
while( itr != end ) {

include/fc/io/fstream.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#include <fc/shared_ptr.hpp>
33
#include <fc/filesystem.hpp>
44
#include <fc/io/iostream.hpp>
5+
#include <fstream>
56

67
namespace fc {
78
class path;
89
class ofstream : virtual public ostream {
910
public:
10-
enum mode { out, binary };
1111
ofstream();
12-
ofstream( const fc::path& file, int m = binary );
12+
ofstream( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary );
1313
~ofstream();
1414

15-
void open( const fc::path& file, int m = binary );
15+
void open( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary );
1616
size_t writesome( const char* buf, size_t len );
1717
size_t writesome(const std::shared_ptr<const char>& buffer, size_t len, size_t offset);
1818
void put( char c );

include/fc/io/raw.hpp

+13-32
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,6 @@ namespace fc {
158158
fc::raw::unpack( s, *v, _max_depth - 1 );
159159
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<T>", ("type",fc::get_typename<T>::name()) ) }
160160

161-
template<typename Stream> inline void pack( Stream& s, const signed_int& v, uint32_t _max_depth ) {
162-
uint32_t val = (v.value<<1) ^ (v.value>>31);
163-
do {
164-
uint8_t b = uint8_t(val) & 0x7f;
165-
val >>= 7;
166-
b |= ((val > 0) << 7);
167-
s.write((char*)&b,1);//.put(b);
168-
} while( val );
169-
}
170-
171161
template<typename Stream> inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth ) {
172162
uint64_t val = v.value;
173163
do {
@@ -178,25 +168,16 @@ namespace fc {
178168
}while( val );
179169
}
180170

181-
template<typename Stream> inline void unpack( Stream& s, signed_int& vi, uint32_t _max_depth ) {
182-
uint32_t v = 0; char b = 0; int by = 0;
183-
do {
184-
s.get(b);
185-
v |= uint32_t(uint8_t(b) & 0x7f) << by;
186-
by += 7;
187-
} while( uint8_t(b) & 0x80 );
188-
vi.value = ((v>>1) ^ (v>>31)) + (v&0x01);
189-
vi.value = v&0x01 ? vi.value : -vi.value;
190-
vi.value = -vi.value;
191-
}
192171
template<typename Stream> inline void unpack( Stream& s, unsigned_int& vi, uint32_t _max_depth ) {
193172
uint64_t v = 0; char b = 0; uint8_t by = 0;
194173
do {
195174
s.get(b);
196-
v |= uint32_t(uint8_t(b) & 0x7f) << by;
175+
if( by >= 64 || (by == 63 && uint8_t(b) > 1) )
176+
FC_THROW_EXCEPTION( overflow_exception, "Invalid packed unsigned_int!" );
177+
v |= uint64_t(uint8_t(b) & 0x7f) << by;
197178
by += 7;
198179
} while( uint8_t(b) & 0x80 );
199-
vi.value = static_cast<uint32_t>(v);
180+
vi.value = static_cast<uint64_t>(v);
200181
}
201182

202183
template<typename Stream, typename T> inline void unpack( Stream& s, const T& vi, uint32_t _max_depth )
@@ -273,9 +254,9 @@ namespace fc {
273254
// std::vector<char>
274255
template<typename Stream> inline void pack( Stream& s, const std::vector<char>& value, uint32_t _max_depth ) {
275256
FC_ASSERT( _max_depth > 0 );
276-
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 );
257+
fc::raw::pack( s, unsigned_int(value.size()), _max_depth - 1 );
277258
if( value.size() )
278-
s.write( &value.front(), (uint32_t)value.size() );
259+
s.write( &value.front(), value.size() );
279260
}
280261
template<typename Stream> inline void unpack( Stream& s, std::vector<char>& value, uint32_t _max_depth ) {
281262
FC_ASSERT( _max_depth > 0 );
@@ -289,7 +270,7 @@ namespace fc {
289270
// fc::string
290271
template<typename Stream> inline void pack( Stream& s, const fc::string& v, uint32_t _max_depth ) {
291272
FC_ASSERT( _max_depth > 0 );
292-
fc::raw::pack( s, unsigned_int((uint32_t)v.size()), _max_depth - 1 );
273+
fc::raw::pack( s, unsigned_int(v.size()), _max_depth - 1 );
293274
if( v.size() ) s.write( v.c_str(), v.size() );
294275
}
295276

@@ -433,7 +414,7 @@ namespace fc {
433414
inline void pack( Stream& s, const std::unordered_set<T>& value, uint32_t _max_depth ) {
434415
FC_ASSERT( _max_depth > 0 );
435416
--_max_depth;
436-
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
417+
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
437418
auto itr = value.begin();
438419
auto end = value.end();
439420
while( itr != end ) {
@@ -478,7 +459,7 @@ namespace fc {
478459
inline void pack( Stream& s, const std::unordered_map<K,V>& value, uint32_t _max_depth ) {
479460
FC_ASSERT( _max_depth > 0 );
480461
--_max_depth;
481-
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
462+
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
482463
auto itr = value.begin();
483464
auto end = value.end();
484465
while( itr != end ) {
@@ -506,7 +487,7 @@ namespace fc {
506487
inline void pack( Stream& s, const std::map<K,V>& value, uint32_t _max_depth ) {
507488
FC_ASSERT( _max_depth > 0 );
508489
--_max_depth;
509-
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
490+
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
510491
auto itr = value.begin();
511492
auto end = value.end();
512493
while( itr != end ) {
@@ -534,7 +515,7 @@ namespace fc {
534515
inline void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth ) {
535516
FC_ASSERT( _max_depth > 0 );
536517
--_max_depth;
537-
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
518+
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
538519
auto itr = value.begin();
539520
auto end = value.end();
540521
while( itr != end ) {
@@ -562,7 +543,7 @@ namespace fc {
562543
inline void pack( Stream& s, const std::vector<T>& value, uint32_t _max_depth ) {
563544
FC_ASSERT( _max_depth > 0 );
564545
--_max_depth;
565-
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
546+
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
566547
auto itr = value.begin();
567548
auto end = value.end();
568549
while( itr != end ) {
@@ -590,7 +571,7 @@ namespace fc {
590571
inline void pack( Stream& s, const std::set<T>& value, uint32_t _max_depth ) {
591572
FC_ASSERT( _max_depth > 0 );
592573
--_max_depth;
593-
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
574+
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
594575
auto itr = value.begin();
595576
auto end = value.end();
596577
while( itr != end ) {

include/fc/io/raw_fwd.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ namespace fc {
116116
template<typename Stream, typename T> inline void pack( Stream& s, const std::vector<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
117117
template<typename Stream, typename T> inline void unpack( Stream& s, std::vector<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
118118

119-
template<typename Stream> inline void pack( Stream& s, const signed_int& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
120-
template<typename Stream> inline void unpack( Stream& s, signed_int& vi, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
121-
122119
template<typename Stream> inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
123120
template<typename Stream> inline void unpack( Stream& s, unsigned_int& vi, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
124121

include/fc/io/raw_variant.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ namespace fc { namespace raw {
128128
{
129129
FC_ASSERT( _max_depth > 0 );
130130
--_max_depth;
131-
unsigned_int vs = (uint32_t)v.size();
131+
unsigned_int vs = v.size();
132132
pack( s, vs, _max_depth );
133133
for( auto itr = v.begin(); itr != v.end(); ++itr )
134134
{

include/fc/io/varint.hpp

+13-59
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,37 @@
44
namespace fc {
55

66
struct unsigned_int {
7-
unsigned_int( uint32_t v = 0 ):value(v){}
7+
unsigned_int( uint64_t v = 0 ):value(v){}
88

99
template<typename T>
1010
unsigned_int( T v ):value(v){}
1111

12-
//operator uint32_t()const { return value; }
13-
//operator uint64_t()const { return value; }
14-
1512
template<typename T>
1613
operator T()const { return static_cast<T>(value); }
1714

18-
unsigned_int& operator=( int32_t v ) { value = v; return *this; }
15+
unsigned_int& operator=( uint64_t v ) { value = v; return *this; }
1916

20-
uint32_t value;
17+
uint64_t value;
2118

22-
friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return i.value == v; }
23-
friend bool operator==( const uint32_t& i, const unsigned_int& v ) { return i == v.value; }
19+
friend bool operator==( const unsigned_int& i, const uint64_t& v ) { return i.value == v; }
20+
friend bool operator==( const uint64_t& i, const unsigned_int& v ) { return i == v.value; }
2421
friend bool operator==( const unsigned_int& i, const unsigned_int& v ) { return i.value == v.value; }
2522

26-
friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return i.value != v; }
27-
friend bool operator!=( const uint32_t& i, const unsigned_int& v ) { return i != v.value; }
23+
friend bool operator!=( const unsigned_int& i, const uint64_t& v ) { return i.value != v; }
24+
friend bool operator!=( const uint64_t& i, const unsigned_int& v ) { return i != v.value; }
2825
friend bool operator!=( const unsigned_int& i, const unsigned_int& v ) { return i.value != v.value; }
2926

30-
friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return i.value < v; }
31-
friend bool operator<( const uint32_t& i, const unsigned_int& v ) { return i < v.value; }
27+
friend bool operator<( const unsigned_int& i, const uint64_t& v ) { return i.value < v; }
28+
friend bool operator<( const uint64_t& i, const unsigned_int& v ) { return i < v.value; }
3229
friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return i.value < v.value; }
3330

34-
friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return i.value >= v; }
35-
friend bool operator>=( const uint32_t& i, const unsigned_int& v ) { return i >= v.value; }
31+
friend bool operator>=( const unsigned_int& i, const uint64_t& v ) { return i.value >= v; }
32+
friend bool operator>=( const uint64_t& i, const unsigned_int& v ) { return i >= v.value; }
3633
friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; }
3734
};
3835

39-
/**
40-
* @brief serializes a 32 bit signed interger in as few bytes as possible
41-
*
42-
* Uses the google protobuf algorithm for seralizing signed numbers
43-
*/
44-
struct signed_int {
45-
signed_int( int32_t v = 0 ):value(v){}
46-
operator int32_t()const { return value; }
47-
template<typename T>
48-
signed_int& operator=( const T& v ) { value = v; return *this; }
49-
signed_int operator++(int) { return value++; }
50-
signed_int& operator++(){ ++value; return *this; }
51-
52-
int32_t value;
53-
54-
friend bool operator==( const signed_int& i, const int32_t& v ) { return i.value == v; }
55-
friend bool operator==( const int32_t& i, const signed_int& v ) { return i == v.value; }
56-
friend bool operator==( const signed_int& i, const signed_int& v ) { return i.value == v.value; }
57-
58-
friend bool operator!=( const signed_int& i, const int32_t& v ) { return i.value != v; }
59-
friend bool operator!=( const int32_t& i, const signed_int& v ) { return i != v.value; }
60-
friend bool operator!=( const signed_int& i, const signed_int& v ) { return i.value != v.value; }
61-
62-
friend bool operator<( const signed_int& i, const int32_t& v ) { return i.value < v; }
63-
friend bool operator<( const int32_t& i, const signed_int& v ) { return i < v.value; }
64-
friend bool operator<( const signed_int& i, const signed_int& v ) { return i.value < v.value; }
65-
66-
friend bool operator>=( const signed_int& i, const int32_t& v ) { return i.value >= v; }
67-
friend bool operator>=( const int32_t& i, const signed_int& v ) { return i >= v.value; }
68-
friend bool operator>=( const signed_int& i, const signed_int& v ) { return i.value >= v.value; }
69-
};
70-
7136
class variant;
7237

73-
void to_variant( const signed_int& var, variant& vo, uint32_t max_depth = 1 );
74-
void from_variant( const variant& var, signed_int& vo, uint32_t max_depth = 1 );
7538
void to_variant( const unsigned_int& var, variant& vo, uint32_t max_depth = 1 );
7639
void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth = 1 );
7740

@@ -80,22 +43,13 @@ void from_variant( const variant& var, unsigned_int& vo, uint32_t max_depth = 1
8043
#include <unordered_map>
8144
namespace std
8245
{
83-
template<>
84-
struct hash<fc::signed_int>
85-
{
86-
public:
87-
size_t operator()(const fc::signed_int &a) const
88-
{
89-
return std::hash<int32_t>()(a.value);
90-
}
91-
};
9246
template<>
9347
struct hash<fc::unsigned_int>
9448
{
9549
public:
96-
size_t operator()(const fc::signed_int &a) const
50+
size_t operator()(const fc::unsigned_int &a) const
9751
{
98-
return std::hash<uint32_t>()(a.value);
52+
return std::hash<uint64_t>()(a.value);
9953
}
10054
};
10155
}

0 commit comments

Comments
 (0)