Skip to content

Commit 8953737

Browse files
committed
Fix Windows, macOS builds and .deb dependencies
- Guard boost::placeholders with BOOST_VERSION >= 107300 so the code compiles with both old (1.59 from depends) and new Boost. - Switch macOS to depends-based build (like Windows) so it uses Boost 1.59 instead of Homebrew's incompatible Boost 1.90. - Replace hardcoded .deb Depends with dpkg-shlibdeps auto-detection so the package installs on any Debian/Ubuntu version.
1 parent d83ff1d commit 8953737

6 files changed

Lines changed: 104 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ jobs:
7474
# Docs
7575
cp COPYING README.md doc/GENERATE-KEYS.md $PKG/usr/share/doc/faircoin/
7676
77+
# Auto-detect shared library dependencies
78+
AUTODEPS=$(dpkg-shlibdeps -O $PKG/usr/bin/faircoind $PKG/usr/bin/faircoin-cli $PKG/usr/bin/faircoin-tx 2>/dev/null | sed 's/^shlibs:Depends=//')
79+
7780
# Control file
7881
cat > $PKG/DEBIAN/control <<EOF
7982
Package: faircoin
8083
Version: ${VERSION}
8184
Section: net
8285
Priority: optional
8386
Architecture: amd64
84-
Depends: libc6, libssl3, libboost-system1.74.0 | libboost-system1.83.0, libboost-filesystem1.74.0 | libboost-filesystem1.83.0, libboost-thread1.74.0 | libboost-thread1.83.0, libboost-program-options1.74.0 | libboost-program-options1.83.0, libboost-chrono1.74.0 | libboost-chrono1.83.0, libdb5.3++, libminiupnpc17, libevent-2.1-7
87+
Depends: ${AUTODEPS}
8588
Maintainer: FairCoin Official <contact@fairco.in>
8689
Description: FairCoin cryptocurrency daemon and CLI
8790
FairCoin is a cryptocurrency with masternodes, coin mixing,

src/faircoin-cli.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "utilstrencodings.h"
1414

1515
#include <boost/filesystem/operations.hpp>
16+
#include <boost/version.hpp>
1617

1718
#define _(x) std::string(x) /* Keep the _() around in case gettext or such will be used later to translate non-UI */
1819

@@ -108,7 +109,11 @@ Object CallRPC(const string& strMethod, const Array& params)
108109

109110
// Connect to localhost
110111
bool fUseSSL = GetBoolArg("-rpcssl", false);
112+
#if BOOST_VERSION >= 108700
113+
boost::asio::io_context io_service;
114+
#else
111115
asio::io_service io_service;
116+
#endif
112117
ssl::context context(ssl::context::sslv23);
113118
context.set_options(ssl::context::no_sslv2 | ssl::context::no_sslv3);
114119
asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);

src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <boost/filesystem/fstream.hpp>
3737
#include <boost/lexical_cast.hpp>
3838
#include <boost/thread.hpp>
39+
#include <boost/version.hpp>
3940

4041
using namespace boost;
4142
using namespace std;
@@ -204,7 +205,9 @@ struct CMainSignals {
204205

205206
void RegisterValidationInterface(CValidationInterface* pwalletIn)
206207
{
208+
#if BOOST_VERSION >= 107300
207209
using namespace boost::placeholders;
210+
#endif
208211
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
209212
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
210213
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
@@ -215,7 +218,9 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn)
215218

216219
void UnregisterValidationInterface(CValidationInterface* pwalletIn)
217220
{
221+
#if BOOST_VERSION >= 107300
218222
using namespace boost::placeholders;
223+
#endif
219224
g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
220225
g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
221226
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));

