diff --git a/CMakeLists.txt b/CMakeLists.txt index bad2407..e391325 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,11 +141,11 @@ ENDIF(WIN32) FIND_PACKAGE(Boost CONFIG COMPONENTS ${BOOST_COMPONENTS}) IF(NOT WIN32) - MESSAGE(STATUS "Configuring fc to build on Unix/Apple") + MESSAGE(STATUS "Configuring fc to build on Unix/Apple") - if(NOT APPLE) - SET(rt_library rt) - endif(NOT APPLE) + IF(NOT APPLE AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") + SET(rt_library rt ) + ENDIF(NOT APPLE AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") ENDIF(NOT WIN32) IF($ENV{OPENSSL_ROOT_DIR}) diff --git a/include/fc/string.hpp b/include/fc/string.hpp index 7fbe2e5..8f269f0 100644 --- a/include/fc/string.hpp +++ b/include/fc/string.hpp @@ -17,7 +17,7 @@ namespace fc std::string to_pretty_string( int64_t ); inline std::string to_string( int32_t v ) { return to_string( int64_t(v) ); } inline std::string to_string( uint32_t v ){ return to_string( uint64_t(v) ); } -#ifdef __APPLE__ +#if defined(__APPLE__) or defined(__OpenBSD__) inline std::string to_string( size_t s) { return to_string(uint64_t(s)); } #endif diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index f7ef613..66c422e 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -153,7 +153,7 @@ namespace fc void to_variant( const uint128_t& var, variant& vo, uint32_t max_depth = 1 ); void from_variant( const variant& var, uint128_t& vo, uint32_t max_depth = 1 ); - #ifdef __APPLE__ + #if defined(__APPLE__) or defined(__OpenBSD__) void to_variant( size_t s, variant& v, uint32_t max_depth = 1 ); #elif !defined(_WIN32) void to_variant( long long int s, variant& v, uint32_t max_depth = 1 ); @@ -229,7 +229,7 @@ namespace fc variant( uint32_t val, uint32_t max_depth = 1 ); variant( int32_t val, uint32_t max_depth = 1 ); variant( uint64_t val, uint32_t max_depth = 1 ); -#ifdef __APPLE__ +#if defined(__APPLE__) or defined(__OpenBSD__) variant( size_t val, uint32_t max_depth = 1 ); #endif variant( int64_t val, uint32_t max_depth = 1 ); @@ -632,7 +632,7 @@ namespace fc template void to_variant( const safe& s, variant& v, uint32_t max_depth ) { - to_variant( s.value, v, max_depth ); + to_variant( static_cast(s.value), v, max_depth ); } template diff --git a/src/crypto/elliptic_common.cpp b/src/crypto/elliptic_common.cpp index dd89c3a..8e4f802 100644 --- a/src/crypto/elliptic_common.cpp +++ b/src/crypto/elliptic_common.cpp @@ -7,8 +7,6 @@ #ifdef _WIN32 # include -#else -# include #endif /* stuff common to all ecc implementations */ @@ -231,12 +229,11 @@ namespace fc { namespace ecc { static std::string _to_base58( const extended_key_data& key ) { - size_t buf_len = key.size() + 4; - char *buffer = (char*)alloca(buf_len); + char buffer[key.size() + 4]; // it's a small static array => allocate on stack memcpy( buffer, key.data(), key.size() ); - fc::sha256 double_hash = fc::sha256::hash( fc::sha256::hash( (char*) key.data(), key.size() )); + fc::sha256 double_hash = fc::sha256::hash( fc::sha256::hash( (char*)key.data(), key.size() )); memcpy( buffer + key.size(), double_hash.data(), 4 ); - return fc::to_base58( buffer, buf_len ); + return fc::to_base58( buffer, sizeof(buffer) ); } static void _parse_extended_data( unsigned char* buffer, std::string base58 ) diff --git a/src/crypto/elliptic_secp256k1.cpp b/src/crypto/elliptic_secp256k1.cpp index b180d44..11969fc 100644 --- a/src/crypto/elliptic_secp256k1.cpp +++ b/src/crypto/elliptic_secp256k1.cpp @@ -14,8 +14,6 @@ #if _WIN32 # include -#else -# include #endif #include "_elliptic_impl_priv.hpp" diff --git a/src/crypto/openssl.cpp b/src/crypto/openssl.cpp index 3f8df03..e4c0e88 100644 --- a/src/crypto/openssl.cpp +++ b/src/crypto/openssl.cpp @@ -39,7 +39,11 @@ namespace fc ~openssl_scope() { +#if not defined(LIBRESSL_VERSION_NUMBER) + // No FIPS in LibreSSL. + // https://marc.info/?l=openbsd-misc&m=139819485423701&w=2 FIPS_mode_set(0); +#endif CONF_modules_unload(1); EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); diff --git a/src/network/tcp_socket.cpp b/src/network/tcp_socket.cpp index 0012ba6..1152496 100644 --- a/src/network/tcp_socket.cpp +++ b/src/network/tcp_socket.cpp @@ -11,6 +11,13 @@ # include #endif +#if defined __OpenBSD__ +# include +# include +# include +# include +#endif + namespace fc { namespace detail @@ -186,16 +193,37 @@ namespace fc { if (setsockopt(my->_sock.native_handle(), IPPROTO_TCP, #if defined( __APPLE__ ) TCP_KEEPALIVE, + #elif defined( __OpenBSD__ ) + SO_KEEPALIVE, #else TCP_KEEPIDLE, #endif (char*)&timeout_sec, sizeof(timeout_sec)) < 0) wlog("Error setting TCP keepalive idle time"); -# if !defined(__APPLE__) || defined(TCP_KEEPINTVL) // TCP_KEEPINTVL not defined before 10.9 +# if defined(__OpenBSD__) + int name[4]; + name[0] = CTL_NET; + name[1] = PF_INET; + name[2] = IPPROTO_TCP; + + int value; + size_t sz; + + // get tics per second + name[3] = TCPCTL_SLOWHZ; + if (sysctl(name, 4, &value, &sz, NULL, 0) == -1) + wlog("Error setting TCP keepalive interval"); + + // set interval + value *= timeout_sec; + name[3] = TCPCTL_KEEPINTVL; + if (sysctl(name, 4, NULL, NULL, &value, sizeof(value)) == -1) + wlog("Error setting TCP keepalive interval"); +# elif !defined(__APPLE__) || defined(TCP_KEEPINTVL) // TCP_KEEPINTVL not defined before 10.9 if (setsockopt(my->_sock.native_handle(), IPPROTO_TCP, TCP_KEEPINTVL, (char*)&timeout_sec, sizeof(timeout_sec)) < 0) wlog("Error setting TCP keepalive interval"); -# endif // !__APPLE__ || TCP_KEEPINTVL +# endif // (__OpenBSD__) or (!__APPLE__ || TCP_KEEPINTVL) #endif // !WIN32 } else diff --git a/src/stacktrace.cpp b/src/stacktrace.cpp index 126691f..910b48f 100644 --- a/src/stacktrace.cpp +++ b/src/stacktrace.cpp @@ -8,6 +8,9 @@ #if BOOST_VERSION / 100 >= 1065 && !defined(__APPLE__) #include #include +#if defined(__OpenBSD__) + #define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED +#endif #include namespace fc diff --git a/src/variant.cpp b/src/variant.cpp index 7a527e9..eaa12d3 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -11,7 +11,7 @@ #include #include -#ifdef __APPLE__ +#if defined(__APPLE__) or defined(__OpenBSD__) #include #endif @@ -79,7 +79,7 @@ variant::variant( uint64_t val, uint32_t max_depth ) set_variant_type( this, uint64_type ); } -#ifdef __APPLE__ +#if defined(__APPLE__) or defined(__OpenBSD__) variant::variant( size_t val, uint32_t max_depth ) { *reinterpret_cast(this) = val; @@ -679,7 +679,7 @@ void from_variant( const variant& var, std::vector& vo, uint32_t max_depth void to_variant( const uint128_t& var, variant& vo, uint32_t max_depth ) { -#ifdef __APPLE__ +#if defined(__APPLE__) or defined(__OpenBSD__) boost::multiprecision::uint128_t helper = uint128_hi64( var ); helper <<= 64; helper += uint128_lo64( var ); @@ -691,7 +691,7 @@ void to_variant( const uint128_t& var, variant& vo, uint32_t max_depth ) void from_variant( const variant& var, uint128_t& vo, uint32_t max_depth ) { -#ifdef __APPLE__ +#if defined(__APPLE__) or defined(__OpenBSD__) boost::multiprecision::uint128_t helper = boost::lexical_cast( var.as_string() ); vo = static_cast( helper >> 64 ); vo <<= 64; @@ -701,7 +701,9 @@ void from_variant( const variant& var, uint128_t& vo, uint32_t max_depth ) #endif } -#ifdef __APPLE__ +#if defined(__APPLE__) +#elif defined(__OpenBSD__) + void to_variant( size_t s, variant& v, uint32_t max_depth ) { v = variant( int64_t(s) ); } #elif !defined(_WIN32) void to_variant( long long int s, variant& v, uint32_t max_depth ) { v = variant( int64_t(s) ); } void to_variant( unsigned long long int s, variant& v, uint32_t max_depth ) { v = variant( uint64_t(s)); }