src/rpcprotocol.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/asio/ssl.hpp>
1111
#include <boost/iostreams/concepts.hpp>
1212
#include <boost/iostreams/stream.hpp>
13+
#include <boost/version.hpp>
1314
#include <list>
1415
#include <map>
1516
#include <stdint.h>
@@ -111,18 +112,27 @@ class SSLIOStreamDevice : public boost::iostreams::device<boost::iostreams::bidi
111112
{
112113
using namespace boost::asio::ip;
113114
tcp::resolver resolver(static_cast<boost::asio::io_service&>(stream.get_executor().context()));
115+
#if BOOST_VERSION >= 108700
116+
boost::system::error_code resolve_ec;
117+
auto results = resolver.resolve(server, port, resolve_ec);
118+
if (resolve_ec)
119+
return false;
120+
boost::system::error_code error = boost::asio::error::host_not_found;
121+
for (const auto& entry : results) {
122+
stream.lowest_layer().close();
123+
stream.lowest_layer().connect(entry, error);
124+
if (!error)
125+
break;
126+
}
127+
#else
114128
tcp::resolver::iterator endpoint_iterator;
115129
#if BOOST_VERSION >= 104300
116130
try {
117131
#endif
118-
// The default query (flags address_configured) tries IPv6 if
119-
// non-localhost IPv6 configured, and IPv4 if non-localhost IPv4
120-
// configured.
121132
tcp::resolver::query query(server.c_str(), port.c_str());
122133
endpoint_iterator = resolver.resolve(query);
123134
#if BOOST_VERSION >= 104300
124135
} catch (boost::system::system_error& e) {
125-
// If we at first don't succeed, try blanket lookup (IPv4+IPv6 independent of configured interfaces)
126136
tcp::resolver::query query(server.c_str(), port.c_str(), resolver_query_base::flags());
127137
endpoint_iterator = resolver.resolve(query);
128138
}
@@ -133,6 +143,7 @@ class SSLIOStreamDevice : public boost::iostreams::device<boost::iostreams::bidi
133143
stream.lowest_layer().close();
134144
stream.lowest_layer().connect(*endpoint_iterator++, error);
135145
}
146+
#endif
136147
if (error)
137148
return false;
138149
return true;

src/rpcserver.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include <boost/iostreams/stream.hpp>
2828
#include <boost/shared_ptr.hpp>
2929
#include <boost/thread.hpp>
30+
#include <boost/version.hpp>
31+
32+
#if BOOST_VERSION >= 107300
33+
using namespace boost::placeholders;
34+
#endif
3035

3136
using namespace boost;
3237
using namespace boost::asio;
@@ -41,11 +46,19 @@ static std::string rpcWarmupStatus("RPC server started");
4146
static CCriticalSection cs_rpcWarmup;
4247

4348
//! These are created by StartRPCThreads, destroyed in StopRPCThreads
49+
#if BOOST_VERSION >= 108700
50+
static boost::asio::io_context* rpc_io_service = NULL;
51+
static map<string, boost::shared_ptr<boost::asio::steady_timer> > deadlineTimers;
52+
static ssl::context* rpc_ssl_context = NULL;
53+
static boost::thread_group* rpc_worker_group = NULL;
54+
static boost::asio::executor_work_guard<boost::asio::io_context::executor_type>* rpc_dummy_work = NULL;
55+
#else
4456
static asio::io_service* rpc_io_service = NULL;
4557
static map<string, boost::shared_ptr<deadline_timer> > deadlineTimers;
4658
static ssl::context* rpc_ssl_context = NULL;
4759
static boost::thread_group* rpc_worker_group = NULL;
4860
static boost::asio::io_service::work* rpc_dummy_work = NULL;
61+
#endif
4962
static std::vector<CSubNet> rpc_allow_subnets; //!< List of subnets to allow RPC connections from
5063
static std::vector<boost::shared_ptr<ip::tcp::acceptor> > rpc_acceptors;
5164

@@ -409,8 +422,13 @@ CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address)
409422
{
410423
CNetAddr netaddr;
411424
// Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses
425+
#if BOOST_VERSION >= 108700
426+
if (address.is_v6() && address.to_v6().is_v4_mapped())
427+
address = boost::asio::ip::make_address_v4(boost::asio::ip::v4_mapped, address.to_v6());
428+
#else
412429
if (address.is_v6() && (address.to_v6().is_v4_compatible() || address.to_v6().is_v4_mapped()))
413430
address = address.to_v6().to_v4();
431+
#endif
414432

415433
if (address.is_v4()) {
416434
boost::asio::ip::address_v4::bytes_type bytes = address.to_v4().to_bytes();
@@ -435,6 +453,16 @@ template <typename Protocol>
435453
class AcceptedConnectionImpl : public AcceptedConnection
436454
{
437455
public:
456+
#if BOOST_VERSION >= 108700
457+
AcceptedConnectionImpl(
458+
boost::asio::io_context& io_context,
459+
ssl::context& context,
460+
bool fUseSSL) : sslStream(io_context, context),
461+
_d(sslStream, fUseSSL),
462+
_stream(_d)
463+
{
464+
}
465+
#else
438466
AcceptedConnectionImpl(
439467
asio::io_service& io_service,
440468
ssl::context& context,
@@ -443,6 +471,7 @@ class AcceptedConnectionImpl : public AcceptedConnection
443471
_stream(_d)
444472
{
445473
}
474+
#endif
446475

447476
virtual std::iostream& stream()
448477
{
@@ -486,7 +515,11 @@ static void RPCListen(boost::shared_ptr<basic_socket_acceptor<Protocol, SocketAc
486515
const bool fUseSSL)
487516
{
488517
// Accept connection
518+
#if BOOST_VERSION >= 108700
519+
boost::shared_ptr<AcceptedConnectionImpl<Protocol> > conn(new AcceptedConnectionImpl<Protocol>(*rpc_io_service, context, fUseSSL));
520+
#else
489521
boost::shared_ptr<AcceptedConnectionImpl<Protocol> > conn(new AcceptedConnectionImpl<Protocol>(static_cast<boost::asio::io_service&>(acceptor->get_executor().context()), context, fUseSSL));
522+
#endif
490523

491524
acceptor->async_accept(
492525
conn->sslStream.lowest_layer(),
@@ -539,7 +572,11 @@ static ip::tcp::endpoint ParseEndpoint(const std::string& strEndpoint, int defau
539572
std::string addr;
540573
int port = defaultPort;
541574
SplitHostPort(strEndpoint, port, addr);
575+
#if BOOST_VERSION >= 108700
576+
return ip::tcp::endpoint(boost::asio::ip::make_address(addr), port);
577+
#else
542578
return ip::tcp::endpoint(asio::ip::address::from_string(addr), port);
579+
#endif
543580
}
544581

545582
void StartRPCThreads()
@@ -591,7 +628,11 @@ void StartRPCThreads()
591628
}
592629

593630
assert(rpc_io_service == NULL);
631+
#if BOOST_VERSION >= 108700
632+
rpc_io_service = new boost::asio::io_context();
633+
#else
594634
rpc_io_service = new asio::io_service();
635+
#endif
595636
rpc_ssl_context = new ssl::context(ssl::context::sslv23);
596637

597638
const bool fUseSSL = GetBoolArg("-rpcssl", false);
@@ -668,7 +709,11 @@ void StartRPCThreads()
668709
v6_only_error);
669710

670711
acceptor->bind(endpoint);
712+
#if BOOST_VERSION >= 108700
713+
acceptor->listen(boost::asio::socket_base::max_listen_connections);
714+
#else
671715
acceptor->listen(socket_base::max_connections);
716+
#endif
672717

673718
RPCListen(acceptor, *rpc_ssl_context, fUseSSL);
674719

@@ -692,19 +737,30 @@ void StartRPCThreads()
692737

693738
rpc_worker_group = new boost::thread_group();
694739
for (int i = 0; i < GetArg("-rpcthreads", 4); i++)
740+
#if BOOST_VERSION >= 108700
741+
rpc_worker_group->create_thread(boost::bind(&boost::asio::io_context::run, rpc_io_service));
742+
#else
695743
rpc_worker_group->create_thread(boost::bind(&asio::io_service::run, rpc_io_service));
744+
#endif
696745
fRPCRunning = true;
697746
}
698747

699748
void StartDummyRPCThread()
700749
{
701750
if (rpc_io_service == NULL) {
751+
#if BOOST_VERSION >= 108700
752+
rpc_io_service = new boost::asio::io_context();
753+
rpc_dummy_work = new boost::asio::executor_work_guard<boost::asio::io_context::executor_type>(boost::asio::make_work_guard(*rpc_io_service));
754+
rpc_worker_group = new boost::thread_group();
755+
rpc_worker_group->create_thread(boost::bind(&boost::asio::io_context::run, rpc_io_service));
756+
#else
702757
rpc_io_service = new asio::io_service();
703758
/* Create dummy "work" to keep the thread from exiting when no timeouts active,
704759
* see http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/io_service.html#boost_asio.reference.io_service.stopping_the_io_service_from_running_out_of_work */
705760
rpc_dummy_work = new asio::io_service::work(*rpc_io_service);
706761
rpc_worker_group = new boost::thread_group();
707762
rpc_worker_group->create_thread(boost::bind(&asio::io_service::run, rpc_io_service));
763+
#endif
708764
fRPCRunning = true;
709765
}
710766
}
@@ -725,7 +781,11 @@ void StopRPCThreads()
725781
LogPrintf("%s: Warning: %s when cancelling acceptor", __func__, ec.message());
726782
}
727783
rpc_acceptors.clear();
784+
#if BOOST_VERSION >= 108700
785+
BOOST_FOREACH (const PAIRTYPE(std::string, boost::shared_ptr<boost::asio::steady_timer>) & timer, deadlineTimers) {
786+
#else
728787
BOOST_FOREACH (const PAIRTYPE(std::string, boost::shared_ptr<deadline_timer>) & timer, deadlineTimers) {
788+
#endif
729789
timer.second->cancel(ec);
730790
if (ec)
731791
LogPrintf("%s: Warning: %s when cancelling timer", __func__, ec.message());
@@ -783,10 +843,19 @@ void RPCRunLater(const std::string& name, boost::function<void(void)> func, int6
783843
assert(rpc_io_service != NULL);
784844

785845
if (deadlineTimers.count(name) == 0) {
846+
#if BOOST_VERSION >= 108700
847+
deadlineTimers.insert(make_pair(name,
848+
boost::shared_ptr<boost::asio::steady_timer>(new boost::asio::steady_timer(*rpc_io_service))));
849+
#else
786850
deadlineTimers.insert(make_pair(name,
787851
boost::shared_ptr<deadline_timer>(new deadline_timer(*rpc_io_service))));
852+
#endif
788853
}
854+
#if BOOST_VERSION >= 108700
855+
deadlineTimers[name]->expires_after(std::chrono::seconds(nSeconds));
856+
#else
789857
deadlineTimers[name]->expires_from_now(posix_time::seconds(nSeconds));
858+
#endif
790859
deadlineTimers[name]->async_wait(boost::bind(RPCRunHandler, _1, func));
791860
}
792861

src/validationinterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "validationinterface.h"
77

8+
#include <boost/version.hpp>
9+
810
static CMainSignals g_signals;
911

1012
CMainSignals& GetMainSignals()
@@ -13,7 +15,9 @@ CMainSignals& GetMainSignals()
1315
}
1416

1517
void RegisterValidationInterface(CValidationInterface* pwalletIn) {
18+
#if BOOST_VERSION >= 107300
1619
using namespace boost::placeholders;
20+
#endif
1721
g_signals.UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1));
1822
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
1923
g_signals.NotifyTransactionLock.connect(boost::bind(&CValidationInterface::NotifyTransactionLock, pwalletIn, _1));
@@ -27,7 +31,9 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
2731
}
2832

2933
void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
34+
#if BOOST_VERSION >= 107300
3035
using namespace boost::placeholders;
36+
#endif
3137
g_signals.BlockFound.disconnect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1));
3238
g_signals.ScriptForMining.disconnect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
3339
g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));

0 commit comments

Comments
 (0)