├── .dir-locals.el ├── .github └── workflows │ ├── build.yml │ └── release.yml ├── .gitignore ├── AUTHORS ├── Bitcoin ├── Tx.cpp ├── Tx.hpp ├── TxId.cpp ├── TxId.hpp ├── TxIn.cpp ├── TxIn.hpp ├── TxOut.cpp ├── TxOut.hpp ├── WitnessField.cpp ├── WitnessField.hpp ├── addr_to_scriptPubKey.cpp ├── addr_to_scriptPubKey.hpp ├── hash160.cpp ├── hash160.hpp ├── le.cpp ├── le.hpp ├── sighash.cpp ├── sighash.hpp ├── varint.cpp └── varint.hpp ├── Boltz ├── Connection.hpp ├── ConnectionIF.hpp ├── Detail │ ├── ClaimTxHandler.cpp │ ├── ClaimTxHandler.hpp │ ├── FallbackConnection.cpp │ ├── FallbackConnection.hpp │ ├── NormalConnection.cpp │ ├── NormalConnection.hpp │ ├── NullConnection.cpp │ ├── NullConnection.hpp │ ├── ServiceImpl.cpp │ ├── ServiceImpl.hpp │ ├── SwapSetupHandler.cpp │ ├── SwapSetupHandler.hpp │ ├── compute_preimage.cpp │ ├── compute_preimage.hpp │ ├── create_connection.cpp │ ├── create_connection.hpp │ ├── find_lockup_outnum.cpp │ ├── find_lockup_outnum.hpp │ ├── initial_claim_tx.cpp │ ├── initial_claim_tx.hpp │ ├── match_lockscript.cpp │ └── match_lockscript.hpp ├── EnvIF.hpp ├── Service.hpp ├── ServiceFactory.cpp ├── ServiceFactory.hpp └── SwapInfo.hpp ├── Boss ├── JsonInput.cpp ├── JsonInput.hpp ├── Main.cpp ├── Main.hpp ├── Mod │ ├── ActiveProber.cpp │ ├── ActiveProber.hpp │ ├── AmountSettingsHandler.cpp │ ├── AmountSettingsHandler.hpp │ ├── AutoDisconnector.cpp │ ├── AutoDisconnector.hpp │ ├── AvailableRpcCommandsAnnouncer.cpp │ ├── AvailableRpcCommandsAnnouncer.hpp │ ├── BlockTracker.cpp │ ├── BlockTracker.hpp │ ├── BoltzSwapper │ │ ├── Env.cpp │ │ ├── Env.hpp │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ ├── README.md │ │ ├── ServiceCreator.cpp │ │ ├── ServiceCreator.hpp │ │ ├── ServiceModule.cpp │ │ └── ServiceModule.hpp │ ├── ChannelCandidateInvestigator │ │ ├── Gumshoe.cpp │ │ ├── Gumshoe.hpp │ │ ├── Janitor.cpp │ │ ├── Janitor.hpp │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ ├── Manager.cpp │ │ ├── Manager.hpp │ │ ├── README.md │ │ ├── Secretary.cpp │ │ └── Secretary.hpp │ ├── ChannelCandidateMatchmaker.cpp │ ├── ChannelCandidateMatchmaker.hpp │ ├── ChannelCandidatePreinvestigator.cpp │ ├── ChannelCandidatePreinvestigator.hpp │ ├── ChannelCreateDestroyMonitor.cpp │ ├── ChannelCreateDestroyMonitor.hpp │ ├── ChannelCreationDecider.cpp │ ├── ChannelCreationDecider.hpp │ ├── ChannelCreator │ │ ├── Carpenter.cpp │ │ ├── Carpenter.hpp │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ ├── Manager.cpp │ │ ├── Manager.hpp │ │ ├── Planner.cpp │ │ ├── Planner.hpp │ │ ├── README.md │ │ ├── RearrangerBySize.cpp │ │ ├── RearrangerBySize.hpp │ │ ├── Reprioritizer.cpp │ │ └── Reprioritizer.hpp │ ├── ChannelFeeManager.cpp │ ├── ChannelFeeManager.hpp │ ├── ChannelFeeSetter.cpp │ ├── ChannelFeeSetter.hpp │ ├── ChannelFinderByDistance.cpp │ ├── ChannelFinderByDistance.hpp │ ├── ChannelFinderByEarnedFee.cpp │ ├── ChannelFinderByEarnedFee.hpp │ ├── ChannelFinderByListpays.cpp │ ├── ChannelFinderByListpays.hpp │ ├── ChannelFinderByPopularity.cpp │ ├── ChannelFinderByPopularity.hpp │ ├── ChannelFundsComputer.cpp │ ├── ChannelFundsComputer.hpp │ ├── CommandReceiver.cpp │ ├── CommandReceiver.hpp │ ├── ComplainerByLowConnectRate.cpp │ ├── ComplainerByLowConnectRate.hpp │ ├── ComplainerByLowSuccessPerDay.cpp │ ├── ComplainerByLowSuccessPerDay.hpp │ ├── ConnectFinderByDns.cpp │ ├── ConnectFinderByDns.hpp │ ├── ConnectFinderByHardcode.cpp │ ├── ConnectFinderByHardcode.hpp │ ├── Connector.cpp │ ├── Connector.hpp │ ├── ConstructedListpeers.cpp │ ├── ConstructedListpeers.hpp │ ├── Dowser.cpp │ ├── Dowser.hpp │ ├── EarningsRebalancer.cpp │ ├── EarningsRebalancer.hpp │ ├── EarningsTracker.cpp │ ├── EarningsTracker.hpp │ ├── FeeModderByBalance.cpp │ ├── FeeModderByBalance.hpp │ ├── FeeModderByPriceTheory.cpp │ ├── FeeModderByPriceTheory.hpp │ ├── FeeModderBySize.cpp │ ├── FeeModderBySize.hpp │ ├── ForwardFeeMonitor.cpp │ ├── ForwardFeeMonitor.hpp │ ├── FundsMover │ │ ├── Attempter.cpp │ │ ├── Attempter.hpp │ │ ├── Claimer.cpp │ │ ├── Claimer.hpp │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ ├── Runner.cpp │ │ ├── Runner.hpp │ │ ├── create_label.cpp │ │ └── create_label.hpp │ ├── HtlcAcceptor.cpp │ ├── HtlcAcceptor.hpp │ ├── InitialConnect.cpp │ ├── InitialConnect.hpp │ ├── InitialRebalancer.cpp │ ├── InitialRebalancer.hpp │ ├── Initiator.cpp │ ├── Initiator.hpp │ ├── InternetConnectionMonitor.cpp │ ├── InternetConnectionMonitor.hpp │ ├── InvoicePayer.cpp │ ├── InvoicePayer.hpp │ ├── JitRebalancer.cpp │ ├── JitRebalancer.hpp │ ├── JsonOutputter.cpp │ ├── JsonOutputter.hpp │ ├── ListfundsAnalyzer.cpp │ ├── ListfundsAnalyzer.hpp │ ├── ListfundsAnnouncer.cpp │ ├── ListfundsAnnouncer.hpp │ ├── ListpaysHandler.cpp │ ├── ListpaysHandler.hpp │ ├── ListpeersAnalyzer.cpp │ ├── ListpeersAnalyzer.hpp │ ├── ListpeersAnnouncer.cpp │ ├── ListpeersAnnouncer.hpp │ ├── Manifester.cpp │ ├── Manifester.hpp │ ├── MoveFundsCommand.cpp │ ├── MoveFundsCommand.hpp │ ├── NeedsConnectSolicitor.cpp │ ├── NeedsConnectSolicitor.hpp │ ├── NeedsOnchainFundsSwapper.cpp │ ├── NeedsOnchainFundsSwapper.hpp │ ├── NewaddrHandler.cpp │ ├── NewaddrHandler.hpp │ ├── NodeBalanceSwapper.cpp │ ├── NodeBalanceSwapper.hpp │ ├── OnchainFeeMonitor.cpp │ ├── OnchainFeeMonitor.hpp │ ├── OnchainFundsAnnouncer.cpp │ ├── OnchainFundsAnnouncer.hpp │ ├── OnchainFundsIgnorer.cpp │ ├── OnchainFundsIgnorer.hpp │ ├── PaymentDeleter.cpp │ ├── PaymentDeleter.hpp │ ├── PeerCompetitorFeeMonitor │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ ├── README.md │ │ ├── Surveyor.cpp │ │ └── Surveyor.hpp │ ├── PeerComplaintsDesk │ │ ├── Exempter.cpp │ │ ├── Exempter.hpp │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ ├── Recorder.cpp │ │ ├── Recorder.hpp │ │ ├── Unmanager.cpp │ │ └── Unmanager.hpp │ ├── PeerFromScidMapper.cpp │ ├── PeerFromScidMapper.hpp │ ├── PeerJudge │ │ ├── AgeTracker.cpp │ │ ├── AgeTracker.hpp │ │ ├── Algo.cpp │ │ ├── Algo.hpp │ │ ├── DataGatherer.cpp │ │ ├── DataGatherer.hpp │ │ ├── Executioner.cpp │ │ ├── Executioner.hpp │ │ ├── Info.hpp │ │ ├── README.md │ │ ├── Unmanager.cpp │ │ └── Unmanager.hpp │ ├── PeerMetrician.cpp │ ├── PeerMetrician.hpp │ ├── PeerStatistician.cpp │ ├── PeerStatistician.hpp │ ├── README.md │ ├── RebalanceUnmanager.cpp │ ├── RebalanceUnmanager.hpp │ ├── Reconnector.cpp │ ├── Reconnector.hpp │ ├── RegularActiveProbe.cpp │ ├── RegularActiveProbe.hpp │ ├── Rpc.cpp │ ├── Rpc.hpp │ ├── RpcWrapper.cpp │ ├── RpcWrapper.hpp │ ├── SelfUptimeMonitor.cpp │ ├── SelfUptimeMonitor.hpp │ ├── SendpayResultMonitor.cpp │ ├── SendpayResultMonitor.hpp │ ├── StatusCommand.cpp │ ├── StatusCommand.hpp │ ├── SwapManager.cpp │ ├── SwapManager.hpp │ ├── SwapReporter.cpp │ ├── SwapReporter.hpp │ ├── TimerTwiceDailyAnnouncer.cpp │ ├── TimerTwiceDailyAnnouncer.hpp │ ├── Timers.cpp │ ├── Timers.hpp │ ├── UnmanagedManager.cpp │ ├── UnmanagedManager.hpp │ ├── Waiter.cpp │ ├── Waiter.hpp │ ├── all.cpp │ └── all.hpp ├── ModG │ ├── Detail │ │ ├── ReqRespBase.cpp │ │ └── ReqRespBase.hpp │ ├── RebalanceUnmanagerProxy.hpp │ ├── ReqResp.hpp │ ├── RpcProxy.cpp │ ├── RpcProxy.hpp │ ├── Swapper.cpp │ └── Swapper.hpp ├── Msg │ ├── AcceptSwapQuotation.hpp │ ├── AmountSettings.hpp │ ├── AvailableRpcCommands.hpp │ ├── Begin.hpp │ ├── Block.hpp │ ├── ChannelCreateResult.hpp │ ├── ChannelCreation.hpp │ ├── ChannelDestruction.hpp │ ├── ChannelFunds.hpp │ ├── CommandFail.hpp │ ├── CommandRequest.hpp │ ├── CommandResponse.hpp │ ├── DbResource.hpp │ ├── EndOfOptions.hpp │ ├── ForwardFee.hpp │ ├── Init.hpp │ ├── InternetOnline.hpp │ ├── JsonCin.hpp │ ├── JsonCout.hpp │ ├── ListfundsAnalyzedResult.hpp │ ├── ListfundsResult.hpp │ ├── ListpeersAnalyzedResult.hpp │ ├── ListpeersResult.hpp │ ├── ManifestCommand.hpp │ ├── ManifestHook.hpp │ ├── ManifestNotification.hpp │ ├── ManifestOption.hpp │ ├── Manifestation.hpp │ ├── NeedsConnect.hpp │ ├── NeedsOnchainFunds.hpp │ ├── Network.hpp │ ├── Notification.hpp │ ├── OnchainFee.hpp │ ├── OnchainFunds.hpp │ ├── Option.hpp │ ├── OptionType.hpp │ ├── PatronizeChannelCandidate.hpp │ ├── PayInvoice.hpp │ ├── PeerMedianChannelFee.hpp │ ├── PeerMetrics.hpp │ ├── PeerStatistics.hpp │ ├── PreinvestigateChannelCandidates.hpp │ ├── ProbeActively.hpp │ ├── ProposeChannelCandidates.hpp │ ├── ProposeConnectCandidates.hpp │ ├── ProposePatronlessChannelCandidate.hpp │ ├── ProvideChannelFeeModifier.hpp │ ├── ProvideDeletablePaymentLabelFilter.hpp │ ├── ProvideHtlcAcceptedDeferrer.hpp │ ├── ProvideStatus.hpp │ ├── ProvideSwapQuotation.hpp │ ├── ProvideUnmanagement.hpp │ ├── RaisePeerComplaint.hpp │ ├── ReleaseHtlcAccepted.hpp │ ├── ReqRespTraits.hpp │ ├── RequestChannelCreation.hpp │ ├── RequestConnect.hpp │ ├── RequestDowser.hpp │ ├── RequestEarningsInfo.hpp │ ├── RequestGetOnchainIgnoreFlag.hpp │ ├── RequestListpays.hpp │ ├── RequestMoveFunds.hpp │ ├── RequestNewaddr.hpp │ ├── RequestPeerFromScid.hpp │ ├── RequestPeerMetrics.hpp │ ├── RequestPeerStatistics.hpp │ ├── RequestRebalanceUnmanaged.hpp │ ├── RequestRpcCommand.hpp │ ├── RequestSelfUptime.hpp │ ├── ResponseConnect.hpp │ ├── ResponseDowser.hpp │ ├── ResponseEarningsInfo.hpp │ ├── ResponseGetOnchainIgnoreFlag.hpp │ ├── ResponseListpays.hpp │ ├── ResponseMoveFunds.hpp │ ├── ResponseNewaddr.hpp │ ├── ResponsePeerFromScid.hpp │ ├── ResponsePeerMetrics.hpp │ ├── ResponsePeerStatistics.hpp │ ├── ResponseRebalanceUnmanaged.hpp │ ├── ResponseRpcCommand.hpp │ ├── ResponseSelfUptime.hpp │ ├── RpcCommandHook.hpp │ ├── SendpayResult.hpp │ ├── SetChannelFee.hpp │ ├── SolicitChannelCandidates.hpp │ ├── SolicitChannelFeeModifier.hpp │ ├── SolicitConnectCandidates.hpp │ ├── SolicitDeletablePaymentLabelFilter.hpp │ ├── SolicitHtlcAcceptedDeferrer.hpp │ ├── SolicitPeerComplaints.hpp │ ├── SolicitStatus.hpp │ ├── SolicitSwapQuotation.hpp │ ├── SolicitUnmanagement.hpp │ ├── StatusListpays.hpp │ ├── SwapCompleted.hpp │ ├── SwapCreation.hpp │ ├── SwapRequest.hpp │ ├── SwapResponse.hpp │ ├── TaskCompletion.hpp │ ├── Timer10Minutes.hpp │ ├── TimerRandomDaily.hpp │ ├── TimerRandomHourly.hpp │ └── TimerTwiceDaily.hpp ├── Shutdown.hpp ├── Signer.cpp ├── Signer.hpp ├── concurrent.cpp ├── concurrent.hpp ├── log.cpp ├── log.hpp ├── open_rpc_socket.cpp ├── open_rpc_socket.hpp ├── random_engine.cpp └── random_engine.hpp ├── CHANGELOG.md ├── COPYING ├── ChangeLog ├── DnsSeed ├── Detail │ ├── decode_bech32_node.cpp │ ├── decode_bech32_node.hpp │ ├── parse_dig_srv.cpp │ └── parse_dig_srv.hpp ├── get.cpp └── get.hpp ├── Ev ├── Io.hpp ├── README.md ├── Semaphore.cpp ├── Semaphore.hpp ├── ThreadPool.cpp ├── ThreadPool.hpp ├── concurrent.cpp ├── concurrent.hpp ├── foreach.hpp ├── map.hpp ├── memoize.hpp ├── now.cpp ├── now.hpp ├── runcmd.cpp ├── runcmd.hpp ├── start.cpp ├── start.hpp ├── yield.cpp └── yield.hpp ├── Graph ├── Dijkstra.hpp └── TreeNode.hpp ├── Jsmn ├── Detail │ ├── DatumIdentifier.hpp │ ├── Iterator.cpp │ ├── Iterator.hpp │ ├── ParseResult.hpp │ ├── Str.cpp │ ├── Str.hpp │ ├── Token.cpp │ ├── Token.hpp │ └── Type.hpp ├── Object.cpp ├── Object.hpp ├── ParseError.cpp ├── ParseError.hpp ├── Parser.hpp ├── ParserExposedBuffer.cpp ├── ParserExposedBuffer.hpp ├── jsonify_string.cpp └── jsonify_string.hpp ├── Json └── Out.hpp ├── Ln ├── Amount.cpp ├── Amount.hpp ├── CommandId.cpp ├── CommandId.hpp ├── HtlcAccepted.cpp ├── HtlcAccepted.hpp ├── NodeId.cpp ├── NodeId.hpp ├── Preimage.cpp ├── Preimage.hpp ├── Scid.cpp └── Scid.hpp ├── Makefile.am ├── NEWS ├── Net ├── Connector.hpp ├── Detail │ ├── AddrInfoReleaser.cpp │ └── AddrInfoReleaser.hpp ├── DirectConnector.cpp ├── DirectConnector.hpp ├── Fd.cpp ├── Fd.hpp ├── IPAddr.cpp ├── IPAddr.hpp ├── IPAddrOrOnion.cpp ├── IPAddrOrOnion.hpp ├── IPBinnerBySubnet.cpp ├── IPBinnerBySubnet.hpp ├── IPBinnerIF.hpp ├── ProxyConnector.cpp ├── ProxyConnector.hpp ├── SocketFd.cpp ├── SocketFd.hpp ├── get_bin_of_onion.cpp └── get_bin_of_onion.hpp ├── README ├── README.md ├── Ripemd160 ├── Hash.cpp ├── Hash.hpp ├── Hasher.cpp └── Hasher.hpp ├── S ├── Bus.cpp ├── Bus.hpp └── Detail │ ├── Signal.hpp │ └── SignalBase.hpp ├── Secp256k1 ├── Detail │ ├── context.cpp │ └── context.hpp ├── G.cpp ├── G.hpp ├── KeyPair.hpp ├── PrivKey.cpp ├── PrivKey.hpp ├── PubKey.cpp ├── PubKey.hpp ├── Random.cpp ├── Random.hpp ├── Signature.cpp ├── Signature.hpp └── SignerIF.hpp ├── Sha256 ├── Hash.cpp ├── Hash.hpp ├── Hasher.cpp ├── Hasher.hpp ├── HasherStream.cpp ├── HasherStream.hpp └── fun.hpp ├── Sqlite3.hpp ├── Sqlite3 ├── Db.cpp ├── Db.hpp ├── Detail │ ├── binds.cpp │ ├── binds.hpp │ ├── columns.cpp │ └── columns.hpp ├── Query.cpp ├── Query.hpp ├── README.md ├── Result.cpp ├── Result.hpp ├── Tx.cpp └── Tx.hpp ├── Stats ├── ReservoirSampler.hpp ├── RunningMean.cpp ├── RunningMean.hpp └── WeightedMedian.hpp ├── Util ├── BacktraceException.hpp ├── Bech32.cpp ├── Bech32.hpp ├── Compiler.hpp ├── Either.hpp ├── Rw.cpp ├── Rw.hpp ├── Str.cpp ├── Str.hpp ├── date.cpp ├── date.hpp ├── duration.cpp ├── duration.hpp ├── format.cpp ├── format.hpp ├── make_unique.hpp ├── stream_elements.hpp ├── stringify.hpp └── vector_emplace_back.hpp ├── Uuid.cpp ├── Uuid.hpp ├── configure.ac ├── contrib-shell.nix ├── contrib ├── README.md ├── clboss-earnings-history ├── clboss-recent-earnings ├── clboss-routing-stats ├── clboss │ ├── __init__.py │ └── alias_cache.py ├── poetry.lock └── pyproject.toml ├── create-tarball.in ├── dev-boltz-api.cpp ├── dev-boltz.cpp ├── dev-proxy-connect.cpp ├── docs ├── channel_balancing.md ├── channel_creation.md ├── channel_fee_manager.md ├── earnings_tracker.md └── offchain_to_onchain_swap.md ├── external ├── basicsecure │ ├── .gitignore │ ├── COPYING │ ├── Makefile.am │ ├── README.md │ ├── basicsecure.c │ ├── basicsecure.h │ ├── configure.ac │ ├── test_clear.c │ └── test_general.c ├── bitcoin-ripemd160 │ ├── Makefile.am │ ├── README.md │ └── crypto │ │ ├── common.h │ │ ├── ripemd160.cpp │ │ └── ripemd160.h ├── bitcoin-sha256 │ ├── Makefile.am │ ├── README.md │ ├── compat │ │ └── cpuid.h │ └── crypto │ │ ├── common.h │ │ ├── sha256.cpp │ │ └── sha256.h ├── jsmn │ ├── LICENSE │ └── jsmn.h ├── secp256k1.patch ├── secp256k1 │ ├── .cirrus.yml │ ├── .gitattributes │ ├── .gitignore │ ├── CHANGELOG.md │ ├── CMakeLists.txt │ ├── CMakePresets.json │ ├── COPYING │ ├── Makefile.am │ ├── README.md │ ├── SECURITY.md │ ├── autogen.sh │ ├── build-aux │ │ └── m4 │ │ │ └── bitcoin_secp.m4 │ ├── ci │ │ ├── cirrus.sh │ │ └── linux-debian.Dockerfile │ ├── cmake │ │ ├── CheckArm32Assembly.cmake │ │ ├── CheckStringOptionValue.cmake │ │ ├── CheckX86_64Assembly.cmake │ │ ├── FindValgrind.cmake │ │ ├── TryAppendCFlags.cmake │ │ ├── arm-linux-gnueabihf.toolchain.cmake │ │ ├── config.cmake.in │ │ ├── source_arm32.s │ │ └── x86_64-w64-mingw32.toolchain.cmake │ ├── configure.ac │ ├── contrib │ │ ├── lax_der_parsing.c │ │ ├── lax_der_parsing.h │ │ ├── lax_der_privatekey_parsing.c │ │ └── lax_der_privatekey_parsing.h │ ├── doc │ │ ├── release-process.md │ │ └── safegcd_implementation.md │ ├── examples │ │ ├── CMakeLists.txt │ │ ├── EXAMPLES_COPYING │ │ ├── ecdh.c │ │ ├── ecdsa.c │ │ ├── examples_util.h │ │ └── schnorr.c │ ├── include │ │ ├── secp256k1.h │ │ ├── secp256k1_ecdh.h │ │ ├── secp256k1_extrakeys.h │ │ ├── secp256k1_preallocated.h │ │ ├── secp256k1_recovery.h │ │ └── secp256k1_schnorrsig.h │ ├── libsecp256k1.pc.in │ ├── sage │ │ ├── gen_exhaustive_groups.sage │ │ ├── gen_split_lambda_constants.sage │ │ ├── group_prover.sage │ │ ├── prove_group_implementations.sage │ │ ├── secp256k1_params.sage │ │ └── weierstrass_prover.sage │ ├── src │ │ ├── CMakeLists.txt │ │ ├── asm │ │ │ └── field_10x26_arm.s │ │ ├── assumptions.h │ │ ├── bench.c │ │ ├── bench.h │ │ ├── bench_ecmult.c │ │ ├── bench_internal.c │ │ ├── checkmem.h │ │ ├── ctime_tests.c │ │ ├── ecdsa.h │ │ ├── ecdsa_impl.h │ │ ├── eckey.h │ │ ├── eckey_impl.h │ │ ├── ecmult.h │ │ ├── ecmult_compute_table.h │ │ ├── ecmult_compute_table_impl.h │ │ ├── ecmult_const.h │ │ ├── ecmult_const_impl.h │ │ ├── ecmult_gen.h │ │ ├── ecmult_gen_compute_table.h │ │ ├── ecmult_gen_compute_table_impl.h │ │ ├── ecmult_gen_impl.h │ │ ├── ecmult_impl.h │ │ ├── field.h │ │ ├── field_10x26.h │ │ ├── field_10x26_impl.h │ │ ├── field_5x52.h │ │ ├── field_5x52_asm_impl.h │ │ ├── field_5x52_impl.h │ │ ├── field_5x52_int128_impl.h │ │ ├── field_impl.h │ │ ├── group.h │ │ ├── group_impl.h │ │ ├── hash.h │ │ ├── hash_impl.h │ │ ├── int128.h │ │ ├── int128_impl.h │ │ ├── int128_native.h │ │ ├── int128_native_impl.h │ │ ├── int128_struct.h │ │ ├── int128_struct_impl.h │ │ ├── modinv32.h │ │ ├── modinv32_impl.h │ │ ├── modinv64.h │ │ ├── modinv64_impl.h │ │ ├── modules │ │ │ ├── ecdh │ │ │ │ ├── Makefile.am.include │ │ │ │ ├── bench_impl.h │ │ │ │ ├── main_impl.h │ │ │ │ └── tests_impl.h │ │ │ ├── extrakeys │ │ │ │ ├── Makefile.am.include │ │ │ │ ├── main_impl.h │ │ │ │ ├── tests_exhaustive_impl.h │ │ │ │ └── tests_impl.h │ │ │ ├── recovery │ │ │ │ ├── Makefile.am.include │ │ │ │ ├── bench_impl.h │ │ │ │ ├── main_impl.h │ │ │ │ ├── tests_exhaustive_impl.h │ │ │ │ └── tests_impl.h │ │ │ └── schnorrsig │ │ │ │ ├── Makefile.am.include │ │ │ │ ├── bench_impl.h │ │ │ │ ├── main_impl.h │ │ │ │ ├── tests_exhaustive_impl.h │ │ │ │ └── tests_impl.h │ │ ├── precompute_ecmult.c │ │ ├── precompute_ecmult_gen.c │ │ ├── precomputed_ecmult.c │ │ ├── precomputed_ecmult.h │ │ ├── precomputed_ecmult_gen.c │ │ ├── precomputed_ecmult_gen.h │ │ ├── scalar.h │ │ ├── scalar_4x64.h │ │ ├── scalar_4x64_impl.h │ │ ├── scalar_8x32.h │ │ ├── scalar_8x32_impl.h │ │ ├── scalar_impl.h │ │ ├── scalar_low.h │ │ ├── scalar_low_impl.h │ │ ├── scratch.h │ │ ├── scratch_impl.h │ │ ├── secp256k1.c │ │ ├── selftest.h │ │ ├── testrand.h │ │ ├── testrand_impl.h │ │ ├── tests.c │ │ ├── tests_exhaustive.c │ │ ├── util.h │ │ └── wycheproof │ │ │ ├── WYCHEPROOF_COPYING │ │ │ ├── ecdsa_secp256k1_sha256_bitcoin_test.h │ │ │ └── ecdsa_secp256k1_sha256_bitcoin_test.json │ └── tools │ │ └── tests_wycheproof_generate.py └── update-secp256k1.sh ├── flake.lock ├── flake.nix ├── generate_commit_hash.sh ├── main.cpp ├── new-mod ├── reproducible ├── .gitignore ├── README.md ├── build.sh ├── continue.sh └── manifest.scm.template ├── shell.nix └── tests ├── bitcoin ├── test_addr_to_scriptpubkey.cpp ├── test_serial.cpp ├── test_sighash.cpp └── test_tx.cpp ├── boltz └── test_match_lockscript.cpp ├── boss ├── channelcandidateinvestigator │ ├── test_gumshoe.cpp │ └── test_secretary.cpp ├── test_availablerpccommandsannouncer.cpp ├── test_channelcreationdecider.cpp ├── test_channelcreator_planner.cpp ├── test_channelcreator_rearrangerbysize.cpp ├── test_channelcreator_reprioritizer.cpp ├── test_earningshistory.cpp ├── test_earningsrebalancer.cpp ├── test_earningstracker.cpp ├── test_feemodderbypricetheory.cpp ├── test_forwardfeemonitor.cpp ├── test_getmanifest.cpp ├── test_initialrebalancer.cpp ├── test_jitrebalancer.cpp ├── test_needsconnectsolicitor.cpp ├── test_onchainfeemonitor_samples_init.cpp ├── test_peercomplaintsdesk_recorder.cpp ├── test_peerjudge_agetracker.cpp ├── test_peerjudge_algo.cpp ├── test_peerjudge_datagatherer.cpp ├── test_peerstatistician.cpp ├── test_recentearnings.cpp ├── test_reqresp.cpp ├── test_rpc.cpp ├── test_stringid.cpp ├── test_swapmanager.cpp ├── test_unmanagedmanager.cpp ├── test_version.cpp └── test_waiter_timed.cpp ├── dnsseed ├── test_decode_bech32_node.cpp ├── test_get.cpp └── test_parse_dig_srv.cpp ├── ev ├── test_concurrent_simple.cpp ├── test_io_mem_leak.cpp ├── test_map.cpp ├── test_memoize.cpp ├── test_plus.cpp ├── test_runcmd.cpp ├── test_semaphore.cpp └── test_throw_in_then.cpp ├── graph └── test_dijkstra.cpp ├── jsmn ├── test_equality.cpp ├── test_iterator.cpp ├── test_parser.cpp └── test_performance.cpp ├── json └── test_out_simple.cpp ├── ln ├── test_amount.cpp ├── test_commandid.cpp ├── test_htlcaccepted.cpp ├── test_nodeid.cpp └── test_scid.cpp ├── net ├── test_ipaddr.cpp └── test_ipaddroronion.cpp ├── ripemd160 └── test_ripemd160.cpp ├── s └── test_bus.cpp ├── sha256 ├── test_hash.cpp └── test_hasher.cpp ├── sqlite3 └── test_sqlite3.cpp ├── stats ├── test_reservoir_sampler.cpp ├── test_running_mean.cpp └── test_weighted_median.cpp ├── test_uuid.cpp └── util ├── test_date.cpp ├── test_duration.cpp ├── test_either.cpp └── test_format.cpp /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((c-mode . ((c-file-style . "linux") 2 | (indent-tabs-mode . t) 3 | (show-trailing-whitespace . t) 4 | (c-basic-offset . 8) 5 | (tab-width . 8) 6 | )) 7 | 8 | (c++-mode . ((c-file-style . "linux") 9 | (indent-tabs-mode . t) 10 | (show-trailing-whitespace . t) 11 | (c-basic-offset . 8) 12 | (tab-width . 8) 13 | )) 14 | ) 15 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: "Code Base Sanity Check" 2 | on: 3 | pull_request: 4 | push: 5 | 6 | jobs: 7 | tests: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | - uses: cachix/install-nix-action@v22 12 | with: 13 | github_access_token: ${{ secrets.GITHUB_TOKEN }} 14 | - run: nix develop --command bash -c "autoreconf -i && ./configure && make -j4 distcheck" 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /clboss 2 | create-tarball 3 | dev-boltz-api 4 | dev-boltz 5 | dev-proxy-connect 6 | data.dev-boltz 7 | *.o 8 | *.la 9 | *.lo 10 | *~ 11 | Makefile.in 12 | config.h.in 13 | *.trs 14 | *.scan 15 | config.status 16 | config.h 17 | configure 18 | contrib/clboss/__pycache__/ 19 | *.log 20 | *.m4 21 | !external/libsodium/m4/*.m4 22 | !external/secp256k1/build-aux/m4/*.m4 23 | libtool 24 | INSTALL 25 | Makefile 26 | TAGS 27 | autom4te* 28 | m4 29 | !external/libsodium/m4 30 | !external/secp256k1/build-aux/m4 31 | stamp-* 32 | auxdir 33 | .deps 34 | .dirstamp 35 | .libs 36 | 37 | test_* 38 | !test_*.cpp 39 | !test_*.c 40 | /commit_hash.h 41 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | ZmnSCPxj 2 | -------------------------------------------------------------------------------- /Bitcoin/TxIn.cpp: -------------------------------------------------------------------------------- 1 | #include"Bitcoin/TxIn.hpp" 2 | #include"Bitcoin/le.hpp" 3 | #include"Bitcoin/varint.hpp" 4 | 5 | std::ostream& operator<<(std::ostream& os, Bitcoin::TxIn const& v) { 6 | os << v.prevTxid 7 | << Bitcoin::le(v.prevOut) 8 | << Bitcoin::varint(v.scriptSig.size()) 9 | ; 10 | for (auto b : v.scriptSig) 11 | os.put(b); 12 | os << Bitcoin::le(v.nSequence); 13 | return os; 14 | } 15 | std::istream& operator>>(std::istream& is, Bitcoin::TxIn& v) { 16 | auto scriptSigLen = std::uint64_t(); 17 | is >> v.prevTxid 18 | >> Bitcoin::le(v.prevOut) 19 | >> Bitcoin::varint(scriptSigLen) 20 | ; 21 | v.scriptSig.resize(std::size_t(scriptSigLen)); 22 | for (auto& b : v.scriptSig) 23 | b = is.get(); 24 | is >> Bitcoin::le(v.nSequence); 25 | return is; 26 | } 27 | -------------------------------------------------------------------------------- /Bitcoin/TxOut.cpp: -------------------------------------------------------------------------------- 1 | #include"Bitcoin/TxOut.hpp" 2 | #include"Bitcoin/le.hpp" 3 | #include"Bitcoin/varint.hpp" 4 | 5 | std::ostream& operator<<(std::ostream& os, Bitcoin::TxOut const& v) { 6 | os << Bitcoin::le(v.amount) 7 | << Bitcoin::varint(v.scriptPubKey.size()) 8 | ; 9 | for (auto b : v.scriptPubKey) 10 | os.put(b); 11 | return os; 12 | } 13 | std::istream& operator>>(std::istream& is, Bitcoin::TxOut& v) { 14 | auto len = std::uint64_t(); 15 | is >> Bitcoin::le(v.amount) 16 | >> Bitcoin::varint(len) 17 | ; 18 | v.scriptPubKey.resize(std::size_t(len)); 19 | for (auto& b : v.scriptPubKey) 20 | b = is.get(); 21 | return is; 22 | } 23 | -------------------------------------------------------------------------------- /Bitcoin/TxOut.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BITCOIN_TXOUT_HPP 2 | #define BITCOIN_TXOUT_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include"Ln/Amount.hpp" 8 | 9 | namespace Bitcoin { 10 | 11 | /** struct Bitcoin::TxOut 12 | * 13 | * @brief represents an output of a Bitcoin 14 | * transaction. 15 | * 16 | * @desc This includes an amount plus a 17 | * script. 18 | */ 19 | struct TxOut { 20 | Ln::Amount amount; 21 | std::vector scriptPubKey; 22 | 23 | bool operator==(TxOut const& o) const { 24 | return amount == o.amount 25 | && scriptPubKey == o.scriptPubKey 26 | ; 27 | } 28 | bool operator!=(TxOut const& o) const { 29 | return !(*this == o); 30 | } 31 | }; 32 | 33 | } 34 | 35 | std::ostream& operator<<(std::ostream&, Bitcoin::TxOut const&); 36 | std::istream& operator>>(std::istream&, Bitcoin::TxOut&); 37 | 38 | #endif /* !defined(BITCOIN_TXOUT_HPP) */ 39 | -------------------------------------------------------------------------------- /Bitcoin/WitnessField.cpp: -------------------------------------------------------------------------------- 1 | #include"Bitcoin/WitnessField.hpp" 2 | #include"Bitcoin/varint.hpp" 3 | 4 | std::ostream& operator<<(std::ostream& os, Bitcoin::WitnessField const& v) { 5 | os << Bitcoin::varint(v.witnesses.size()); 6 | for (auto const& w : v.witnesses) { 7 | os << Bitcoin::varint(w.size()); 8 | for (auto b : w) 9 | os.put(b); 10 | } 11 | return os; 12 | } 13 | std::istream& operator>>(std::istream& is, Bitcoin::WitnessField& v) { 14 | auto len = std::uint64_t(); 15 | is >> Bitcoin::varint(len); 16 | v.witnesses.resize(std::size_t(len)); 17 | for (auto& w : v.witnesses) { 18 | is >> Bitcoin::varint(len); 19 | w.resize(len); 20 | for (auto& b : w) 21 | b = is.get(); 22 | } 23 | return is; 24 | } 25 | -------------------------------------------------------------------------------- /Bitcoin/hash160.cpp: -------------------------------------------------------------------------------- 1 | #include"Bitcoin/hash160.hpp" 2 | #include"Ripemd160/Hash.hpp" 3 | #include"Ripemd160/Hasher.hpp" 4 | #include"Sha256/Hash.hpp" 5 | #include"Sha256/fun.hpp" 6 | 7 | namespace Bitcoin { 8 | 9 | void hash160( Ripemd160::Hash& hash160, Sha256::Hash& sha256 10 | , void const* p, std::size_t len 11 | ) { 12 | sha256 = Sha256::fun(p, len); 13 | 14 | std::uint8_t buf[32]; 15 | sha256.to_buffer(buf); 16 | 17 | auto r_hasher = Ripemd160::Hasher(); 18 | r_hasher.feed(buf, sizeof(buf)); 19 | hash160 = std::move(r_hasher).finalize(); 20 | } 21 | Ripemd160::Hash hash160(void const* p, std::size_t len) { 22 | auto sha256 = Sha256::Hash(); 23 | auto hash160_ = Ripemd160::Hash(); 24 | hash160(hash160_, sha256, p, len); 25 | return hash160_; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Bitcoin/hash160.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BITCOIN_HASH160_HPP 2 | #define BITCOIN_HASH160_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Ripemd160 { class Hash; } 8 | namespace Sha256 { class Hash; } 9 | 10 | namespace Bitcoin { 11 | 12 | /** Bitcoin::hash160 13 | * 14 | * @brief hashes the input by SHA256, then 15 | * hashes the SHA256 hash by RIPEMD160. 16 | * 17 | * @desc There are two variants, one which 18 | * just returns the RIPEMD160, and the 19 | * other which also outputs the intermediate 20 | * SHA256. 21 | */ 22 | Ripemd160::Hash hash160(void const* p, std::size_t len); 23 | void hash160( Ripemd160::Hash& hash160, Sha256::Hash& sha256 24 | , void const* p, std::size_t len 25 | ); 26 | 27 | } 28 | 29 | #endif /* BITCOIN_HASH160_HPP */ 30 | -------------------------------------------------------------------------------- /Boltz/Connection.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOLTZ_CONNECTION_HPP 2 | #define BOLTZ_CONNECTION_HPP 3 | 4 | #include"Boltz/Detail/NormalConnection.hpp" 5 | 6 | namespace Boltz { 7 | 8 | /** class Boltz::Connection 9 | * 10 | * @brief shim for `Boltz::Detail::NormalConnection`. 11 | */ 12 | class Connection : public Boltz::Detail::NormalConnection { 13 | public: 14 | explicit 15 | Connection( Ev::ThreadPool& threadpool 16 | /* Base address of the API endpoint. */ 17 | , std::string api_base = "https://boltz.exchange/api" 18 | /* SOCKS5 proxy to use. Empty string means no proxy. */ 19 | , std::string proxy = "" 20 | ) : Detail::NormalConnection( threadpool 21 | , std::move(api_base) 22 | , std::move(proxy) 23 | ) 24 | { } 25 | }; 26 | 27 | } 28 | 29 | #endif /* !defined(BOLTZ_CONNECTION_HPP) */ 30 | -------------------------------------------------------------------------------- /Boltz/Detail/NullConnection.cpp: -------------------------------------------------------------------------------- 1 | #include"Boltz/Detail/NullConnection.hpp" 2 | #include"Ev/Io.hpp" 3 | 4 | namespace Boltz { namespace Detail { 5 | 6 | Ev::Io 7 | NullConnection::api( std::string api /* e.g. "/createswap" */ 8 | /* nullptr if GET, or the request body if POST. */ 9 | , std::unique_ptr params 10 | ) { 11 | return Ev::lift().then([]() -> Ev::Io { 12 | throw Boltz::ApiError("no connection available"); 13 | }); 14 | } 15 | 16 | }} 17 | -------------------------------------------------------------------------------- /Boltz/Detail/NullConnection.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOLTZ_DETAIL_NULLCONNECTION_HPP 2 | #define BOLTZ_DETAIL_NULLCONNECTION_HPP 3 | 4 | #include"Boltz/ConnectionIF.hpp" 5 | 6 | namespace Boltz { namespace Detail { 7 | 8 | /** class Boltz::Detail::NullConnection 9 | * 10 | * @brief a connection to a Boltz-like service that 11 | * always fails. 12 | */ 13 | class NullConnection : public Boltz::ConnectionIF { 14 | public: 15 | Ev::Io 16 | api( std::string api /* e.g. "/createswap" */ 17 | /* nullptr if GET, or the request body if POST. */ 18 | , std::unique_ptr params 19 | ) override; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOLTZ_DETAIL_NULLCONNECTION_HPP) */ 25 | -------------------------------------------------------------------------------- /Boltz/Detail/compute_preimage.cpp: -------------------------------------------------------------------------------- 1 | #include"Boltz/Detail/compute_preimage.hpp" 2 | #include"Ln/Preimage.hpp" 3 | #include"Sha256/Hash.hpp" 4 | #include"Secp256k1/SignerIF.hpp" 5 | 6 | namespace Boltz { namespace Detail { 7 | 8 | Ln::Preimage compute_preimage( Secp256k1::SignerIF& signer 9 | , Ln::Preimage const& base_preimage 10 | ) { 11 | std::uint8_t buf[32]; 12 | base_preimage.to_buffer(buf); 13 | auto actual_preimage_h = signer.get_privkey_salted_hash(buf); 14 | actual_preimage_h.to_buffer(buf); 15 | 16 | auto actual_preimage = Ln::Preimage(); 17 | actual_preimage.from_buffer(buf); 18 | return actual_preimage; 19 | } 20 | 21 | }} 22 | -------------------------------------------------------------------------------- /Boltz/Detail/compute_preimage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOLTZ_DETAIL_COMPUTE_PREIMAGE_HPP 2 | #define BOLTZ_DETAIL_COMPUTE_PREIMAGE_HPP 3 | 4 | namespace Ln { class Preimage; } 5 | namespace Secp256k1 { class SignerIF; } 6 | 7 | namespace Boltz { namespace Detail { 8 | 9 | /** Boltz::Detail::compute_preimage 10 | * 11 | * @brief computes the actual preimage to use, 12 | * based on a base preimage and the signer 13 | * privkey. 14 | * 15 | * @desc this ensures that the preimage in the 16 | * database is not the actual preimage that is 17 | * used when dealing with the Boltz instance, 18 | * so that even if a developer runs a Boltz 19 | * instance and is given a database to debug, 20 | * there is no risk of loss to the user who 21 | * gave the database. 22 | */ 23 | Ln::Preimage compute_preimage( Secp256k1::SignerIF& signer 24 | , Ln::Preimage const& base_preimage 25 | ); 26 | 27 | }} 28 | 29 | #endif /* !defined(BOLTZ_DETAIL_COMPUTE_PREIMAGE_HPP) */ 30 | -------------------------------------------------------------------------------- /Boltz/Detail/create_connection.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOLTZ_DETAIL_CREATE_CONNECITON_HPP 2 | #define BOLTZ_DETAIL_CREATE_CONNECITON_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Boltz { class ConnectionIF; } 8 | namespace Ev { class ThreadPool; } 9 | 10 | namespace Boltz { namespace Detail { 11 | 12 | /** Boltz::Detail::create_connection 13 | * 14 | * @brief Creates a `Boltz::ConnectionIF` object appropriate 15 | * for the given setup for a Boltz-like service. 16 | */ 17 | std::unique_ptr 18 | create_connection( Ev::ThreadPool& threadpool 19 | /* Can be "" if no clearnet endpoint. */ 20 | , std::string clearnet_endpoint 21 | /* Can be "" if no Tor endpoint. */ 22 | , std::string tor_endpoint 23 | /* Can be "" if no Tor proxy. */ 24 | , std::string tor_proxy 25 | , bool always_use_proxy 26 | ); 27 | 28 | }} 29 | 30 | #endif /* !defined(BOLTZ_DETAIL_CREATE_CONNECITON_HPP) */ 31 | -------------------------------------------------------------------------------- /Boltz/Detail/find_lockup_outnum.cpp: -------------------------------------------------------------------------------- 1 | #include"Bitcoin/Tx.hpp" 2 | #include"Boltz/Detail/find_lockup_outnum.hpp" 3 | #include"Sha256/Hash.hpp" 4 | #include"Sha256/fun.hpp" 5 | #include 6 | 7 | namespace Boltz { namespace Detail { 8 | 9 | int find_lockup_outnum( Bitcoin::Tx const& tx 10 | , std::vector const& redeemScript 11 | ) { 12 | auto hash = Sha256::fun( 13 | &redeemScript[0], redeemScript.size() 14 | ); 15 | auto scriptPubKey = std::vector(34); 16 | scriptPubKey[0] = 0x00; 17 | scriptPubKey[1] = 0x20; 18 | hash.to_buffer(&scriptPubKey[2]); 19 | 20 | auto it = std::find_if( tx.outputs.begin(), tx.outputs.end() 21 | , [&scriptPubKey](Bitcoin::TxOut const& out) { 22 | return out.scriptPubKey == scriptPubKey; 23 | }); 24 | if (it == tx.outputs.end()) 25 | return -1; 26 | return it - tx.outputs.begin(); 27 | } 28 | 29 | }} 30 | -------------------------------------------------------------------------------- /Boltz/Detail/find_lockup_outnum.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOLTZ_DETAIL_FIND_LOCKUP_OUTNUM_HPP 2 | #define BOLTZ_DETAIL_FIND_LOCKUP_OUTNUM_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Bitcoin { class Tx; } 8 | 9 | namespace Boltz { namespace Detail { 10 | 11 | /** Boltz::Detail::find_lockup_outnum 12 | * 13 | * @brief finds the output of the given 14 | * transaction which pays out to a P2WSH 15 | * that matches the given `redeemScript`. 16 | * 17 | * @return -1 if not found, or a zero or 18 | * positive output index if found. 19 | */ 20 | int find_lockup_outnum( Bitcoin::Tx const& tx 21 | , std::vector const& redeemScript 22 | ); 23 | 24 | }} 25 | 26 | #endif /* !defined(BOLTZ_DETAIL_FIND_LOCKUP_OUTNUM_HPP) */ 27 | -------------------------------------------------------------------------------- /Boltz/Detail/match_lockscript.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOLTZ_DETAIL_MATCH_LOCKSCRIPT_HPP 2 | #define BOLTZ_DETAIL_MATCH_LOCKSCRIPT_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Ripemd160 { class Hash; } 8 | namespace Secp256k1 { class PubKey; } 9 | 10 | namespace Boltz { namespace Detail { 11 | 12 | /** Boltz::Detail::match_lockscript 13 | * 14 | * @brief determines if the given supposed SCRIPT 15 | * matches the expected lockscript from a proper 16 | * BOLTZ instance. 17 | */ 18 | bool match_lockscript( Ripemd160::Hash& hash 19 | , Secp256k1::PubKey& pubkey_hash 20 | , std::uint32_t& locktime 21 | , Secp256k1::PubKey& pubkey_locktime 22 | , std::vector const& script 23 | ); 24 | 25 | }} 26 | 27 | #endif /* !defined(BOLTZ_DETAIL_MATCH_LOCKSCRIPT_HPP) */ 28 | -------------------------------------------------------------------------------- /Boltz/SwapInfo.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOLTZ_SWAPINFO_HPP 2 | #define BOLTZ_SWAPINFO_HPP 3 | 4 | #include"Sha256/Hash.hpp" 5 | #include 6 | #include 7 | 8 | namespace Boltz { 9 | 10 | /** struct Boltz::SwapInfo 11 | * 12 | * @brief Contains information about the swap. 13 | */ 14 | struct SwapInfo { 15 | /* Pay this in order to complete the swap. */ 16 | std::string invoice; 17 | /* The hash of the above invoice. */ 18 | Sha256::Hash hash; 19 | /* Blockheight. */ 20 | std::uint32_t timeout; 21 | }; 22 | 23 | } 24 | 25 | #endif /* !defined(BOLTZ_SWAPINFO_HPP) */ 26 | -------------------------------------------------------------------------------- /Boss/JsonInput.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_JSONINPUT_HPP 2 | #define BOSS_JSONINPUT_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Ev { template class Io; } 8 | namespace Ev { class ThreadPool; } 9 | namespace S { class Bus; } 10 | 11 | namespace Boss { 12 | 13 | /** class JsonInput 14 | * 15 | * @brief special module that takes the cin and 16 | * emits Boss::Msg::JsonCin messages for each 17 | * JSON object it receivs. 18 | * 19 | * @desc Unlike other modules, this module has a 20 | * run function. 21 | * When the run function action returns, the input 22 | * has reached end-of-file and the rest of the BOSS 23 | * needs to shut down. 24 | */ 25 | class JsonInput { 26 | private: 27 | class Impl; 28 | std::unique_ptr pimpl; 29 | 30 | public: 31 | explicit 32 | JsonInput( Ev::ThreadPool& threadpool 33 | , std::istream& cin 34 | , S::Bus& bus 35 | ); 36 | JsonInput(JsonInput&&); 37 | ~JsonInput(); 38 | 39 | Ev::Io run(); 40 | }; 41 | 42 | } 43 | 44 | #endif /* ~defined(BOSS_JSONINPUT_HPP) */ 45 | -------------------------------------------------------------------------------- /Boss/Main.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MAIN_HPP 2 | #define BOSS_MAIN_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Ev { template class Io; } 12 | namespace Net { class Fd; } 13 | 14 | namespace Boss { 15 | 16 | class Main { 17 | private: 18 | class Impl; 19 | std::unique_ptr pimpl; 20 | 21 | public: 22 | Main() = delete; 23 | Main( std::vector argv 24 | , std::istream& cin 25 | , std::ostream& cout 26 | , std::ostream& cerr 27 | , std::function< Net::Fd( std::string const& 28 | , std::string const& 29 | ) 30 | > open_rpc_socket 31 | ); 32 | Main(Main&&); 33 | ~Main(); 34 | 35 | Ev::Io run(); 36 | }; 37 | 38 | } 39 | 40 | #endif /* !defined(BOSS_MAIN_HPP) */ 41 | -------------------------------------------------------------------------------- /Boss/Mod/AmountSettingsHandler.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_AMOUNTSETTINGSHANDLER_HPP 2 | #define BOSS_MOD_AMOUNTSETTINGSHANDLER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | class AmountSettingsHandler { 11 | private: 12 | class Impl; 13 | std::unique_ptr pimpl; 14 | 15 | public: 16 | AmountSettingsHandler() =delete; 17 | AmountSettingsHandler(AmountSettingsHandler const&) =delete; 18 | ~AmountSettingsHandler(); 19 | 20 | AmountSettingsHandler(AmountSettingsHandler&&); 21 | 22 | explicit 23 | AmountSettingsHandler(S::Bus&); 24 | }; 25 | 26 | }} 27 | 28 | #endif /* !defined(BOSS_MOD_AMOUNTSETTINGSHANDLER_HPP) */ 29 | -------------------------------------------------------------------------------- /Boss/Mod/BlockTracker.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_BLOCKTRACKER_HPP 2 | #define BOSS_MOD_BLOCKTRACKER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Boss { namespace Mod { class Rpc; }} 8 | namespace Ev { template class Io; } 9 | namespace S { class Bus; } 10 | 11 | namespace Boss { namespace Mod { 12 | 13 | /** class Boss::Mod::BlockTracker 14 | * 15 | * @brief simple module to emit a Boss::Msg::Block message 16 | * at each block processed by lightningd. 17 | */ 18 | class BlockTracker { 19 | private: 20 | S::Bus& bus; 21 | 22 | std::uint32_t height; 23 | 24 | Ev::Io fail(std::string); 25 | Ev::Io loop(Boss::Mod::Rpc&); 26 | void start(); 27 | 28 | public: 29 | explicit 30 | BlockTracker(S::Bus& bus_) : bus(bus_) { start(); } 31 | }; 32 | 33 | }} 34 | 35 | #endif /* !defined(BOSS_MOD_BLOCKTRACKER_HPP) */ 36 | -------------------------------------------------------------------------------- /Boss/Mod/BoltzSwapper/Env.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_BOLTZSWAPPER_ENV_HPP 2 | #define BOSS_MOD_BOLTZSWAPPER_ENV_HPP 3 | 4 | #include"Boltz/EnvIF.hpp" 5 | 6 | namespace Boss { namespace Mod { class Rpc; }} 7 | namespace S { class Bus; } 8 | 9 | namespace Boss { namespace Mod { namespace BoltzSwapper { 10 | 11 | /** class Boss::Mod::BoltzSwapper::Env 12 | * 13 | * @brief fulfills the `Boltz::EnvIF` interface, 14 | * using the RPC and log of CLBOSS. 15 | */ 16 | class Env : public Boltz::EnvIF { 17 | private: 18 | S::Bus& bus; 19 | Boss::Mod::Rpc* rpc; 20 | 21 | void start(); 22 | 23 | public: 24 | Env() =delete; 25 | Env(Env&&) =delete; 26 | Env(Env const&) =delete; 27 | 28 | explicit 29 | Env(S::Bus& bus_) : bus(bus_), rpc(nullptr) { 30 | start(); 31 | } 32 | 33 | /* Boltz::EnvIF. */ 34 | Ev::Io get_feerate() override; 35 | Ev::Io broadcast_tx(Bitcoin::Tx) override; 36 | Ev::Io logd(std::string) override; 37 | Ev::Io loge(std::string) override; 38 | }; 39 | 40 | }}} 41 | 42 | #endif /* !defined(BOSS_MOD_BOLTZSWAPPER_ENV_HPP) */ 43 | -------------------------------------------------------------------------------- /Boss/Mod/BoltzSwapper/Main.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_BOLTZSWAPPER_MAIN_HPP 2 | #define BOSS_MOD_BOLTZSWAPPER_MAIN_HPP 3 | 4 | #include 5 | 6 | namespace Ev { class ThreadPool; } 7 | namespace S { class Bus; } 8 | 9 | namespace Boss { namespace Mod { namespace BoltzSwapper { 10 | 11 | /** class Boss::Mod::BoltzSwapper::Main 12 | * 13 | * @brief main module for interfacing with Boltz 14 | * instances. 15 | */ 16 | class Main { 17 | private: 18 | class Impl; 19 | std::unique_ptr pimpl; 20 | 21 | public: 22 | Main() =delete; 23 | 24 | Main(Main&&); 25 | Main& operator=(Main&&); 26 | ~Main(); 27 | 28 | Main(S::Bus&, Ev::ThreadPool&); 29 | }; 30 | 31 | }}} 32 | 33 | #endif /* !defined(BOSS_MOD_BOLTZSWAPPER_MAIN_HPP) */ 34 | -------------------------------------------------------------------------------- /Boss/Mod/BoltzSwapper/README.md: -------------------------------------------------------------------------------- 1 | 2 | The `Boss::Mod::BoltzSwapper` provides offchain-to-onchain 3 | swap services. 4 | 5 | - `ServiceModule` - a thin wrapper that converts from Boss 6 | messages to calls to a `Boltz::Service`. 7 | - `ServiceCreator` - at `Boss::Msg::Init`, constructs the 8 | various `ServiceModule`s according to hardcoded known 9 | Boltz instances. 10 | - `Env` - an implementation of `Boltz::EnvIF` for Boss. 11 | - `Main` - holds the `ServiceCreator` and `Env`. 12 | -------------------------------------------------------------------------------- /Boss/Mod/BoltzSwapper/ServiceModule.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_BOLTZSWAPPER_SERVICEMODULE_HPP 2 | #define BOSS_MOD_BOLTZSWAPPER_SERVICEMODULE_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Boltz { class Service; } 8 | namespace S { class Bus; } 9 | 10 | namespace Boss { namespace Mod { namespace BoltzSwapper { 11 | 12 | class ServiceModule { 13 | private: 14 | class Impl; 15 | std::unique_ptr pimpl; 16 | 17 | public: 18 | ServiceModule() =delete; 19 | 20 | ServiceModule(ServiceModule&&); 21 | ServiceModule& operator=(ServiceModule&&); 22 | ~ServiceModule(); 23 | 24 | explicit 25 | ServiceModule( S::Bus& bus 26 | , std::unique_ptr 27 | , std::string label 28 | ); 29 | }; 30 | 31 | }}} 32 | 33 | #endif /* !defined(BOSS_MOD_BOLTZSWAPPER_SERVICEMODULE_HPP) */ 34 | 35 | -------------------------------------------------------------------------------- /Boss/Mod/ChannelCandidateInvestigator/README.md: -------------------------------------------------------------------------------- 1 | 2 | The `ChannelCandidateInvestigator` is a module which waits for 3 | `ProposeChannelCandidates` and puts them in persistent storage. 4 | 5 | Every random-hour, we investigate up to some number of candidates. 6 | The gumshoe tries to connect to the candidates. 7 | 8 | If the candidate is not reachable, we decrement its score by 1. 9 | If the candidate is reachable, we increment its score by 1. 10 | If the score drops too low, we stop investigating it and remove it from 11 | our table. 12 | 13 | New candidates start with a score of 0. 14 | 15 | When there are few positive/zero-scored candidates, we 16 | `SolicitChannelCandidates` to trigger other modules. 17 | 18 | The sub-modules are: 19 | 20 | * `Main` - contains the other sub-modules. 21 | * `Secretary` - handles queries and updates to the database. 22 | * `Gumshoe` - handles checking the candidates. 23 | * `Manager` - operates the `Secretary` and `Gumshoe`, and does most of 24 | the bus talking. 25 | -------------------------------------------------------------------------------- /Boss/Mod/ChannelCandidatePreinvestigator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_CHANNELCANDIDATEPREINVESTIGATOR_HPP 2 | #define BOSS_MOD_CHANNELCANDIDATEPREINVESTIGATOR_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | class ChannelCandidatePreinvestigator { 11 | private: 12 | class Impl; 13 | std::unique_ptr pimpl; 14 | 15 | public: 16 | ChannelCandidatePreinvestigator() =delete; 17 | 18 | ChannelCandidatePreinvestigator(S::Bus&); 19 | ChannelCandidatePreinvestigator(ChannelCandidatePreinvestigator&&); 20 | ~ChannelCandidatePreinvestigator(); 21 | }; 22 | 23 | }} 24 | 25 | #endif /* !defined(BOSS_MOD_CHANNELCANDIDATEPREINVESTIGATOR_HPP) */ 26 | -------------------------------------------------------------------------------- /Boss/Mod/ChannelCreationDecider.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_CHANNELCREATIONDECIDER_HPP 2 | #define BOSS_MOD_CHANNELCREATIONDECIDER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::ChannelCreationDecider 11 | * 12 | * @brief module that decides whether to create 13 | * channels whenever `Boss::Msg::OnchainFunds` 14 | * is emitted. 15 | */ 16 | class ChannelCreationDecider { 17 | private: 18 | class Impl; 19 | std::unique_ptr pimpl; 20 | 21 | public: 22 | ChannelCreationDecider() =delete; 23 | ChannelCreationDecider(ChannelCreationDecider const&) =delete; 24 | 25 | explicit 26 | ChannelCreationDecider(S::Bus& bus); 27 | ChannelCreationDecider(ChannelCreationDecider&&); 28 | ~ChannelCreationDecider(); 29 | }; 30 | 31 | }} 32 | 33 | #endif /* !defined(BOSS_MOD_CHANNELCREATIONDECIDER_HPP) */ 34 | -------------------------------------------------------------------------------- /Boss/Mod/ChannelCreator/Main.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/Mod/ChannelCreator/Carpenter.hpp" 2 | #include"Boss/Mod/ChannelCreator/Main.hpp" 3 | #include"Boss/Mod/ChannelCreator/Manager.hpp" 4 | #include"Util/make_unique.hpp" 5 | 6 | namespace Boss { namespace Mod { namespace ChannelCreator { 7 | 8 | Main::Main( S::Bus& bus 9 | , Boss::Mod::Waiter& waiter 10 | , Boss::Mod::ChannelCandidateInvestigator::Main& investigator 11 | ) : carpenter(Util::make_unique(bus, waiter)) 12 | , manager(Util::make_unique( bus 13 | , investigator 14 | , *carpenter 15 | )) 16 | { } 17 | Main::~Main() { } 18 | 19 | }}} 20 | -------------------------------------------------------------------------------- /Boss/Mod/ChannelCreator/README.md: -------------------------------------------------------------------------------- 1 | 2 | This module creates channels. 3 | 4 | It reacts to `Boss::Msg::RequestChannelCreation`, then queries a 5 | `Boss::Mod::ChannelCandidateInvestigator::Main` for candidates, 6 | then figures out some kind of divison of available funds to those 7 | candidates. 8 | 9 | - `Dowser` - given a single candidate, attempts to figure out some 10 | recommended amount to put in a channel for this. 11 | This object is created at runtime for each recommended candidate. 12 | - `Planner` - given an amount, some proposal nodes, and how many 13 | channels we already have, creates a plan of how to build channels. 14 | This object is created at runtime when we have onchain funds we 15 | want to use. 16 | - `Carpenter` - actually constructs channels, and reports channel 17 | creation success and failure. 18 | - `Manager` - handles the above objects, and wrangles with most 19 | messages received. 20 | - `Main` - Holds the `Carpenter` and `Manager`. 21 | -------------------------------------------------------------------------------- /Boss/Mod/ChannelFundsComputer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_CHANNELFUNDSCOMPUTER_HPP 2 | #define BOSS_MOD_CHANNELFUNDSCOMPUTER_HPP 3 | 4 | namespace Boss { namespace Msg { struct ListfundsResult; }} 5 | namespace Ev { template class Io; } 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | class ChannelFundsComputer { 11 | private: 12 | S::Bus& bus; 13 | 14 | void start(); 15 | Ev::Io on_listfunds(Msg::ListfundsResult const&); 16 | 17 | public: 18 | ChannelFundsComputer() =delete; 19 | ChannelFundsComputer(ChannelFundsComputer const&) =delete; 20 | ChannelFundsComputer(ChannelFundsComputer&&) =delete; 21 | 22 | explicit 23 | ChannelFundsComputer(S::Bus& bus_) : bus(bus_) { start(); } 24 | }; 25 | 26 | }} 27 | 28 | #endif /* !defined(BOSS_MOD_CHANNELFUNDSCOMPUTER_HPP) */ 29 | -------------------------------------------------------------------------------- /Boss/Mod/CommandReceiver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_COMMANDRECEIVER_HPP 2 | #define BOSS_MOD_COMMANDRECEIVER_HPP 3 | 4 | #include"Ln/CommandId.hpp" 5 | #include 6 | #include 7 | 8 | namespace S { class Bus; } 9 | 10 | namespace Boss { namespace Mod { 11 | 12 | class CommandReceiver { 13 | private: 14 | S::Bus& bus; 15 | 16 | std::set pendings; 17 | 18 | public: 19 | explicit 20 | CommandReceiver(S::Bus& bus_); 21 | }; 22 | 23 | }} 24 | 25 | #endif /* !defined(BOSS_MOD_COMMANDRECEIVER_HPP) */ 26 | -------------------------------------------------------------------------------- /Boss/Mod/ComplainerByLowConnectRate.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_COMPLAINERBYLOWCONNECTRATE_HPP 2 | #define BOSS_MOD_COMPLAINERBYLOWCONNECTRATE_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::ComplainerByLowConnectRate 11 | * 12 | * @brief Module to raise complaints on peers that have a low 13 | * three-day connect rate. 14 | */ 15 | class ComplainerByLowConnectRate { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | ComplainerByLowConnectRate() =delete; 22 | ComplainerByLowConnectRate(ComplainerByLowConnectRate const&) =delete; 23 | 24 | ComplainerByLowConnectRate(ComplainerByLowConnectRate&&); 25 | ~ComplainerByLowConnectRate(); 26 | explicit 27 | ComplainerByLowConnectRate(S::Bus& bus); 28 | }; 29 | 30 | }} 31 | 32 | #endif /* !defined(BOSS_MOD_COMPLAINERBYLOWCONNECTRATE_HPP) */ 33 | -------------------------------------------------------------------------------- /Boss/Mod/ComplainerByLowSuccessPerDay.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_COMPLAINERBYLOWSUCCESSPERDAY_HPP 2 | #define BOSS_MOD_COMPLAINERBYLOWSUCCESSPERDAY_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::ComplainerByLowSuccessPerDay 11 | * 12 | * @brief Complains about peers that have a low `success_per_day` 13 | * metric, as presumably those peers have insufficient quality 14 | * in their connections. 15 | * This tries to up the metric as well by triggering active 16 | * probes for peers that are near the borderline. 17 | */ 18 | class ComplainerByLowSuccessPerDay { 19 | private: 20 | class Impl; 21 | std::unique_ptr pimpl; 22 | 23 | public: 24 | ComplainerByLowSuccessPerDay() =delete; 25 | 26 | ~ComplainerByLowSuccessPerDay(); 27 | ComplainerByLowSuccessPerDay(ComplainerByLowSuccessPerDay&&); 28 | 29 | explicit 30 | ComplainerByLowSuccessPerDay(S::Bus&); 31 | }; 32 | 33 | }} 34 | 35 | #endif /* !defined(BOSS_MOD_COMPLAINERBYLOWSUCCESSPERDAY_HPP) */ 36 | -------------------------------------------------------------------------------- /Boss/Mod/ConnectFinderByDns.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_CONNECTFINDERBYDNS_HPP 2 | #define BOSS_MOD_CONNECTFINDERBYDNS_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::ConnectFinderByDns 11 | * 12 | * @brief module to find new connection candidates 13 | * by referring to DNS seeds. 14 | */ 15 | class ConnectFinderByDns { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | ConnectFinderByDns() =delete; 22 | explicit 23 | ConnectFinderByDns(S::Bus& bus); 24 | ConnectFinderByDns(ConnectFinderByDns&&); 25 | ~ConnectFinderByDns(); 26 | }; 27 | 28 | }} 29 | 30 | #endif /* !defined(BOSS_MOD_CONNECTFINDERBYDNS_HPP) */ 31 | -------------------------------------------------------------------------------- /Boss/Mod/ConnectFinderByHardcode.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_CONNECTFINDERBYHARDCODE_HPP 2 | #define BOSS_MOD_CONNECTFINDERBYHARDCODE_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::ConnectFinderByHardcode 11 | * 12 | * @brief provides some possible connection 13 | * candidates from a hardcoded list. 14 | */ 15 | class ConnectFinderByHardcode { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | ConnectFinderByHardcode() =delete; 22 | ConnectFinderByHardcode(S::Bus& bus); 23 | ConnectFinderByHardcode(ConnectFinderByHardcode&&); 24 | ~ConnectFinderByHardcode(); 25 | }; 26 | 27 | }} 28 | 29 | #endif /* BOSS_MOD_CONNECTFINDERBYHARDCODE_HPP */ 30 | -------------------------------------------------------------------------------- /Boss/Mod/Connector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_CONNECTOR_HPP 2 | #define BOSS_MOD_CONNECTOR_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Mod { class Rpc; }} 7 | namespace Ev { template class Io; } 8 | namespace S { class Bus; } 9 | 10 | namespace Boss { namespace Mod { 11 | 12 | /** class Boss::Mod::Connector 13 | * 14 | * @brief module that does `connect` commands. 15 | */ 16 | class Connector { 17 | private: 18 | S::Bus& bus; 19 | Boss::Mod::Rpc *rpc; 20 | 21 | Ev::Io connect(std::string const& node); 22 | void start(); 23 | 24 | public: 25 | Connector(S::Bus& bus_) : bus(bus_) { start(); } 26 | Connector(Connector&&) =delete; 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MOD_CONNECTOR_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Mod/Dowser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_DOWSER_HPP 2 | #define BOSS_MOD_DOWSER_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Mod { class Rpc; }} 8 | namespace S { class Bus; } 9 | 10 | namespace Boss { namespace Mod { 11 | 12 | /** class Boss::Mod::Dowser 13 | * 14 | * @brief Determines the amount of plausible flow between two nodes. 15 | * 16 | * @desc This module responds to `Boss::Msg::RequestDowser`. 17 | */ 18 | class Dowser { 19 | private: 20 | S::Bus& bus; 21 | Boss::Mod::Rpc* rpc; 22 | Ln::NodeId self_id; 23 | 24 | class CommandImpl; 25 | std::unique_ptr cmdimpl; 26 | 27 | class Run; 28 | 29 | void start(); 30 | 31 | public: 32 | Dowser() =delete; 33 | Dowser(Dowser&&) =delete; 34 | Dowser(Dowser const&) =delete; 35 | 36 | ~Dowser(); 37 | explicit 38 | Dowser(S::Bus& bus); 39 | }; 40 | 41 | }} 42 | 43 | #endif /* !defined(BOSS_MOD_DOWSER_HPP) */ 44 | -------------------------------------------------------------------------------- /Boss/Mod/EarningsRebalancer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_EARNINGSREBALANCER_HPP 2 | #define BOSS_MOD_EARNINGSREBALANCER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::EarningsRebalancer 11 | * 12 | * @brief moves funds to nodes that have low capacity on our side. 13 | * Determine sources of funds based on earned incoming fees. 14 | */ 15 | class EarningsRebalancer { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | EarningsRebalancer() =delete; 22 | 23 | EarningsRebalancer(EarningsRebalancer&&); 24 | EarningsRebalancer& operator=(EarningsRebalancer&&) =default; 25 | ~EarningsRebalancer(); 26 | 27 | explicit 28 | EarningsRebalancer(S::Bus& bus); 29 | }; 30 | 31 | }} 32 | 33 | #endif /* !defined(BOSS_MOD_EARNINGSREBALANCER_HPP) */ 34 | -------------------------------------------------------------------------------- /Boss/Mod/FeeModderByPriceTheory.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_FEEMODDERBYPRICETHEORY_HPP 2 | #define BOSS_MOD_FEEMODDERBYPRICETHEORY_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::FeeModderByPriceTheory 11 | * 12 | * @brief controls fee according to a theory that there exists 13 | * some global optimum price that maximizes profit. 14 | */ 15 | class FeeModderByPriceTheory { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | FeeModderByPriceTheory() =delete; 22 | 23 | FeeModderByPriceTheory(FeeModderByPriceTheory&&); 24 | ~FeeModderByPriceTheory(); 25 | 26 | explicit 27 | FeeModderByPriceTheory(S::Bus& bus); 28 | }; 29 | 30 | }} 31 | 32 | #endif /* !defined(BOSS_MOD_FEEMODDERBYPRICETHEORY_HPP) */ 33 | -------------------------------------------------------------------------------- /Boss/Mod/FeeModderBySize.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_FEEMODDERBYSIZE_HPP 2 | #define BOSS_MOD_FEEMODDERBYSIZE_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::FeeModderBySize 11 | * 12 | * @brief Adjust fees depending on the size 13 | * of our node relative to competitors. 14 | */ 15 | class FeeModderBySize { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | FeeModderBySize() =delete; 22 | FeeModderBySize(FeeModderBySize&&); 23 | ~FeeModderBySize(); 24 | 25 | explicit 26 | FeeModderBySize(S::Bus& bus); 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MOD_FEEMODDERBYSIZE_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Mod/FundsMover/Main.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_FUNDSMOVER_MAIN_HPP 2 | #define BOSS_MOD_FUNDSMOVER_MAIN_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { namespace FundsMover { 9 | 10 | /** class Boss::Mod::FundsMover::Main 11 | * 12 | * @brief primary holding module for `FundsMover` module. 13 | */ 14 | class Main { 15 | private: 16 | class Impl; 17 | std::unique_ptr pimpl; 18 | 19 | public: 20 | Main() =delete; 21 | 22 | Main(Main&&); 23 | ~Main(); 24 | 25 | explicit 26 | Main(S::Bus&); 27 | }; 28 | 29 | }}} 30 | 31 | #endif /* !defined(BOSS_MOD_FUNDSMOVER_MAIN_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Mod/FundsMover/create_label.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/Mod/FundsMover/create_label.hpp" 2 | #include"Sha256/Hash.hpp" 3 | #include"Util/Str.hpp" 4 | 5 | namespace { 6 | 7 | auto const label_prefix = std::string("CLBOSS FundsMover payment, " 8 | "this should automatically " 9 | "get deleted. Hash: "); 10 | 11 | } 12 | 13 | namespace Boss { namespace Mod { namespace FundsMover { 14 | 15 | std::string create_label(Sha256::Hash const& payment_hash) { 16 | return label_prefix + std::string(payment_hash); 17 | } 18 | 19 | bool is_our_label(std::string const& label) { 20 | if (label.size() != label_prefix.length() + 64) 21 | return false; 22 | if ( std::string(label.begin(), label.begin() + label_prefix.length()) 23 | != label_prefix 24 | ) 25 | return false; 26 | auto hash = std::string( label.begin() + label_prefix.length() 27 | , label.end() 28 | ); 29 | return Util::Str::ishex(hash); 30 | } 31 | 32 | }}} 33 | -------------------------------------------------------------------------------- /Boss/Mod/FundsMover/create_label.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_FUNDSMOVER_CREATE_LABEL_HPP 2 | #define BOSS_MOD_FUNDSMOVER_CREATE_LABEL_HPP 3 | 4 | #include 5 | 6 | namespace Sha256 { class Hash; } 7 | 8 | namespace Boss { namespace Mod { namespace FundsMover { 9 | 10 | /** Boss::Mod::FundsMover::create_label 11 | * 12 | * @brief Creates the label to be used for funds-movement 13 | * attempts. 14 | */ 15 | std::string create_label(Sha256::Hash const& payment_hash); 16 | 17 | /** Boss::Mod::FundsMover::is_our_label 18 | * 19 | * @brief Determine if the given label matches one that we 20 | * created. 21 | */ 22 | bool is_our_label(std::string const&); 23 | 24 | }}} 25 | 26 | #endif /* !defined(BOSS_MOD_FUNDSMOVER_CREATE_LABEL_HPP) */ 27 | -------------------------------------------------------------------------------- /Boss/Mod/HtlcAcceptor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_HTLCACCEPTOR_HPP 2 | #define BOSS_MOD_HTLCACCEPTOR_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Mod { class Waiter; }} 7 | namespace S { class Bus; } 8 | 9 | namespace Boss { namespace Mod { 10 | 11 | /** class Boss::Mod::HtlcAcceptor 12 | * 13 | * @brief manifests an interest in the `htlc_accepted` 14 | * hook, and allows other modules to defer the normal 15 | * handling of `htlc_accepted`. 16 | * 17 | * @desc See `Boss::Msg::SolicitHtlcAcceptedDeferrer`, 18 | * `Boss::Msg::ProvideHtlAcceptedDeferrer`, and 19 | * `Boss::Msg::ReleaseHtlcAccepted`. 20 | */ 21 | class HtlcAcceptor { 22 | private: 23 | class Impl; 24 | std::unique_ptr pimpl; 25 | 26 | public: 27 | HtlcAcceptor() =delete; 28 | 29 | HtlcAcceptor(HtlcAcceptor&&); 30 | ~HtlcAcceptor(); 31 | 32 | explicit 33 | HtlcAcceptor( S::Bus& bus 34 | , Boss::Mod::Waiter& waiter 35 | ); 36 | }; 37 | 38 | }} 39 | 40 | #endif /* !defined(BOSS_MOD_HTLCACCEPTOR_HPP) */ 41 | -------------------------------------------------------------------------------- /Boss/Mod/InitialRebalancer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_INITIALREBALANCER_HPP 2 | #define BOSS_MOD_INITIALREBALANCER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::InitialRebalancer 11 | * 12 | * @brief If a channel has most funds owned by us at `ListpeersResult`, 13 | * move funds to other channels if possible. 14 | */ 15 | class InitialRebalancer { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | InitialRebalancer() =delete; 22 | 23 | InitialRebalancer(InitialRebalancer&&); 24 | ~InitialRebalancer(); 25 | 26 | explicit 27 | InitialRebalancer(S::Bus& bus); 28 | }; 29 | 30 | }} 31 | 32 | #endif /* !defined(BOSS_MOD_INITIALREBALANCER_HPP) */ 33 | -------------------------------------------------------------------------------- /Boss/Mod/Initiator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_INITIATOR_HPP 2 | #define BOSS_MOD_INITIATOR_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Boss { namespace Mod { class Rpc; }} 9 | namespace Ev { class ThreadPool; } 10 | namespace Net { class Fd; } 11 | namespace S { class Bus; } 12 | 13 | namespace Boss { namespace Mod { 14 | 15 | /** class Boss::Mod::Initiator 16 | * 17 | * @brief handles the `init` command, creates the RPC 18 | * interface and broadcasts the Boss::Msg::Init 19 | * message which contains the RPC. 20 | */ 21 | class Initiator { 22 | private: 23 | class Impl; 24 | std::unique_ptr pimpl; 25 | 26 | public: 27 | Initiator() =delete; 28 | 29 | Initiator( S::Bus& bus 30 | , Ev::ThreadPool& threadpool 31 | , std::function open_rpc_socket 34 | ); 35 | Initiator(Initiator&&); 36 | ~Initiator(); 37 | }; 38 | 39 | }} 40 | 41 | #endif /* !defined(BOSS_MOD_INITIATOR_HPP) */ 42 | -------------------------------------------------------------------------------- /Boss/Mod/JitRebalancer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_JITREBALANCER_HPP 2 | #define BOSS_MOD_JITREBALANCER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::JitRebalancer 11 | * 12 | * @brief Rebalances channels just in time for a forward. 13 | * 14 | * @desc Registers as an `htlc_accepted` deferrer, and defers 15 | * forwards if they are to nodes with insufficient outgoing 16 | * capacity. 17 | * It then arranges to move funds to that channel if possible. 18 | */ 19 | class JitRebalancer { 20 | private: 21 | class Impl; 22 | std::unique_ptr pimpl; 23 | 24 | public: 25 | JitRebalancer() =delete; 26 | 27 | JitRebalancer(JitRebalancer&&); 28 | ~JitRebalancer(); 29 | 30 | explicit 31 | JitRebalancer(S::Bus& bus); 32 | }; 33 | 34 | }} 35 | 36 | #endif /* !defined(BOSS_MOD_JITREBALANCER_HPP) */ 37 | -------------------------------------------------------------------------------- /Boss/Mod/JsonOutputter.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/Mod/JsonOutputter.hpp" 2 | #include"Boss/Msg/JsonCout.hpp" 3 | #include"Boss/concurrent.hpp" 4 | #include"Ev/Io.hpp" 5 | #include"Ev/yield.hpp" 6 | #include"S/Bus.hpp" 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | JsonOutputter::JsonOutputter( std::ostream& cout_ 11 | , S::Bus& bus 12 | ) : cout(cout_) { 13 | bus.subscribe([this](Boss::Msg::JsonCout const& j) { 14 | auto& obj = j.obj; 15 | auto start = outs.empty(); 16 | 17 | outs.push(obj.output()); 18 | 19 | if (!start) 20 | return Ev::lift(); 21 | return Boss::concurrent(loop()); 22 | }); 23 | } 24 | 25 | Ev::Io JsonOutputter::loop() { 26 | return Ev::yield().then([this]() { 27 | if (outs.empty()) 28 | return Ev::lift(); 29 | cout << outs.front() << std::endl; 30 | outs.pop(); 31 | return loop(); 32 | }); 33 | } 34 | 35 | }} 36 | -------------------------------------------------------------------------------- /Boss/Mod/JsonOutputter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_JSONOUTPUTTER_HPP 2 | #define BOSS_MOD_JSONOUTPUTTER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ev { template class Io; } 9 | namespace S { class Bus; } 10 | 11 | namespace Boss { namespace Mod { 12 | 13 | /** class Boss::Mod::JsonOutputter 14 | * 15 | * @brief module that outputs Boss::Msg::JsonCout 16 | * objects. 17 | */ 18 | class JsonOutputter { 19 | private: 20 | std::ostream& cout; 21 | std::queue outs; 22 | 23 | Ev::Io loop(); 24 | public: 25 | JsonOutputter( std::ostream& cout_ 26 | , S::Bus& bus_ 27 | ); 28 | }; 29 | 30 | }} 31 | 32 | #endif /* !defined(BOSS_MOD_JSONOUTPUTTER_HPP) */ 33 | -------------------------------------------------------------------------------- /Boss/Mod/ListfundsAnalyzer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_LISTFUNDSANALYZER_HPP 2 | #define BOSS_MOD_LISTFUNDSANALYZER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::ListfundsAnalyzer 11 | * 12 | * @brief Module to analyze the result of `listfunds` command. 13 | */ 14 | class ListfundsAnalyzer { 15 | private: 16 | class Impl; 17 | std::unique_ptr pimpl; 18 | 19 | public: 20 | ListfundsAnalyzer() =delete; 21 | ListfundsAnalyzer(ListfundsAnalyzer&&); 22 | ~ListfundsAnalyzer(); 23 | explicit 24 | ListfundsAnalyzer(S::Bus& bus); 25 | }; 26 | 27 | }} 28 | 29 | #endif /* !defined(BOSS_MOD_LISTFUNDSANALYZER_HPP) */ 30 | -------------------------------------------------------------------------------- /Boss/Mod/ListfundsAnnouncer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_LISTFUNDSANNOUNCER_HPP 2 | #define BOSS_MOD_LISTFUNDSANNOUNCER_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Mod { class Rpc; }} 7 | namespace Ev { template class Io; } 8 | namespace Jsmn { class Object; } 9 | namespace S { class Bus; } 10 | 11 | namespace Boss { namespace Mod { 12 | 13 | /** class Boss::Mod::ListfundsAnnouncer 14 | * 15 | * @brief Periodically performs `listfunds` and 16 | * announces it. 17 | */ 18 | class ListfundsAnnouncer { 19 | private: 20 | S::Bus& bus; 21 | Boss::Mod::Rpc* rpc; 22 | 23 | void start(); 24 | Ev::Io on_10_minutes(); 25 | Ev::Io fail(std::string const&, Jsmn::Object); 26 | 27 | public: 28 | ListfundsAnnouncer() =delete; 29 | ListfundsAnnouncer(ListfundsAnnouncer const&) =delete; 30 | ListfundsAnnouncer(ListfundsAnnouncer&&) =delete; 31 | 32 | ListfundsAnnouncer(S::Bus& bus_ 33 | ) : bus(bus_), rpc(nullptr) 34 | { start(); } 35 | }; 36 | 37 | }} 38 | 39 | #endif /* !defined(BOSS_MOD_LISTFUNDSANNOUNCER_HPP) */ 40 | -------------------------------------------------------------------------------- /Boss/Mod/ListpaysHandler.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_LISTPAYSHANDLER_HPP 2 | #define BOSS_MOD_LISTPAYSHANDLER_HPP 3 | 4 | #include"Sha256/Hash.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Mod { class Rpc; }} 8 | namespace Ev { template class Io; } 9 | namespace S { class Bus; } 10 | 11 | namespace Boss { namespace Mod { 12 | 13 | /** class Boss::Mod::ListpaysHandler 14 | * 15 | * @brief Handles `Boss::Msg::RequestListpays` 16 | * messages and emits `Boss::Msg::ResponseListpays` 17 | * in response. 18 | */ 19 | class ListpaysHandler { 20 | private: 21 | S::Bus& bus; 22 | Boss::Mod::Rpc* rpc; 23 | std::vector pending; 24 | 25 | void start(); 26 | Ev::Io listpays(Sha256::Hash); 27 | 28 | public: 29 | ListpaysHandler() =delete; 30 | ListpaysHandler(ListpaysHandler&&) =delete; 31 | ListpaysHandler(ListpaysHandler const&) =delete; 32 | 33 | explicit 34 | ListpaysHandler(S::Bus& bus_) : bus(bus_), rpc(nullptr) { 35 | start(); 36 | } 37 | }; 38 | 39 | }} 40 | 41 | #endif /* !defined(BOSS_MOD_LISTPAYSHANDLER_HPP) */ 42 | -------------------------------------------------------------------------------- /Boss/Mod/ListpeersAnalyzer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_LISTPEERSANALYZER_HPP 2 | #define BOSS_MOD_LISTPEERSANALYZER_HPP 3 | 4 | namespace S { class Bus; } 5 | 6 | namespace Boss { namespace Mod { 7 | 8 | /** class Boss::Mod::ListpeersAnalyzer 9 | * 10 | * @brief converts `Boss::Msg::ListpeersResult` to 11 | * `Boss::Msg::ListpeersAnalyzedResult`. 12 | */ 13 | class ListpeersAnalyzer { 14 | public: 15 | ListpeersAnalyzer(S::Bus&); 16 | }; 17 | 18 | }} 19 | 20 | #endif /* !defined(BOSS_MOD_LISTPEERSANALYZER_HPP) */ 21 | -------------------------------------------------------------------------------- /Boss/Mod/Manifester.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_MANIFESTER_HPP 2 | #define BOSS_MOD_MANIFESTER_HPP 3 | 4 | #include"Boss/Msg/ManifestCommand.hpp" 5 | #include"Boss/Msg/ManifestOption.hpp" 6 | #include 7 | #include 8 | #include 9 | 10 | namespace S { class Bus; } 11 | 12 | namespace Boss { namespace Mod { 13 | 14 | /** class Boss::Mod::Manifester 15 | * 16 | * @brief Makes the plugin manifest itself. 17 | * Responds to `getmanifest` commands. 18 | */ 19 | class Manifester { 20 | private: 21 | S::Bus& bus; 22 | std::map commands; 23 | std::set hooks; 24 | std::set notifications; 25 | std::map options; 26 | 27 | void start(); 28 | 29 | public: 30 | explicit 31 | Manifester(S::Bus& bus_) : bus(bus_) { start(); } 32 | }; 33 | 34 | }} 35 | 36 | #endif /* !defined(BOSS_MOD_MANIFESTER_HPP) */ 37 | -------------------------------------------------------------------------------- /Boss/Mod/MoveFundsCommand.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_MOVEFUNDSCOMMAND_HPP 2 | #define BOSS_MOD_MOVEFUNDSCOMMAND_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::MoveFundsCommand 11 | * 12 | * @brief Provides a debugging `clboss-movefunds` command. 13 | * This command is intended for developer debugging and will 14 | * be removed in the future. 15 | */ 16 | class MoveFundsCommand { 17 | private: 18 | class Impl; 19 | std::unique_ptr pimpl; 20 | 21 | public: 22 | MoveFundsCommand() =delete; 23 | 24 | MoveFundsCommand(MoveFundsCommand&&); 25 | ~MoveFundsCommand(); 26 | 27 | explicit 28 | MoveFundsCommand(S::Bus& bus); 29 | }; 30 | 31 | }} 32 | 33 | #endif /* !defined(BOSS_MOD_MOVEFUNDSCOMMAND_HPP) */ 34 | -------------------------------------------------------------------------------- /Boss/Mod/NeedsConnectSolicitor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_NEEDSCONNECTSOLICITOR_HPP 2 | #define BOSS_MOD_NEEDSCONNECTSOLICITOR_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::NeedsConnectSolicitor 11 | * 12 | * @brief handles NeedsConnect messages. 13 | * 14 | * @desc Handles NeedsConnect messages by 15 | * soliciting connect candidates via 16 | * SolicitConnectCandidates messages, 17 | * and waiting for ProposeConnectCandidates, 18 | * then emitting individual RequestConnect. 19 | */ 20 | class NeedsConnectSolicitor { 21 | private: 22 | class Impl; 23 | std::unique_ptr pimpl; 24 | 25 | public: 26 | explicit 27 | NeedsConnectSolicitor(S::Bus& bus_); 28 | NeedsConnectSolicitor(NeedsConnectSolicitor&&); 29 | ~NeedsConnectSolicitor(); 30 | }; 31 | 32 | }} 33 | 34 | #endif /* !defined(BOSS_MOD_NEEDSCONNECTSOLICITOR_HPP) */ 35 | -------------------------------------------------------------------------------- /Boss/Mod/NeedsOnchainFundsSwapper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_NEEDSONCHAINFUNDSSWAPPER_HPP 2 | #define BOSS_MOD_NEEDSONCHAINFUNDSSWAPPER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::NeedsOnchainFundsSwapper 11 | * 12 | * @brief Handles `Boss::Msg::NeedsOnchainFunds` 13 | * messages, by swapping offchain funds for 14 | * onchain funds. 15 | */ 16 | class NeedsOnchainFundsSwapper { 17 | private: 18 | class Impl; 19 | std::unique_ptr pimpl; 20 | 21 | public: 22 | NeedsOnchainFundsSwapper() =delete; 23 | 24 | NeedsOnchainFundsSwapper(NeedsOnchainFundsSwapper&&); 25 | NeedsOnchainFundsSwapper& operator=(NeedsOnchainFundsSwapper&&); 26 | ~NeedsOnchainFundsSwapper(); 27 | 28 | explicit 29 | NeedsOnchainFundsSwapper(S::Bus& bus); 30 | }; 31 | 32 | }} 33 | 34 | #endif /* !defined(BOSS_MOD_NEEDSONCHAINFUNDSSWAPPER_HPP) */ 35 | -------------------------------------------------------------------------------- /Boss/Mod/NewaddrHandler.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_NEWADDRHANDLER_HPP 2 | #define BOSS_MOD_NEWADDRHANDLER_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Mod { class Rpc; }} 7 | namespace Ev { template class Io; } 8 | namespace S { class Bus; } 9 | 10 | namespace Boss { namespace Mod { 11 | 12 | /** class Boss::Mod::NewaddrHandler 13 | * 14 | * @brief handles `Boss::Msg::RequestNewaddr` 15 | * and responds with `Boss::Msg::ResponseNewaddr`. 16 | */ 17 | class NewaddrHandler { 18 | private: 19 | S::Bus& bus; 20 | Boss::Mod::Rpc* rpc; 21 | std::vector pending; 22 | 23 | void start(); 24 | Ev::Io newaddr(void*); 25 | 26 | public: 27 | NewaddrHandler() =delete; 28 | NewaddrHandler(NewaddrHandler&&) =delete; 29 | NewaddrHandler(NewaddrHandler const&) =delete; 30 | 31 | NewaddrHandler(S::Bus& bus_ 32 | ) : bus(bus_), rpc(nullptr) { start(); } 33 | }; 34 | 35 | }} 36 | 37 | #endif /* !defined(BOSS_MOD_NEWADDRHANDLER_HPP) */ 38 | -------------------------------------------------------------------------------- /Boss/Mod/NodeBalanceSwapper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_NODEBALANCESWAPPER_HPP 2 | #define BOSS_MOD_NODEBALANCESWAPPER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::NodeBalanceSwapper 11 | * 12 | * @brief swaps offchain amounts for 13 | * onchain amounts if our offchain 14 | * incoming capacity is low. 15 | * 16 | * @desc this handles node-level balancing, 17 | * i.e. we should have both incoming and 18 | * outgoing capacity. 19 | * Other modules are responsible for 20 | * channel-level balancing. 21 | */ 22 | class NodeBalanceSwapper { 23 | private: 24 | class Impl; 25 | std::unique_ptr pimpl; 26 | 27 | public: 28 | NodeBalanceSwapper() =delete; 29 | 30 | NodeBalanceSwapper(NodeBalanceSwapper&&); 31 | NodeBalanceSwapper& operator=(NodeBalanceSwapper&&); 32 | ~NodeBalanceSwapper(); 33 | 34 | explicit 35 | NodeBalanceSwapper(S::Bus& bus); 36 | }; 37 | 38 | }} 39 | 40 | #endif /* !defined(BOSS_MOD_NODEBALANCESWAPPER_HPP) */ 41 | -------------------------------------------------------------------------------- /Boss/Mod/OnchainFundsIgnorer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_ONCHAINFUNDSIGNORER_HPP 2 | #define BOSS_MOD_ONCHAINFUNDSIGNORER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::OnchainFundsIgnorer 11 | * 12 | * @brief Provides RPC commands `clboss-ignore-onchain` and 13 | * `clboss-notice-onchain` to tell CLBOSS to ignore onchain 14 | * funds. 15 | * Also exposes the `ignore` flag to other modules via the 16 | * `Msg::RequestGetIgnoreOnchainFlag` message. 17 | */ 18 | class OnchainFundsIgnorer { 19 | private: 20 | class Impl; 21 | std::unique_ptr pimpl; 22 | 23 | public: 24 | OnchainFundsIgnorer() =delete; 25 | OnchainFundsIgnorer(OnchainFundsIgnorer const&) =delete; 26 | 27 | OnchainFundsIgnorer(OnchainFundsIgnorer&&); 28 | ~OnchainFundsIgnorer(); 29 | 30 | explicit 31 | OnchainFundsIgnorer(S::Bus& bus); 32 | }; 33 | 34 | }} 35 | 36 | #endif /* !defined(BOSS_MOD_ONCHAINFUNDSIGNORER_HPP) */ 37 | -------------------------------------------------------------------------------- /Boss/Mod/PaymentDeleter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PAYMENTDELETER_HPP 2 | #define BOSS_MOD_PAYMENTDELETER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::PaymentDeleter 11 | * 12 | * @brief Deletes outgoing payments that CLBOSS initiated. 13 | */ 14 | class PaymentDeleter { 15 | private: 16 | class Impl; 17 | std::unique_ptr pimpl; 18 | 19 | public: 20 | PaymentDeleter() =delete; 21 | 22 | ~PaymentDeleter(); 23 | PaymentDeleter(PaymentDeleter&&); 24 | 25 | explicit 26 | PaymentDeleter(S::Bus& bus); 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MOD_PAYMENTDELETER_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Mod/PeerCompetitorFeeMonitor/Main.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERCOMPETITORFEEMONITOR_MAIN_HPP 2 | #define BOSS_MOD_PEERCOMPETITORFEEMONITOR_MAIN_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { namespace PeerCompetitorFeeMonitor { 9 | 10 | /** class Boss::Mod::PeerCompetitorFeeMonitor::Main 11 | * 12 | * @brief periodically checks the fees that go into 13 | * each of our peers. 14 | */ 15 | class Main { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | Main() =delete; 22 | 23 | Main(Main&&); 24 | Main& operator=(Main&&); 25 | ~Main(); 26 | 27 | explicit 28 | Main(S::Bus& bus); 29 | }; 30 | 31 | }}} 32 | 33 | #endif /* !defined(BOSS_MOD_PEERCOMPETITORFEEMONITOR_MAIN_HPP) */ 34 | -------------------------------------------------------------------------------- /Boss/Mod/PeerCompetitorFeeMonitor/README.md: -------------------------------------------------------------------------------- 1 | This module checks the offchain channel fees of peers-of-peers. 2 | It checks all the incoming directions of every channel of every 3 | peer for their base and proportional channel feerates, and 4 | computes the weighted median (with channel size as the weight). 5 | 6 | The logic here is that this is a reasonable baseline for our 7 | own feerate with that peer. 8 | 9 | This module only performs this measuring and broadcasts the 10 | extracted information. 11 | Other modules should handle the actual changing of our own 12 | feerate. 13 | 14 | - `Surveyor` - Temporary object that measures the median 15 | competitor feerate for a particular node. 16 | - `Main` - Handles events and creates `Surveyor` as needed. 17 | -------------------------------------------------------------------------------- /Boss/Mod/PeerComplaintsDesk/Main.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERCOMPLAINTSDESK_MAIN_HPP 2 | #define BOSS_MOD_PEERCOMPLAINTSDESK_MAIN_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { namespace PeerComplaintsDesk { 9 | 10 | /** class Boss::Mod::PeerComplaintsDesk::Main 11 | * 12 | * @brief main object for the `PeerComplaintsDesk`, which holds 13 | * all the other objects. 14 | */ 15 | class Main { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | Main() =delete; 22 | Main(Main const&) =delete; 23 | 24 | Main(Main&&); 25 | ~Main(); 26 | 27 | explicit 28 | Main(S::Bus& bus); 29 | }; 30 | 31 | }}} 32 | 33 | #endif /* !defined(BOSS_MOD_PEERCOMPLAINTSDESK_MAIN_HPP) */ 34 | -------------------------------------------------------------------------------- /Boss/Mod/PeerComplaintsDesk/Unmanager.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/Mod/PeerComplaintsDesk/Unmanager.hpp" 2 | #include"Boss/Msg/ProvideUnmanagement.hpp" 3 | #include"Boss/Msg/SolicitUnmanagement.hpp" 4 | #include"Ev/Io.hpp" 5 | #include"S/Bus.hpp" 6 | #include 7 | 8 | namespace Boss { namespace Mod { namespace PeerComplaintsDesk { 9 | 10 | Unmanager::Unmanager(S::Bus& bus) { 11 | bus.subscribe ([this, &bus](Msg::SolicitUnmanagement const& _) { 13 | auto fun = [this](Ln::NodeId const& node, bool is_unmanaged) { 14 | if (is_unmanaged) 15 | unmanaged.insert(node); 16 | else 17 | unmanaged.erase(unmanaged.find(node)); 18 | return Ev::lift(); 19 | }; 20 | return bus.raise(Msg::ProvideUnmanagement{ 21 | "close", 22 | std::move(fun) 23 | }); 24 | }); 25 | } 26 | 27 | }}} 28 | -------------------------------------------------------------------------------- /Boss/Mod/PeerComplaintsDesk/Unmanager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERCOMPLAINTSDESK_UNMANAGER_HPP 2 | #define BOSS_MOD_PEERCOMPLAINTSDESK_UNMANAGER_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | #include 6 | 7 | namespace S { class Bus; } 8 | 9 | namespace Boss { namespace Mod { namespace PeerComplaintsDesk { 10 | 11 | /** class Boss::Mod::PeerComplaintsDesk::Unmanager 12 | * 13 | * @brief Holds information on unmanaged `close` nodes. 14 | */ 15 | class Unmanager { 16 | private: 17 | std::set unmanaged; 18 | 19 | public: 20 | Unmanager() =delete; 21 | Unmanager(Unmanager const&) =delete; 22 | 23 | Unmanager(Unmanager&&) =default; 24 | 25 | explicit 26 | Unmanager(S::Bus& bus); 27 | 28 | std::set const& get_unmanaged() const { 29 | return unmanaged; 30 | } 31 | }; 32 | 33 | }}} 34 | 35 | #endif /* !defined(BOSS_MOD_PEERCOMPLAINTSDESK_UNMANAGER_HPP) */ 36 | -------------------------------------------------------------------------------- /Boss/Mod/PeerFromScidMapper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERFROMSCIDMAPPER_HPP 2 | #define BOSS_MOD_PEERFROMSCIDMAPPER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::PeerFromScidMapper 11 | * 12 | * @brief Handles `Boss::Msg::RequestePeerFromScid` messages, 13 | * figuring out the peer node ID from a given SCID, and 14 | * broadcasts `Boss::Msg::ResponsePeerFromScid` in response. 15 | */ 16 | class PeerFromScidMapper { 17 | private: 18 | class Impl; 19 | std::unique_ptr pimpl; 20 | 21 | public: 22 | PeerFromScidMapper() =delete; 23 | PeerFromScidMapper(PeerFromScidMapper const&) =delete; 24 | 25 | PeerFromScidMapper(PeerFromScidMapper&&); 26 | ~PeerFromScidMapper(); 27 | 28 | explicit 29 | PeerFromScidMapper(S::Bus& bus); 30 | }; 31 | 32 | }} 33 | 34 | #endif /* !defined(BOSS_MOD_PEERFROMSCIDMAPPER_HPP) */ 35 | -------------------------------------------------------------------------------- /Boss/Mod/PeerJudge/Info.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERJUDGE_INFO_HPP 2 | #define BOSS_MOD_PEERJUDGE_INFO_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | #include"Ln/NodeId.hpp" 6 | 7 | namespace Boss { namespace Mod { namespace PeerJudge { 8 | 9 | /** struct Boss::Mod::PeerJudge::Info 10 | * 11 | * @brief Contains information gathered about one peer. 12 | */ 13 | struct Info { 14 | Ln::NodeId id; 15 | 16 | /* The size of all CHANNELD_NORMAL channels to the peer. */ 17 | Ln::Amount total_normal; 18 | /* The total earnings over the specified time frame. */ 19 | Ln::Amount earned; 20 | }; 21 | 22 | }}} 23 | 24 | #endif /* !defined(BOSS_MOD_PEERJUDGE_INFO_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Mod/PeerJudge/Unmanager.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/Mod/PeerJudge/Unmanager.hpp" 2 | #include"Boss/Msg/ProvideUnmanagement.hpp" 3 | #include"Boss/Msg/SolicitUnmanagement.hpp" 4 | #include"Ev/Io.hpp" 5 | #include"S/Bus.hpp" 6 | #include 7 | 8 | namespace Boss { namespace Mod { namespace PeerJudge { 9 | 10 | Unmanager::Unmanager(S::Bus& bus) { 11 | bus.subscribe ([this, &bus](Msg::SolicitUnmanagement const& _) { 13 | auto fun = [this](Ln::NodeId const& node, bool is_unmanaged) { 14 | if (is_unmanaged) 15 | unmanaged.insert(node); 16 | else 17 | unmanaged.erase(unmanaged.find(node)); 18 | return Ev::lift(); 19 | }; 20 | return bus.raise(Msg::ProvideUnmanagement{ 21 | "close", 22 | std::move(fun) 23 | }); 24 | }); 25 | } 26 | 27 | }}} 28 | 29 | -------------------------------------------------------------------------------- /Boss/Mod/PeerJudge/Unmanager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERJUDGE_UNMANAGER_HPP 2 | #define BOSS_MOD_PEERJUDGE_UNMANAGER_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | #include 6 | 7 | namespace S { class Bus; } 8 | 9 | namespace Boss { namespace Mod { namespace PeerJudge { 10 | 11 | /** class Boss::Mod::PeerJudge::Unmanager 12 | * 13 | * @brief Holds information on unmanaged `close` nodes. 14 | */ 15 | class Unmanager { 16 | private: 17 | std::set unmanaged; 18 | 19 | public: 20 | Unmanager() =delete; 21 | Unmanager(Unmanager const&) =delete; 22 | 23 | Unmanager(Unmanager&&) =default; 24 | 25 | explicit 26 | Unmanager(S::Bus& bus); 27 | 28 | std::set const& get_unmanaged() const { 29 | return unmanaged; 30 | } 31 | }; 32 | 33 | }}} 34 | 35 | #endif /* !defined(BOSS_MOD_PEERJUDGE_UNMANAGER_HPP) */ 36 | -------------------------------------------------------------------------------- /Boss/Mod/PeerMetrician.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERMETRICIAN_HPP 2 | #define BOSS_MOD_PEERMETRICIAN_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::PeerMetrician 11 | * 12 | * @brief This is not a poet. 13 | * Instead, this queries the peer statistician for raw 14 | * data, then generates metrics we might find useful 15 | * for judging if we should close channels to the peer 16 | * or not. 17 | */ 18 | class PeerMetrician { 19 | private: 20 | class Impl; 21 | std::unique_ptr pimpl; 22 | 23 | public: 24 | PeerMetrician() =delete; 25 | 26 | PeerMetrician(PeerMetrician&&); 27 | ~PeerMetrician(); 28 | 29 | explicit 30 | PeerMetrician(S::Bus& bus); 31 | }; 32 | 33 | }} 34 | 35 | #endif /* !defined(BOSS_MOD_PEERMETRICIAN_HPP) */ 36 | -------------------------------------------------------------------------------- /Boss/Mod/PeerStatistician.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_PEERSTATISTICIAN_HPP 2 | #define BOSS_MOD_PEERSTATISTICIAN_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | class PeerStatistician { 11 | private: 12 | class Impl; 13 | std::unique_ptr pimpl; 14 | 15 | public: 16 | PeerStatistician() =delete; 17 | PeerStatistician(PeerStatistician const&) =delete; 18 | 19 | PeerStatistician(PeerStatistician&&); 20 | ~PeerStatistician(); 21 | 22 | explicit 23 | PeerStatistician(S::Bus& bus); 24 | }; 25 | 26 | }} 27 | 28 | #endif /* !defined(BOSS_MOD_PEERSTATISTICIAN_HPP) */ 29 | -------------------------------------------------------------------------------- /Boss/Mod/RegularActiveProbe.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_REGULARACTIVEPROBE_HPP 2 | #define BOSS_MOD_REGULARACTIVEPROBE_HPP 3 | 4 | namespace S { class Bus; } 5 | 6 | namespace Boss { namespace Mod { 7 | 8 | class RegularActiveProbe { 9 | private: 10 | S::Bus& bus; 11 | 12 | void start(); 13 | 14 | public: 15 | RegularActiveProbe() =delete; 16 | RegularActiveProbe(RegularActiveProbe&&) =delete; 17 | RegularActiveProbe(RegularActiveProbe const&) =delete; 18 | 19 | explicit 20 | RegularActiveProbe(S::Bus& bus_) : bus(bus_) { start(); } 21 | }; 22 | 23 | }} 24 | 25 | #endif /* !defined(BOSS_MOD_REGULARACTIVEPROBE_HPP) */ 26 | -------------------------------------------------------------------------------- /Boss/Mod/RpcWrapper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_RPCWRAPPER_HPP 2 | #define BOSS_MOD_RPCWRAPPER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::RpcWrapper 11 | * 12 | * @brief Handles RPC commands sent via the bus. 13 | * 14 | * @desc This module allows RPC commands to be 15 | * sent via the bus, instead of the `Boss::Mod::Rpc` 16 | * object being sent over the `Boss::Msg::Init` 17 | * message. 18 | * By using the bus, it is easier to test modules 19 | * in isolation, since mocking the RPC. 20 | */ 21 | class RpcWrapper { 22 | private: 23 | class Impl; 24 | std::unique_ptr pimpl; 25 | 26 | public: 27 | RpcWrapper() =delete; 28 | RpcWrapper(RpcWrapper const&) =delete; 29 | 30 | RpcWrapper(RpcWrapper&&); 31 | ~RpcWrapper(); 32 | explicit 33 | RpcWrapper(S::Bus& bus); 34 | }; 35 | 36 | }} 37 | 38 | #endif /* BOSS_MOD_RPCWRAPPER_HPP */ 39 | -------------------------------------------------------------------------------- /Boss/Mod/SelfUptimeMonitor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_SELFUPTIMEMONITOR_HPP 2 | #define BOSS_MOD_SELFUPTIMEMONITOR_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::SelfUptimeMonitor 11 | * 12 | * @brief Monitors our own uptime. 13 | * Uptime is about being internet connected and CLBOSS is running. 14 | */ 15 | class SelfUptimeMonitor { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | SelfUptimeMonitor() =delete; 22 | 23 | SelfUptimeMonitor(SelfUptimeMonitor&&); 24 | ~SelfUptimeMonitor(); 25 | 26 | explicit 27 | SelfUptimeMonitor(S::Bus& bus); 28 | }; 29 | 30 | }} 31 | 32 | #endif /* !defined(BOSS_MOD_SELFUPTIMEMONITOR_HPP) */ 33 | -------------------------------------------------------------------------------- /Boss/Mod/SendpayResultMonitor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_SENDPAYRESULTMONITOR_HPP 2 | #define BOSS_MOD_SENDPAYRESULTMONITOR_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::SendpayResultMonitor 11 | * 12 | * @brief monitors result of `sendpay`/`sendonion` commands, 13 | * and broadcasts `Boss::Msg::SendpayResult` messages. 14 | */ 15 | class SendpayResultMonitor { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | SendpayResultMonitor() =delete; 22 | 23 | SendpayResultMonitor(SendpayResultMonitor&&); 24 | ~SendpayResultMonitor(); 25 | 26 | explicit 27 | SendpayResultMonitor(S::Bus&); 28 | }; 29 | 30 | }} 31 | 32 | #endif /* !defined(BOSS_MOD_SENDPAYRESULTMONITOR_HPP) */ 33 | -------------------------------------------------------------------------------- /Boss/Mod/SwapManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_SWAPMANAGER_HPP 2 | #define BOSS_MOD_SWAPMANAGER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::SwapManager 11 | * 12 | * @brief Handles offchain-to-onchain swaps, 13 | * keeping information needed to track them 14 | * in persistent storage. 15 | */ 16 | class SwapManager { 17 | private: 18 | class Impl; 19 | std::unique_ptr pimpl; 20 | 21 | public: 22 | SwapManager() =delete; 23 | 24 | SwapManager(SwapManager&&); 25 | SwapManager& operator=(SwapManager&&); 26 | ~SwapManager(); 27 | 28 | explicit 29 | SwapManager(S::Bus& bus); 30 | }; 31 | 32 | }} 33 | 34 | #endif /* !defined(BOSS_MOD_SWAPMANAGER_HPP) */ 35 | -------------------------------------------------------------------------------- /Boss/Mod/SwapReporter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_SWAPREPORTER_HPP 2 | #define BOSS_MOD_SWAPREPORTER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::SwapReporter 11 | * 12 | * @brief Monitors all `SwapManager` swaps and makes it available 13 | * on `clboss-status` as well as `clboss-swaps`. 14 | */ 15 | class SwapReporter { 16 | private: 17 | class Impl; 18 | std::unique_ptr pimpl; 19 | 20 | public: 21 | SwapReporter() =delete; 22 | SwapReporter(SwapReporter&&); 23 | ~SwapReporter(); 24 | 25 | explicit 26 | SwapReporter(S::Bus&); 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MOD_SWAPREPORTER_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Mod/TimerTwiceDailyAnnouncer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_TIMERTWICEDAILYANNOUNCER_HPP 2 | #define BOSS_MOD_TIMERTWICEDAILYANNOUNCER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::TimerTwiceDailyAnnouncer 11 | * 12 | * @brief Announces `Msg::TimerTwiceDaily` at slightly less 13 | * than twice a day. 14 | * Ensures that if the previous announce was more than half 15 | * day ago (e.g. we were down) it gets announced now. 16 | */ 17 | class TimerTwiceDailyAnnouncer { 18 | private: 19 | class Impl; 20 | std::unique_ptr pimpl; 21 | 22 | public: 23 | TimerTwiceDailyAnnouncer() =delete; 24 | TimerTwiceDailyAnnouncer(TimerTwiceDailyAnnouncer const&) =delete; 25 | 26 | TimerTwiceDailyAnnouncer(TimerTwiceDailyAnnouncer&&); 27 | ~TimerTwiceDailyAnnouncer(); 28 | explicit 29 | TimerTwiceDailyAnnouncer(S::Bus&); 30 | }; 31 | 32 | }} 33 | 34 | #endif /* !defined(BOSS_MOD_TIMERTWICEDAILYANNOUNCER_HPP) */ 35 | -------------------------------------------------------------------------------- /Boss/Mod/UnmanagedManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_UNMANAGEDMANAGER_HPP 2 | #define BOSS_MOD_UNMANAGEDMANAGER_HPP 3 | 4 | #include 5 | 6 | namespace S { class Bus; } 7 | 8 | namespace Boss { namespace Mod { 9 | 10 | /** class Boss::Mod::UnmanagedManager 11 | * 12 | * @brief Handles the set of unmanaged nodes. 13 | */ 14 | class UnmanagedManager { 15 | private: 16 | class Impl; 17 | std::unique_ptr pimpl; 18 | 19 | public: 20 | UnmanagedManager() =delete; 21 | 22 | UnmanagedManager(UnmanagedManager&&); 23 | ~UnmanagedManager(); 24 | 25 | explicit 26 | UnmanagedManager(S::Bus&); 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MOD_UNMANAGEDMANAGER_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Mod/all.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MOD_ALL_HPP 2 | #define BOSS_MOD_ALL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ev { class ThreadPool; } 9 | namespace Net { class Fd; } 10 | namespace S { class Bus; } 11 | 12 | namespace Boss { namespace Mod { 13 | 14 | /** Boss::Mod::all 15 | * 16 | * @brief Constructs all the modules of the boss. 17 | * Returns a shared pointer to an object that 18 | * cleans up all modules on destruction. 19 | */ 20 | std::shared_ptr all( std::ostream& cout 21 | , S::Bus& bus 22 | , Ev::ThreadPool& threadpool 23 | , std::function< Net::Fd( std::string const& 24 | , std::string const& 25 | ) 26 | > open_rpc_socket 27 | ); 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MOD_ALL_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/ModG/RpcProxy.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/Mod/Rpc.hpp" 2 | #include"Boss/ModG/RpcProxy.hpp" 3 | #include"Boss/Msg/RequestRpcCommand.hpp" 4 | #include"Boss/Msg/ResponseRpcCommand.hpp" 5 | #include"Ev/Io.hpp" 6 | #include"Jsmn/Object.hpp" 7 | #include"Json/Out.hpp" 8 | #include"S/Bus.hpp" 9 | 10 | namespace Boss { namespace ModG { 11 | 12 | RpcProxy::~RpcProxy() =default; 13 | 14 | RpcProxy::RpcProxy(S::Bus& bus) 15 | : core(bus) { } 16 | 17 | Ev::Io 18 | RpcProxy::command( std::string const& command 19 | , Json::Out params 20 | ) { 21 | return core.execute(Msg::RequestRpcCommand{ 22 | nullptr, command, params 23 | }).then([](Msg::ResponseRpcCommand resp) { 24 | if (!resp.succeeded) 25 | throw Mod::RpcError( std::move(resp.command) 26 | , std::move(resp.result) 27 | ); 28 | return Ev::lift(std::move(resp.result)); 29 | }); 30 | } 31 | 32 | }} 33 | -------------------------------------------------------------------------------- /Boss/Msg/AcceptSwapQuotation.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_ACCEPTSWAPQUOTATION_HPP 2 | #define BOSS_MSG_ACCEPTSWAPQUOTATION_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::AcceptSwapQuotation 10 | * 11 | * @brief broadcasted when a particular swap provider 12 | * has been selected for this swap. 13 | * The swap provider must acknowledge this with a 14 | * `Boss::Msg::SwapCreation` identifying the solicitor 15 | * and provider. 16 | */ 17 | struct AcceptSwapQuotation { 18 | /* How much to pay offchain to get funds onchain. */ 19 | Ln::Amount offchain_amount; 20 | /* The onchain address that should receive the funds. */ 21 | std::string onchain_address; 22 | 23 | /* Identify the solicitor that is asking for the swap. */ 24 | void* solicitor; 25 | /* Identify the module that we want to perform the swap. */ 26 | void* provider; 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MSG_ACCEPTSWAPQUOTATION_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Msg/AmountSettings.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_AMOUNTSETTINGS_HPP 2 | #define BOSS_MSG_AMOUNTSETTINGS_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::AmountSettings 9 | * 10 | * @brief Broadcast before `init` completes (before RPC 11 | * and DB are available) with all the various settings 12 | * related to how large the node is. 13 | */ 14 | struct AmountSettings { 15 | /* Minimum and maximum channel size. */ 16 | Ln::Amount min_channel; 17 | Ln::Amount max_channel; 18 | /* How much we will always definitely leave onchain for 19 | * various actions? */ 20 | Ln::Amount reserve; 21 | /* How much should be onchain in order to trigger channel 22 | * creation? 23 | */ 24 | Ln::Amount min_amount; 25 | /* On channel creation, how much to leave onchain at minimum 26 | * for the next channel creation event? */ 27 | Ln::Amount min_remaining; 28 | }; 29 | 30 | }} 31 | 32 | #endif /* !defined(BOSS_MSG_AMOUNTSETTINGS_HPP) */ 33 | -------------------------------------------------------------------------------- /Boss/Msg/AvailableRpcCommands.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_AVAILABLERPCCOMMANDS_HPP 2 | #define BOSS_MSG_AVAILABLERPCCOMMANDS_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::AvailableRpcCommands 10 | * 11 | * @brief Broadcast at startup, containing the commands 12 | * available on the managed C-Lightning node, plus the 13 | * usage of the commands. 14 | */ 15 | struct AvailableRpcCommands { 16 | struct Desc { 17 | std::string category; 18 | /*~ Does not include command name. */ 19 | std::string usage; 20 | }; 21 | /*~ Key is the command name. */ 22 | std::map commands; 23 | }; 24 | 25 | }} 26 | 27 | #endif /* BOSS_MSG_AVAILABLERPCCOMMANDS_HPP */ 28 | -------------------------------------------------------------------------------- /Boss/Msg/Begin.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_BEGIN_HPP 2 | #define BOSS_MSG_BEGIN_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::Begin 7 | * 8 | * @brief message broadcasted at the start of the system. 9 | */ 10 | struct Begin { 11 | }; 12 | 13 | }} 14 | 15 | #endif /* !defined(BOSS_MSG_BEGIN_HPP) */ 16 | -------------------------------------------------------------------------------- /Boss/Msg/Block.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_BLOCK_HPP 2 | #define BOSS_MSG_BLOCK_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::Block 9 | * 10 | * @brief a new block has been processed by lightningd. 11 | * 12 | * @desc emitted at each new block. 13 | * While one block is being emitted, other Block messages 14 | * will not occur, and your module should see Blocks as 15 | * monotonically increasing. 16 | * However, subscribers which block will also delay other 17 | * subscribers (as is usual for S::Bus::raise). 18 | * Modules subscribed to this message should also note 19 | * that some heights can get skipped if blocks come in 20 | * faster than all CLBOSS modules can handle them. 21 | */ 22 | struct Block { 23 | std::uint32_t height; 24 | }; 25 | 26 | }} 27 | 28 | #endif /* !defined(BOSS_MSG_BLOCK_HPP) */ 29 | -------------------------------------------------------------------------------- /Boss/Msg/ChannelCreateResult.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_CHANNELCREATERESULT_HPP 2 | #define BOSS_MSG_CHANNELCREATERESULT_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ChannelCreateResult 9 | * 10 | * @brief used to report that we attempted a 11 | * channel open with the node, and whether 12 | * it succeeded or failed. 13 | */ 14 | struct ChannelCreateResult { 15 | Ln::NodeId node; 16 | bool success; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* !defined(BOSS_MSG_CHANNELCREATERESULT_HPP) */ 22 | 23 | -------------------------------------------------------------------------------- /Boss/Msg/ChannelCreation.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_CHANNELCREATION_HPP 2 | #define BOSS_MSG_CHANNELCREATION_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ChannelCreation 9 | * 10 | * @brief Tells everyone that we now have a new channel 11 | * with a peer. 12 | * This applies regardless of whether it was us who 13 | * initiated the channel, or the peer. 14 | * See also `Boss::Msg::ChannelDestruction`. 15 | */ 16 | struct ChannelCreation { 17 | Ln::NodeId peer; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_CHANNELCREATION_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/ChannelDestruction.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_CHANNELDESTRUCTION_HPP 2 | #define BOSS_MSG_CHANNELDESTRUCTION_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ChannelDestruction 9 | * 10 | * @brief Tells everyone that we lost an existing channel 11 | * with a peer. 12 | * Basically, if we leave `CHANNELD_NORMAL`, or if we leave 13 | * `CHANNELD_AWAITING_LOCKIN` but did not enter 14 | * `CHANNELD_NORMAL`. 15 | * See also `Boss::Msg::ChannelCreation`. 16 | */ 17 | struct ChannelDestruction { 18 | Ln::NodeId peer; 19 | }; 20 | 21 | }} 22 | 23 | #endif /* !defined(BOSS_MSG_CHANNELDESTRUCTION_HPP) */ 24 | -------------------------------------------------------------------------------- /Boss/Msg/ChannelFunds.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_CHANNELFUNDS_HPP 2 | #define BOSS_MSG_CHANNELFUNDS_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ChannelFunds 9 | * 10 | * @brief periodically emitted to inform all modules 11 | * of channel funds. 12 | */ 13 | struct ChannelFunds { 14 | /* Total on all channels. */ 15 | Ln::Amount total; 16 | /* Total on connected channels. */ 17 | Ln::Amount connected; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_CHANNELFUNDS_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/CommandFail.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_COMMANDFAIL_HPP 2 | #define BOSS_MSG_COMMANDFAIL_HPP 3 | 4 | #include"Json/Out.hpp" 5 | #include"Ln/CommandId.hpp" 6 | #include 7 | 8 | namespace Boss { namespace Msg { 9 | 10 | /** struct Boss::Msg::CommandFail 11 | * 12 | * @brief Emit in response to a `Boss::Msg::CommandRequest`, 13 | * to indicate that the command failed. 14 | * If multiple responses for the same ID are emitted, or 15 | * for a nonexistent ID, the extras/nonexistent are 16 | * silently ignored. 17 | */ 18 | struct CommandFail { 19 | Ln::CommandId id; 20 | int code; 21 | std::string message; 22 | Json::Out data; 23 | }; 24 | 25 | }} 26 | 27 | #endif /* !defined(BOSS_MSG_COMMANDFAIL_HPP) */ 28 | -------------------------------------------------------------------------------- /Boss/Msg/CommandRequest.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_COMMANDREQUEST_HPP 2 | #define BOSS_MSG_COMMANDREQUEST_HPP 3 | 4 | #include"Jsmn/Object.hpp" 5 | #include"Ln/CommandId.hpp" 6 | #include 7 | #include 8 | 9 | namespace Boss { namespace Msg { 10 | 11 | /** struct Boss::Msg::CommandRequest 12 | * 13 | * @brief emitted whenever a command or hook is 14 | * received on stdin. 15 | * Respond by Boss::Msg::CommandResponse. 16 | */ 17 | struct CommandRequest { 18 | std::string command; 19 | Jsmn::Object params; 20 | Ln::CommandId id; 21 | }; 22 | 23 | }} 24 | 25 | #endif /* !defined(BOSS_MSG_COMMANDREQUEST_HPP) */ 26 | -------------------------------------------------------------------------------- /Boss/Msg/CommandResponse.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_COMMANDRESPONSE_HPP 2 | #define BOSS_MSG_COMMANDRESPONSE_HPP 3 | 4 | #include"Json/Out.hpp" 5 | #include"Ln/CommandId.hpp" 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::CommandResponse 10 | * 11 | * @brief Emit in response to a Boss::Msg::CommandRequest. 12 | * If multiple responses for the same ID are emitted, or 13 | * for a nonexistent ID, the extras/nonexistent are 14 | * silently ignored. 15 | */ 16 | struct CommandResponse { 17 | Ln::CommandId id; 18 | Json::Out response; 19 | }; 20 | 21 | }} 22 | 23 | #endif /* !defined(BOSS_MSG_COMMANDRESPONSE_HPP) */ 24 | -------------------------------------------------------------------------------- /Boss/Msg/DbResource.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_DBRESOURCE_HPP 2 | #define BOSS_MSG_DBRESOURCE_HPP 3 | 4 | #include"Sqlite3/Db.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::DbResource 9 | * 10 | * @brief provides access to the db. 11 | * 12 | * @desc emitted before `Boss::Msg::Init`. 13 | * The same database is broadcast in this and 14 | * in `Boss::Msg::Init`. 15 | * 16 | * However, this message exists to assist in 17 | * testing otherwise-logic-only modules that 18 | * have persistent data. 19 | * `Init` includes a lot of other items that 20 | * are a pain to mock in testing, so a module 21 | * that is interested only in the database 22 | * and on bus messages can listen to this 23 | * instead of `Init`. 24 | */ 25 | struct DbResource { 26 | Sqlite3::Db db; 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MSG_DBRESOURCE_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Msg/EndOfOptions.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_ENDOFOPTIONS_HPP 2 | #define BOSS_MSG_ENDOFOPTIONS_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::EndOfOptions 7 | * 8 | * @brief Raised at initialization, after all `Boss::Msg::Option` 9 | * messages have been sent. 10 | */ 11 | struct EndOfOptions { }; 12 | 13 | }} 14 | 15 | #endif /* !defined(BOSS_MSG_ENDOFOPTIONS_HPP) */ 16 | -------------------------------------------------------------------------------- /Boss/Msg/ForwardFee.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_FORWARDFEE_HPP 2 | #define BOSS_MSG_FORWARDFEE_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | #include"Ln/NodeId.hpp" 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::ForwardFee 10 | * 11 | * @brief Informs everyone of a *successful* forwarding 12 | * performed by us. 13 | */ 14 | struct ForwardFee { 15 | /* The incoming peer. */ 16 | Ln::NodeId in_id; 17 | /* The outgoing peer. */ 18 | Ln::NodeId out_id; 19 | /* The fee. */ 20 | Ln::Amount fee; 21 | /* The time, in seconds, it took from us receiving the incoming HTLC 22 | * to us receiving the preimage from the outgoing HTLC. */ 23 | double resolution_time; 24 | /* The amount forwarded. */ 25 | Ln::Amount amount; 26 | }; 27 | 28 | }} 29 | 30 | #endif /* !defined(BOSS_MSG_FORWARDFEE_HPP) */ 31 | -------------------------------------------------------------------------------- /Boss/Msg/Init.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_INIT_HPP 2 | #define BOSS_MSG_INIT_HPP 3 | 4 | #include"Boss/Msg/Network.hpp" 5 | #include"Ln/NodeId.hpp" 6 | #include"Sqlite3/Db.hpp" 7 | 8 | namespace Boss { namespace Mod { class Rpc; }} 9 | namespace Net { class Connector; } 10 | namespace Secp256k1 { class SignerIF; } 11 | 12 | namespace Boss { namespace Msg { 13 | 14 | /** struct Boss::Msg::Init 15 | * 16 | * @brief emitted when the `init` command is 17 | * performed. 18 | */ 19 | struct Init { 20 | Network network; 21 | Boss::Mod::Rpc& rpc; 22 | Ln::NodeId self_id; 23 | Sqlite3::Db db; 24 | Net::Connector& connector; 25 | Secp256k1::SignerIF& signer; 26 | /* Empty string if no proxy. */ 27 | std::string proxy; 28 | bool always_use_proxy; 29 | }; 30 | 31 | }} 32 | 33 | #endif /* !defined(BOSS_MSG_INIT_HPP) */ 34 | -------------------------------------------------------------------------------- /Boss/Msg/InternetOnline.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_INTERNETONLINE_HPP 2 | #define BOSS_MSG_INTERNETONLINE_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::InternetOnline 7 | * 8 | * @brief signals to everyone whether we are 9 | * online or not. 10 | * 11 | * @desc Broadcast whenever online-ness changes. 12 | * 13 | * At startup, we are considered offline, so the 14 | * first `Boss::Msg::InternetOnline` would have 15 | * `online` as `true`. 16 | * Conversely, if you are tracking this in your 17 | * module, you can initialize your module to 18 | * assume offline-ness, and once we do our 19 | * initial online check the 20 | * `Boss::Msg::InternetOnline` will update your 21 | * module if we are online after all. 22 | */ 23 | struct InternetOnline { 24 | bool online; 25 | }; 26 | 27 | }} 28 | 29 | #endif /* !defined(BOSS_MSG_INTERNETONLINE_HPP) */ 30 | -------------------------------------------------------------------------------- /Boss/Msg/JsonCin.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_JSONCIN_HPP 2 | #define BOSS_MSG_JSONCIN_HPP 3 | 4 | #include"Jsmn/Object.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | struct JsonCin { 9 | Jsmn::Object obj; 10 | }; 11 | 12 | }} 13 | 14 | #endif /* !defined(BOSS_MSG_JSONCIN_HPP */ 15 | 16 | -------------------------------------------------------------------------------- /Boss/Msg/JsonCout.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_JSONCOUT_HPP 2 | #define BOSS_MSG_JSONCOUT_HPP 3 | 4 | #include"Json/Out.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | struct JsonCout { 9 | Json::Out obj; 10 | }; 11 | 12 | }} 13 | 14 | #endif /* !defined(BOSS_MSG_JSONCOUT_HPP) */ 15 | -------------------------------------------------------------------------------- /Boss/Msg/ListfundsAnalyzedResult.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_LISTFUNDSANALYZEDRESULT_HPP 2 | #define BOSS_MSG_LISTFUNDSANALYZEDRESULT_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ListfundsAnalyzedResult 9 | * 10 | * @brief The result from `listfunds`, analyzed. 11 | */ 12 | struct ListfundsAnalyzedResult { 13 | /* Total funds owned by us, both onchain and offchain. */ 14 | Ln::Amount total_owned; 15 | }; 16 | 17 | }} 18 | 19 | #endif /* !defined(BOSS_MSG_LISTFUNDSANALYZEDRESULT_HPP) */ 20 | -------------------------------------------------------------------------------- /Boss/Msg/ListfundsResult.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_LISTFUNDSRESULT_HPP 2 | #define BOSS_MSG_LISTFUNDSRESULT_HPP 3 | 4 | #include"Jsmn/Object.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ListfundsResult 9 | * 10 | * @brief periodically emitted with the result 11 | * of `listfunds`. 12 | */ 13 | struct ListfundsResult { 14 | /* Known to be an array. */ 15 | Jsmn::Object outputs; 16 | /* Known to be an array. */ 17 | Jsmn::Object channels; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_LISTFUNDSRESULT_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/ListpeersResult.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_LISTPEERSRESULT_HPP 2 | #define BOSS_MSG_LISTPEERSRESULT_HPP 3 | 4 | #include"Boss/Mod/ConstructedListpeers.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ListpeersResult 9 | * 10 | * @brief announced during `init` to inform all 11 | * modules about `listpeers` command result. 12 | * Also announced every 10 minutes. 13 | * 14 | * IMPORTANT - this msg is no longer directly obtained from 15 | * `listpeers` but rather is constructed by "convolving" the value 16 | * from `listpeerchannels`. Specifically, the top level `peer` 17 | * objects are non-standard and only have what CLBOSS uses ... 18 | */ 19 | 20 | struct ListpeersResult { 21 | Boss::Mod::ConstructedListpeers cpeers; 22 | 23 | /* Whether this listpeerchannelss was performed during `init` 24 | * or on the 10-minute timer. 25 | */ 26 | bool initial; 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MSG_LISTPEERSRESULT_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Msg/ManifestCommand.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_MANIFESTCOMMAND_HPP 2 | #define BOSS_MSG_MANIFESTCOMMAND_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ManifestCommand 9 | * 10 | * @brief emitted while handling a Boss::Msg::Manifestation 11 | * in order to register a command. 12 | */ 13 | struct ManifestCommand { 14 | std::string name; 15 | std::string usage; 16 | std::string description; 17 | bool deprecated; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_MANIFESTCOMMAND_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/ManifestHook.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_MANIFESTHOOK_HPP 2 | #define BOSS_MSG_MANIFESTHOOK_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ManifestHook 9 | * 10 | * @brief emitted in respone to Boss::Msg::Manifestation 11 | * to register a hook. 12 | * Multiple modules can register the same hook and listen 13 | * for Boss::Msg::CommandRequest for that hook, though 14 | * only the first one that responds will drive the hook. 15 | */ 16 | struct ManifestHook { 17 | std::string name; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_MANIFESTHOOK_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/ManifestNotification.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_MANIFESTNOTIFICATION_HPP 2 | #define BOSS_MSG_MANIFESTNOTIFICATION_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ManifestNotification 9 | * 10 | * @brief emitted in respone to Boss::Msg::Manifestation 11 | * to register a notification. 12 | * Multiple modules can register the same notification 13 | * and listen for Boss::Msg::Notification. 14 | */ 15 | struct ManifestNotification { 16 | std::string name; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* !defined(BOSS_MSG_MANIFESTNOTIFICATION_HPP) */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/ManifestOption.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_MANIFESTOPTION_HPP 2 | #define BOSS_MSG_MANIFESTOPTION_HPP 3 | 4 | #include"Boss/Msg/OptionType.hpp" 5 | #include"Json/Out.hpp" 6 | #include 7 | 8 | namespace Boss { namespace Msg { 9 | 10 | /** struct Boss::Msg::ManifestOption 11 | * 12 | * @brief emit in response to `Boss::Msg::Manifestation` to 13 | * register an option. 14 | */ 15 | struct ManifestOption { 16 | std::string name; 17 | OptionType type; 18 | Json::Out default_value; 19 | std::string description; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_MANIFESTOPTION_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/Manifestation.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_MANIFESTATION_HPP 2 | #define BOSS_MSG_MANIFESTATION_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::Manifestation 7 | * 8 | * @brief emitted during `getmanifest`. 9 | * Modules triggering on this message should emit 10 | * Boss::Msg::Manifest* messages. 11 | */ 12 | struct Manifestation {}; 13 | 14 | }} 15 | 16 | #endif /* BOSS_MSG_MANIFESTATION_HPP */ 17 | -------------------------------------------------------------------------------- /Boss/Msg/NeedsConnect.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_NEEDSCONNECT_HPP 2 | #define BOSS_MSG_NEEDSCONNECT_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::NeedsConnect 7 | * 8 | * @brief emitted whenever we think we need to 9 | * make a few connections. 10 | * 11 | * @desc Emitted whenever we need connections. 12 | * Note that the purpose of the connection is 13 | * not to make channels, but to get gossip in 14 | * order to learn more about the network. 15 | */ 16 | struct NeedsConnect { }; 17 | 18 | }} 19 | 20 | #endif /* !defined(BOSS_MSG_NEEDSCONNECT_HPP) */ 21 | -------------------------------------------------------------------------------- /Boss/Msg/NeedsOnchainFunds.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_NEEDSONCHAINFUNDS_HPP 2 | #define BOSS_MSG_NEEDSONCHAINFUNDS_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::NeedsOnchainFunds 9 | * 10 | * @brief Broadcasted whenever we have onchain 11 | * funds, but those are too low to practically 12 | * put into reasonable-sized channels. 13 | * This message contains the missing amount. 14 | */ 15 | struct NeedsOnchainFunds { 16 | Ln::Amount needed; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* !defined(BOSS_MSG_NEEDSONCHAINFUNDS_HPP) */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/Network.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_NETWORK_HPP 2 | #define BOSS_MSG_NETWORK_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | enum Network 7 | { Network_Bitcoin 8 | , Network_Testnet 9 | , Network_Regtest 10 | , Network_Signet 11 | }; 12 | 13 | } } 14 | 15 | #endif /* !defined(BOSS_MSG_NETWORK_HPP) */ 16 | -------------------------------------------------------------------------------- /Boss/Msg/Notification.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_NOTIFICATION_HPP 2 | #define BOSS_MSG_NOTIFICATION_HPP 3 | 4 | #include"Jsmn/Object.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::Notification 10 | * 11 | * @brief emitted whenever a notification is 12 | * received on stdin. 13 | */ 14 | struct Notification { 15 | std::string notification; 16 | Jsmn::Object params; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* BOSS_MSG_NOTIFICATION_HPP */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/OnchainFee.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_ONCHAINFEE_HPP 2 | #define BOSS_MSG_ONCHAINFEE_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::OnchainFee 9 | * 10 | * @brief emitted at startup, as well as periodically, 11 | * and reporting whether or not fees are low. 12 | */ 13 | struct OnchainFee { 14 | bool fees_low; 15 | 16 | /* nullptr if unknown, or pointer to some value if known. */ 17 | std::unique_ptr last_feerate; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_ONCHAINFEE_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/OnchainFunds.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_ONCHAINFUNDS_HPP 2 | #define BOSS_MSG_ONCHAINFUNDS_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::OnchainFunds 9 | * 10 | * @brief message sent whenever we notice 11 | * we have some confirmed onchain funds. 12 | * 13 | * @desc the amount indicated already has the 14 | * cost of spending the inputs and creating one 15 | * channel factored in, 16 | * and will thus be lower if your funds are in 17 | * many small inputs than if it were in a single 18 | * big input. 19 | * 20 | * Only deeply-confirmed funds are considered. 21 | * This includes change outputs. 22 | */ 23 | struct OnchainFunds { 24 | Ln::Amount onchain; 25 | }; 26 | 27 | }} 28 | 29 | #endif /* !defined(BOSS_MSG_ONCHAINFUNDS_HPP) */ 30 | -------------------------------------------------------------------------------- /Boss/Msg/Option.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_OPTION_HPP 2 | #define BOSS_MSG_OPTION_HPP 3 | 4 | #include"Jsmn/Object.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::Option 10 | * 11 | * @brief emitted during `init` handling, providing the value 12 | * of an option that we registered. 13 | */ 14 | struct Option { 15 | std::string name; 16 | Jsmn::Object value; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* !defined(BOSS_MSG_OPTION_HPP) */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/OptionType.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_OPTIONTYPE_HPP 2 | #define BOSS_MSG_OPTIONTYPE_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** enum Boss::Msg::OptionType 7 | * 8 | * @brief the types that a `lightningd` option can have. 9 | */ 10 | enum OptionType { 11 | OptionType_String, 12 | OptionType_Bool, 13 | OptionType_Int, 14 | OptionType_Flag 15 | }; 16 | 17 | }} 18 | 19 | #endif /* !defined(BOSS_MSG_OPTIONTYPE_HPP) */ 20 | -------------------------------------------------------------------------------- /Boss/Msg/PatronizeChannelCandidate.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PATRONIZECHANNELCANDIDATE_HPP 2 | #define BOSS_MSG_PATRONIZECHANNELCANDIDATE_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::PatronizeChannelCandidate 10 | * 11 | * @brief emitted asynchronously in response to 12 | * `Boss::Msg::ProposePatronlessChannelCandidate`. 13 | * 14 | * @desc The channel investigator emits this 15 | * message, which triggers the matchmaker to figure 16 | * out a patron using the given nodes as guides. 17 | */ 18 | struct PatronizeChannelCandidate { 19 | Ln::NodeId proposal; 20 | /* A set of nodes which might be a good idea to 21 | * try to target. 22 | * These will not necessarily become the patron, 23 | * but are used as guides to derive *some* patron 24 | * for the proposal. 25 | */ 26 | std::vector guide; 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MSG_PATRONIZECHANNELCANDIDATE_HPP) */ 32 | -------------------------------------------------------------------------------- /Boss/Msg/PayInvoice.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PAYINVOICE_HPP 2 | #define BOSS_MSG_PAYINVOICE_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::PayInvoice 9 | * 10 | * @brief Emitted when we want to pay an 11 | * invoice for some reason. 12 | */ 13 | struct PayInvoice { 14 | std::string invoice; 15 | }; 16 | 17 | }} 18 | 19 | #endif /* !defined(BOSS_MSG_PAYINVOICE_HPP) */ 20 | -------------------------------------------------------------------------------- /Boss/Msg/PeerMedianChannelFee.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PEERMEDIANCHANNELFEE_HPP 2 | #define BOSS_MSG_PEERMEDIANCHANNELFEE_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::PeerMedianChannelFee 10 | * 11 | * @brief broadcast at `init`, and at the random 12 | * hourly timer, informing all modules of the 13 | * median channel fees going *into* our peers. 14 | */ 15 | struct PeerMedianChannelFee { 16 | Ln::NodeId node; 17 | std::uint32_t base; 18 | std::uint32_t proportional; 19 | }; 20 | 21 | }} 22 | 23 | #endif /* !defined(BOSS_MSG_PEERMEDIANCHANNELFEE_HPP) */ 24 | -------------------------------------------------------------------------------- /Boss/Msg/PreinvestigateChannelCandidates.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PREINVESTIGATECHANNELCANDIDATES_HPP 2 | #define BOSS_MSG_PREINVESTIGATECHANNELCANDIDATES_HPP 3 | 4 | #include"Boss/Msg/ProposeChannelCandidates.hpp" 5 | #include 6 | #include 7 | 8 | namespace Boss { namespace Msg { 9 | 10 | /** struct Boss::Msg::PreinvestigateChannelCandidates 11 | * 12 | * @brief emit in order to preinvestigate a set of channel 13 | * candidates. 14 | * 15 | * @desc The preinvestigator will accept this message, then 16 | * connect to each listed `proposal` node, one at a time. 17 | * If it successfullly `connect`s, the preinvestigator will 18 | * emit a `ProposeChannelCandidates` for the main 19 | * investigator. 20 | * 21 | * The preinvestigator will emit only up to `max_candidates` 22 | * successfully-connected candidates. 23 | */ 24 | struct PreinvestigateChannelCandidates { 25 | std::vector candidates; 26 | std::size_t max_candidates; 27 | }; 28 | 29 | }} 30 | 31 | #endif /* !defined(BOSS_MSG_PREINVESTIGATECHANNELCANDIDATES_HPP) */ 32 | 33 | -------------------------------------------------------------------------------- /Boss/Msg/ProbeActively.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PROBEACTIVELY_HPP 2 | #define BOSS_MSG_PROBEACTIVELY_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ProbeActively 9 | * 10 | * @brief requests the active prober to initiate an attempt 11 | * at actively probing the given peer. 12 | */ 13 | struct ProbeActively { 14 | Ln::NodeId peer; 15 | }; 16 | 17 | }} 18 | 19 | #endif /* !defined(BOSS_MSG_PROBEACTIVELY_HPP) */ 20 | -------------------------------------------------------------------------------- /Boss/Msg/ProposeConnectCandidates.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PROPOSECONNECTCANDIDATES_HPP 2 | #define BOSS_MSG_PROPOSECONNECTCANDIDATES_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::ProposeConnectCandidates 10 | * 11 | * @brief propose some connects in response to 12 | * SolicitConnectCandidates. 13 | */ 14 | struct ProposeConnectCandidates { 15 | /* Each string should be of the form id@host:port. */ 16 | std::vector candidates; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* !defined(BOSS_MSG_PROPOSECONNECTCANDIDATES_HPP) */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/ProposePatronlessChannelCandidate.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PROPOSEPATRONLESSCHANNELCANDIDATE_HPP 2 | #define BOSS_MSG_PROPOSEPATRONLESSCHANNELCANDIDATE_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ProposePatronlessChannelCandidate 9 | * 10 | * @brief emit this to propose a channel candidate 11 | * and delegate figuring out a patron for it to 12 | * some other module. 13 | * 14 | * @desc this is not the preferred way of proposing 15 | * channel candidates, as we need some way of guessing 16 | * how much would be a reasonable amount to put into a 17 | * channel with a candidate. 18 | * 19 | * Patrons are how we guess that --- if the candidate 20 | * has good capacity, direct or otherwise, going to 21 | * the patron, then we have sense it is good to open 22 | * larger channels to it. 23 | */ 24 | struct ProposePatronlessChannelCandidate { 25 | Ln::NodeId proposal; 26 | }; 27 | 28 | }} 29 | 30 | #endif /* !defined(BOSS_MSG_PROPOSEPATRONLESSCHANNELCANDIDATE_HPP) */ 31 | -------------------------------------------------------------------------------- /Boss/Msg/ProvideDeletablePaymentLabelFilter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PROVIDEDELETABLEPAYMENTLABELFILTER_HPP 2 | #define BOSS_MSG_PROVIDEDELETABLEPAYMENTLABELFILTER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::ProvideDeletablePaymentLabelFilter 10 | * 11 | * @brief Sent in direct response to the 12 | * `Boss::Msg::SolicitDeletablePaymentLabelFilter` 13 | * message. 14 | * This provides a function that, if it returns true, 15 | * indicates the payment with the given label should 16 | * be deleted. 17 | */ 18 | struct ProvideDeletablePaymentLabelFilter { 19 | std::function filter; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_PROVIDEDELETABLEPAYMENTLABELFILTER_HPP) */ 25 | 26 | -------------------------------------------------------------------------------- /Boss/Msg/ProvideStatus.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PROVIDESTATUS 2 | #define BOSS_MSG_PROVIDESTATUS 3 | 4 | #include"Json/Out.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::ProvideStatus 10 | * 11 | * @brief emitted by modules in response to 12 | * `Boss::Msg::SolicitStatus` in order to 13 | * report their status. 14 | */ 15 | struct ProvideStatus { 16 | /* Field name to use in the status response. */ 17 | std::string key; 18 | /* Content of the field. */ 19 | Json::Out value; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_PROVIDESTATUS) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/ProvideUnmanagement.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_PROVIDEUNMANAGEMENT_HPP 2 | #define BOSS_MSG_PROVIDEUNMANAGEMENT_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Ev { template class Io; } 8 | namespace Ln { class NodeId; } 9 | 10 | namespace Boss { namespace Msg { 11 | 12 | /** struct Boss::Msg::ProvideUnmanagement 13 | * 14 | * @brief Tell the `Boss::Mod::UnmanagedManager` about any unmanagement tags 15 | * this module wants to use, in response to a broadcasted `SolicitUnmanagement`. 16 | */ 17 | struct ProvideUnmanagement { 18 | std::string tag; 19 | /* When initially provided this function is called with `true` for all 20 | * nodes with this tag. 21 | * Then, when a tag is removed or added, this is called with `true` if 22 | * added or `false` if removed. */ 23 | std::function(Ln::NodeId const& node, bool unmanaged)> inform; 24 | }; 25 | 26 | }} 27 | 28 | #endif /* !defined(BOSS_MSG_PROVIDEUNMANAGEMENT_HPP) */ 29 | -------------------------------------------------------------------------------- /Boss/Msg/RaisePeerComplaint.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RAISEPEERCOMPLAINT_HPP 2 | #define BOSS_MSG_RAISEPEERCOMPLAINT_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::RaisePeerComplaint 10 | * 11 | * @brief Emitted by modules to raise complaints about bad peers. 12 | * This should be emitted in direct reaction to the 13 | * `Boss::Msg::SolicitPeerComplaints` message. 14 | */ 15 | struct RaisePeerComplaint { 16 | /* The peer we are complaining about. */ 17 | Ln::NodeId peer; 18 | /* Human-readable string describing the complaint. */ 19 | std::string complaint; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_RAISEPEERCOMPLAINT_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/ReleaseHtlcAccepted.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RELEASEHTLCACCEPTED_HPP 2 | #define BOSS_MSG_RELEASEHTLCACCEPTED_HPP 3 | 4 | #include"Ln/HtlcAccepted.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ReleaseHtlcAccepted 9 | * 10 | * @brief emitted by a module when it has decided on 11 | * how to handle an `htlc_accepted` hook that it 12 | * previously deferred. 13 | * 14 | * @desc `Boss::Mod::HtlcAcceptor` implements a timeout 15 | * on deferred HTLCs, and if the timeout is reached, 16 | * will let the HTLC be handled normally by `lightningd`. 17 | * If you send after the timeout, the acceptor will 18 | * safely ignore it. 19 | * 20 | * HTLCs are identified by the `id` in the request that 21 | * is passed to deferrer functions that were provided in 22 | * `Boss::Msg::ProvideHtlcAcceptedDeferrer` messages. 23 | */ 24 | struct ReleaseHtlcAccepted { 25 | Ln::HtlcAccepted::Response response; 26 | }; 27 | 28 | }} 29 | 30 | #endif /* !defined(BOSS_MSG_RELEASEHTLCACCEPTED_HPP) */ 31 | -------------------------------------------------------------------------------- /Boss/Msg/ReqRespTraits.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQRESPTRAITS_HPP 2 | #define BOSS_MSG_REQRESPTRAITS_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::ReqRespTraits 7 | * 8 | * @brief A traits class, **NOT** an actual message! 9 | * 10 | * @desc This describes how to set or get the `requester` 11 | * field of a `Request` or `Response` message. 12 | * If you have a `void* requester` this Just Works, but 13 | * you can specialize this trait if you want to use a 14 | * different field name for the requester. 15 | */ 16 | template 17 | struct ReqRespTraits { 18 | static void set_requester(Message& m, void* requester) { 19 | m.requester = requester; 20 | } 21 | static void* get_requester(Message const& m) { 22 | return m.requester; 23 | } 24 | }; 25 | 26 | }} 27 | 28 | #endif /* !defined(BOSS_MSG_REQRESPTRAITS_HPP) */ 29 | -------------------------------------------------------------------------------- /Boss/Msg/RequestChannelCreation.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTCHANNELCREATION_HPP 2 | #define BOSS_MSG_REQUESTCHANNELCREATION_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::RequestChannelCreation 9 | * 10 | * @brief emitted when we think it is a good 11 | * idea to create channels now. 12 | * It contains the total amount of bitcoins 13 | * to target to put into channels. 14 | */ 15 | struct RequestChannelCreation { 16 | Ln::Amount amount; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* BOSS_MSG_REQUESTCHANNELCREATION_HPP */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/RequestConnect.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTCONNECT_HPP 2 | #define BOSS_MSG_REQUESTCONNECT_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::RequestConnect 9 | * 10 | * @brief emitted to ask the Connector module 11 | * to connect a specific node, and then respond 12 | * with whether the connection succeeded or not. 13 | */ 14 | struct RequestConnect { 15 | /* Can be just nodeid, or else nodeid@host:port, or basically 16 | * anything the `connect` command understands. */ 17 | std::string node; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_REQUESTCONNECT_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/RequestDowser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTDOWSER_HPP 2 | #define BOSS_MSG_REQUESTDOWSER_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::RequestDowser 9 | * 10 | * @brief Requests for a dowser estimation of the flow between 11 | * two nodes. 12 | * 13 | * @desc The dowser just guesses how much capacity is available 14 | * between the two specified nodes. 15 | */ 16 | struct RequestDowser { 17 | void* requester; 18 | Ln::NodeId fromid; 19 | Ln::NodeId toid; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_REQUESTDOWSER_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/RequestEarningsInfo.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTEARNINGSINFO_HPP 2 | #define BOSS_MSG_REQUESTEARNINGSINFO_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::RequestEarningsInfo 9 | * 10 | * @brief Requests to get information about fee earnings, as well 11 | * as debits due to rebalancings, about a node. 12 | */ 13 | struct RequestEarningsInfo { 14 | void* requester; 15 | Ln::NodeId node; 16 | }; 17 | 18 | }} 19 | 20 | #endif /* !defined(BOSS_MSG_REQUESTEARNINGSINFO_HPP) */ 21 | -------------------------------------------------------------------------------- /Boss/Msg/RequestGetOnchainIgnoreFlag.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTGETONCHAINIGNOREFLAG_HPP 2 | #define BOSS_MSG_REQUESTGETONCHAINIGNOREFLAG_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::RequestGetOnchainIgnoreFlag 7 | * 8 | * @brief emit in order to query if we should be ignoring onchain 9 | * funds now or not. 10 | * This will be replied to with `ResponseGetOnchainIgnoreFlag`. 11 | */ 12 | struct RequestGetOnchainIgnoreFlag { 13 | void* requester; 14 | }; 15 | 16 | }} 17 | 18 | #endif /* BOSS_MSG_REQUESTGETONCHAINIGNOREFLAG_HPP */ 19 | -------------------------------------------------------------------------------- /Boss/Msg/RequestListpays.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTLISTPAYS_HPP 2 | #define BOSS_MSG_REQUESTLISTPAYS_HPP 3 | 4 | #include"Sha256/Hash.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::RequestListpays 9 | * 10 | * @brief emitted whenever some module wants 11 | * to know the status of some payment. 12 | * 13 | * @desc the listpays handler will emit a 14 | * `Boss::Msg::ResponseListpays` in response 15 | * to this. 16 | */ 17 | struct RequestListpays { 18 | /* What about a future with payment points??? */ 19 | Sha256::Hash payment_hash; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_REQUESTLISTPAYS_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/RequestMoveFunds.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTMOVEFUNDS_HPP 2 | #define BOSS_MSG_REQUESTMOVEFUNDS_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | #include"Ln/NodeId.hpp" 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::RequestMoveFunds 10 | * 11 | * @brief Requests to move funds from the channel of one 12 | * peer to the channel of another peer. 13 | */ 14 | struct RequestMoveFunds { 15 | /* Pointer to the object that requested moving 16 | * funds. */ 17 | void* requester; 18 | /* Node from which channel funds will be removed. */ 19 | Ln::NodeId source; 20 | /* Node to which channel funds will be moved. */ 21 | Ln::NodeId destination; 22 | /* Amount to move. */ 23 | Ln::Amount amount; 24 | /* Fee budget. */ 25 | Ln::Amount fee_budget; 26 | }; 27 | 28 | }} 29 | 30 | #endif /* !defined(BOSS_MSG_REQUESTMOVEFUNDS_HPP) */ 31 | -------------------------------------------------------------------------------- /Boss/Msg/RequestNewaddr.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTNEWADDR_HPP 2 | #define BOSS_MSG_REQUESTNEWADDR_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::RequestNewaddr 7 | * 8 | * @brief emitted to request for a new 9 | * address. 10 | */ 11 | struct RequestNewaddr { 12 | void* requester; 13 | }; 14 | 15 | }} 16 | 17 | #endif /* !defined(BOSS_MSG_REQUESTNEWADDR_HPP) */ 18 | -------------------------------------------------------------------------------- /Boss/Msg/RequestPeerFromScid.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTPEERFROMSCID_HPP 2 | #define BOSS_MSG_REQUESTPEERFROMSCID_HPP 3 | 4 | #include"Ln/Scid.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::RequestPeerFromScid 9 | * 10 | * @brief requests the peer `Ln::NodeId` from the 11 | * given `Ln::Scid`. 12 | */ 13 | struct RequestPeerFromScid { 14 | void* requester; 15 | Ln::Scid scid; 16 | }; 17 | 18 | }} 19 | 20 | #endif /* !defined(BOSS_MSG_REQUESTPEERFROMSCID_HPP) */ 21 | -------------------------------------------------------------------------------- /Boss/Msg/RequestPeerMetrics.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTPEERMETRICS_HPP 2 | #define BOSS_MSG_REQUESTPEERMETRICS_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::RequestPeerMetrics 7 | * 8 | * @brief emit this in order to request peer metrics. 9 | */ 10 | struct RequestPeerMetrics { 11 | /* Used to identify the object requesting 12 | * for peer metrics. 13 | * Will be copied in the corresponding 14 | * `Boss::Msg::ResponsePeerMetrics`. 15 | */ 16 | void* requester; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* !defined(BOSS_MSG_REQUESTPEERMETRICS_HPP) */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/RequestPeerStatistics.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTPEERSTATISTICS_HPP 2 | #define BOSS_MSG_REQUESTPEERSTATISTICS_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::RequestPeerStatistics 7 | * 8 | * @brief emit to request the `Boss::Mod::PeerStatistician` 9 | * for data from all peers in the given time frame. 10 | * 11 | * @desc The given `requester` pointer will be copied in 12 | * the corresponding `Boss::Msg::ResponsePeerStatistics`. 13 | * The peer statistician will only keep data for the last 14 | * three months. 15 | */ 16 | struct RequestPeerStatistics { 17 | void* requester; 18 | /* Time frame, in seconds from the epoch. 19 | * start_time < end_time. 20 | */ 21 | double start_time; 22 | double end_time; 23 | }; 24 | 25 | }} 26 | 27 | #endif /* !defined(BOSS_MSG_REQUESTPEERSTATISTICS_HPP) */ 28 | -------------------------------------------------------------------------------- /Boss/Msg/RequestRebalanceUnmanaged.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTREBALANCEUNMANAGED_HPP 2 | #define BOSS_MSG_REQUESTREBALANCEUNMANAGED_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::RequestRebalanceUnmanaged 7 | * 8 | * @brief Requests the `Boss::Mod::RebalanceUnmanager` to provide 9 | * the list of unmanaged-for-rebalance nodes. 10 | */ 11 | struct RequestRebalanceUnmanaged { 12 | void* requester; 13 | }; 14 | 15 | }} 16 | 17 | #endif /* !defined(BOSS_MSG_REQUESTREBALANCEUNMANAGED_HPP) */ 18 | -------------------------------------------------------------------------------- /Boss/Msg/RequestRpcCommand.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTRPCCOMMAND_HPP 2 | #define BOSS_MSG_REQUESTRPCCOMMAND_HPP 3 | 4 | #include"Json/Out.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::RequestRpcCommand 10 | * 11 | * @brief Requests an RPC command to be sent to the 12 | * `lightningd`. 13 | * This is handled by the `Boss::Mod::RpcWrapper`. 14 | * The result of the command will then be broadcast 15 | * via `Boss::Msg::ResponseRpcCommand`. 16 | */ 17 | struct RequestRpcCommand { 18 | /*~ The object that requested the RPC command. */ 19 | void* requester; 20 | /*~ The command to execute. */ 21 | std::string command; 22 | /*~ The parameters to the command. */ 23 | Json::Out params; 24 | }; 25 | 26 | }} 27 | 28 | #endif /* BOSS_MSG_REQUESTRPCCOMMAND_HPP */ 29 | -------------------------------------------------------------------------------- /Boss/Msg/RequestSelfUptime.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_REQUESTSELFUPTIME_HPP 2 | #define BOSS_MSG_REQUESTSELFUPTIME_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::RequestSelfUptime 7 | * 8 | * @brief queries our own uptime. 9 | * The `Boss::Mod::SelfUptimeMonitor` will respond with a 10 | * `Boss::Msg::ResponseSelfUptime` message. 11 | */ 12 | struct RequestSelfUptime { 13 | void* requester; 14 | }; 15 | 16 | }} 17 | 18 | #endif /* !defined(BOSS_MSG_REQUESTSELFUPTIME_HPP) */ 19 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseConnect.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSECONNECT_HPP 2 | #define BOSS_MSG_RESPONSECONNECT_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ResponseConnect 9 | * 10 | * @brief sent in response to a RequestConnect. 11 | */ 12 | struct ResponseConnect { 13 | std::string node; 14 | bool success; 15 | }; 16 | 17 | }} 18 | 19 | #endif /* !defined(BOSS_MSG_RESPONSECONNECT_HPP) */ 20 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseDowser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSEDOWSER_HPP 2 | #define BOSS_MSG_RESPONSEDOWSER_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ResponseDowser 9 | * 10 | * @brief Emitted in response to `Boss::Msg::RequestDowser`. 11 | * 12 | * @desc this contains the estimated practical capacity between the two 13 | * nodes. 14 | */ 15 | struct ResponseDowser { 16 | void* requester; 17 | Ln::Amount amount; 18 | }; 19 | 20 | }} 21 | 22 | #endif /* !defined(BOSS_MSG_RESPONSEDOWSER_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseGetOnchainIgnoreFlag.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSEGETONCHAINIGNOREFLAG_HPP 2 | #define BOSS_MSG_RESPONSEGETONCHAINIGNOREFLAG_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::ResponseGetOnchainIgnoreFlag 7 | * 8 | * @brief Emitted in response to `RequestGetOnchainIgnoreFlag`. 9 | */ 10 | struct ResponseGetOnchainIgnoreFlag { 11 | void* requester; 12 | /* Set if we should be ignoring onchain funds. */ 13 | bool ignore; 14 | /* If ignore is true, how many more seconds to be waiting. */ 15 | double seconds; 16 | }; 17 | 18 | }} 19 | 20 | #endif /* BOSS_MSG_RESPONSEGETONCHAINIGNOREFLAG_HPP */ 21 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseListpays.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSELISTPAYS_HPP 2 | #define BOSS_MSG_RESPONSELISTPAYS_HPP 3 | 4 | #include"Boss/Msg/StatusListpays.hpp" 5 | #include"Ln/Amount.hpp" 6 | #include"Ln/NodeId.hpp" 7 | #include"Sha256/Hash.hpp" 8 | 9 | namespace Boss { namespace Msg { 10 | 11 | /** struct Boss::Msg::ResponseListpays 12 | * 13 | * @brief emitted in response to a 14 | * `Boss::Msg::RequestListpays` message. 15 | * Contains details of the payment. 16 | */ 17 | struct ResponseListpays { 18 | Sha256::Hash payment_hash; 19 | 20 | /* Status of the payment. */ 21 | StatusListpays status; 22 | /* Who the payee is. 23 | * Not valid if status is nonexistent. 24 | */ 25 | Ln::NodeId payee; 26 | 27 | /* These are only valid if the payment succeeded. */ 28 | /* Amount we think reached the payee. */ 29 | Ln::Amount amount; 30 | /* Amount we think we released. */ 31 | Ln::Amount amount_sent; 32 | }; 33 | 34 | }} 35 | 36 | #endif /* !defined(BOSS_MSG_RESPONSELISTPAYS_HPP) */ 37 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseMoveFunds.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSEMOVEFUNDS_HPP 2 | #define BOSS_MSG_RESPONSEMOVEFUNDS_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ResponseMoveFunds 9 | * 10 | * @brief Response from the corresponding 11 | * `Boss::Msg::RequestMoveFunds` message. 12 | */ 13 | struct ResponseMoveFunds { 14 | void* requester; 15 | 16 | /* Actual amount we were able to move before giving up. */ 17 | Ln::Amount amount_moved; 18 | /* Actual amount spent on fees. */ 19 | Ln::Amount fee_spent; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_RESPONSEMOVEFUNDS_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseNewaddr.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSENEWADDR_HPP 2 | #define BOSS_MSG_RESPONSENEWADDR_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ResponseNewaddr 9 | * 10 | * @brief emitted in response to a 11 | * `Boss::Msg::RequestNewaddr` 12 | */ 13 | struct ResponseNewaddr { 14 | std::string address; 15 | void* requester; 16 | }; 17 | 18 | }} 19 | 20 | #endif /* !defined(BOSS_MSG_RESPONSENEWADDR_HPP) */ 21 | -------------------------------------------------------------------------------- /Boss/Msg/ResponsePeerFromScid.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RSEPONSEPEERFROMSCID_HPP 2 | #define BOSS_MSG_RSEPONSEPEERFROMSCID_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::ResponsePeerFromScid 9 | * 10 | * @brief returns the peer `Ln::NodeId` from the given 11 | * `Ln::Scid`. 12 | * Broadcast in response to `Boss::Msg::RequestPeerFromScid`. 13 | * The peer may be `nullptr` if the given `Ln::Scid` was 14 | * not recognized. 15 | */ 16 | struct ResponsePeerFromScid { 17 | void* requester; 18 | Ln::Scid scid; 19 | Ln::NodeId peer; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_RSEPONSEPEERFROMSCID_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/ResponsePeerMetrics.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSEPEERMETRICS_HPP 2 | #define BOSS_MSG_RESPONSEPEERMETRICS_HPP 3 | 4 | #include"Boss/Msg/PeerMetrics.hpp" 5 | #include"Ln/NodeId.hpp" 6 | #include 7 | 8 | namespace Boss { namespace Msg { 9 | 10 | /** struct Boss::Msg::ResponsePeerMetrics 11 | * 12 | * @brief eventually emitted in response to a 13 | * `Boss::Msg::RequestPeerMetrics` with the 14 | * `requester` field copied. 15 | * 16 | * @desc contains metrics from recorded statistical 17 | * data for the last 3 days, 2 weeks, and month. 18 | */ 19 | struct ResponsePeerMetrics { 20 | void* requester; 21 | 22 | std::map day3; 23 | std::map weeks2; 24 | std::map month1; 25 | }; 26 | 27 | }} 28 | 29 | #endif /* !defined(BOSS_MSG_RESPONSEPEERMETRICS_HPP) */ 30 | -------------------------------------------------------------------------------- /Boss/Msg/ResponsePeerStatistics.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSEPEERSTATISTICS_HPP 2 | #define BOSS_MSG_RESPONSEPEERSTATISTICS_HPP 3 | 4 | #include"Boss/Msg/PeerStatistics.hpp" 5 | #include"Ln/NodeId.hpp" 6 | #include 7 | 8 | namespace Boss { namespace Msg { 9 | 10 | /** struct Boss::Msg::ResponsePeerStatistics 11 | * 12 | * @brief Raised in response to `Boss::Msg::RequestPeerStatistics`. 13 | * Contains all data about all peers that were present in the 14 | * requested time frame. 15 | */ 16 | struct ResponsePeerStatistics { 17 | void* requester; 18 | 19 | std::map statistics; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_RESPONSEPEERSTATISTICS_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseRebalanceUnmanaged.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSEREBALANCEUNMANAGED_HPP 2 | #define BOSS_MSG_RESPONSEREBALANCEUNMANAGED_HPP 3 | 4 | #include 5 | 6 | namespace Ln { class NodeId; } 7 | 8 | namespace Boss { namespace Msg { 9 | 10 | /** struct Boss::Msg::ResponseRebalanceUnmanaged 11 | * 12 | * @brief Broadcasted by `Boss::Mod::RebalanceUnmanager` in response 13 | * to `Boss::Msg::RequestRebalanceUnmanaged`. 14 | */ 15 | struct ResponseRebalanceUnmanaged { 16 | void* requester; 17 | 18 | std::set const& unmanaged; 19 | }; 20 | 21 | }} 22 | 23 | #endif /* !defined(BOSS_MSG_RESPONSEREBALANCEUNMANAGED_HPP) */ 24 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseRpcCommand.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSERPCCOMMAND_HPP 2 | #define BOSS_MSG_RESPONSERPCCOMMAND_HPP 3 | 4 | #include"Jsmn/Object.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::ResponseRpcCommand 10 | * 11 | * @brief Broadcast in response to `Boss::Msg::RequestRpcCommand`, 12 | * after the corresponding command has succeeded or failed. 13 | */ 14 | struct ResponseRpcCommand { 15 | /*~ The object that requested the RPC command. */ 16 | void* requester; 17 | /*~ True if the command succeded. */ 18 | bool succeeded; 19 | /*~ Result if succeeded, or the error if failed. */ 20 | Jsmn::Object result; 21 | /*~ The command that failed if it failed, empty if the 22 | * command succeeded. 23 | */ 24 | std::string command; 25 | }; 26 | 27 | }} 28 | 29 | #endif /* BOSS_MSG_RESPONSERPCCOMMAND_HPP */ 30 | -------------------------------------------------------------------------------- /Boss/Msg/ResponseSelfUptime.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RESPONSESELFUPTIME_HPP 2 | #define BOSS_MSG_RESPONSESELFUPTIME_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::ResponseSelfUptime 7 | * 8 | * @brief Broadcast in response to `Boss::Msg::RequestSelfUptime` to 9 | * provide uptime information. 10 | */ 11 | struct ResponseSelfUptime { 12 | void* requester; 13 | 14 | /* Uptime in the last 3 days. */ 15 | double day3; 16 | /* Uptime in the last 14 days. */ 17 | double weeks2; 18 | /* Uptime in the last 30 days. */ 19 | double month1; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_RESPONSESELFUPTIME_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/RpcCommandHook.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_RPCCOMMANDHOOK_HPP 2 | #define BOSS_MSG_RPCCOMMANDHOOK_HPP 3 | 4 | #include"Jsmn/Object.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::RpcCommandHook 9 | * 10 | * @brief Emitted in response to the `lightningd` receiving 11 | * an RPC command. 12 | * 13 | * @desc This does not require or wait for a response: the 14 | * `Boss::Mod::CommandReceiver` specially treats `rpc_command` 15 | * hooks and responds to those immediately. 16 | * After responding, the `CommandReceiver` emits this message. 17 | */ 18 | struct RpcCommandHook { 19 | Jsmn::Object params; 20 | }; 21 | 22 | }} 23 | 24 | #endif /* !defined(BOSS_MSG_RPCCOMMANDHOOK_HPP) */ 25 | -------------------------------------------------------------------------------- /Boss/Msg/SetChannelFee.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SETCHANNELFEE_HPP 2 | #define BOSS_MSG_SETCHANNELFEE_HPP 3 | 4 | #include"Ln/NodeId.hpp" 5 | #include 6 | 7 | namespace Boss { namespace Msg { 8 | 9 | /** struct Boss::Msg::SetChannelFee 10 | * 11 | * @brief Emit to set the channel fees of a peer node. 12 | */ 13 | struct SetChannelFee { 14 | Ln::NodeId node; 15 | std::uint32_t base; 16 | std::uint32_t proportional; 17 | }; 18 | 19 | }} 20 | 21 | #endif /* !defined(BOSS_MSG_SETCHANNELFEE_HPP) */ 22 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitChannelCandidates.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITCHANNELCANDIDATES_HPP 2 | #define BOSS_MSG_SOLICITCHANNELCANDIDATES_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::SolicitChannelCandidates 7 | * 8 | * @brief emitted whenever we think we need 9 | * new channel candidates. 10 | * 11 | * @desc Unlike SolicitConnectCandidates, modules 12 | * do not need to immediately respond with 13 | * ProposeChannelCandidates; 14 | * they can run in the background and then emit 15 | * proposals later. 16 | * 17 | * Channel candidates need to be evaluated for a 18 | * while first before we consider them ready for 19 | * making channels with. 20 | */ 21 | struct SolicitChannelCandidates { }; 22 | 23 | }} 24 | 25 | #endif /* !defined(BOSS_MSG_SOLICITCHANNELCANDIDATES_HPP) */ 26 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitChannelFeeModifier.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITCHANNELFEEMODIFIER_HPP 2 | #define BOSS_MSG_SOLICITCHANNELFEEMODIFIER_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::SolicitChannelFeeModifier 7 | * 8 | * @brief sent when the `Boss::Mod::ChannelFeeSetter` 9 | * wants to know how the other modules would like 10 | * fees to be modified. 11 | * 12 | * @desc Modules that want to modify the channel fees 13 | * should emit `Boss::Msg::ProvideChannelFeeModifier` 14 | * messages synchronously in response to this message. 15 | */ 16 | struct SolicitChannelFeeModifier {}; 17 | 18 | }} 19 | 20 | #endif /* !defined(BOSS_MSG_SOLICITCHANNELFEEMODIFIER_HPP) */ 21 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitConnectCandidates.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITCONNECTCANDIDATES_HPP 2 | #define BOSS_MSG_SOLICITCONNECTCANDIDATES_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::SolicitConnectCandidates 7 | * 8 | * @brief emitted when we want to look for new 9 | * candidates to connect to. 10 | * 11 | * @desc Modules waiting on this message should 12 | * emit a ProposeConnectCandidates message in 13 | * response to this message. 14 | */ 15 | struct SolicitConnectCandidates {}; 16 | 17 | }} 18 | 19 | #endif /* BOSS_MSG_SOLICITCONNECTCANDIDATES_HPP */ 20 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitDeletablePaymentLabelFilter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITDELETABLEPAYMENTLABELFILTER_HPP 2 | #define BOSS_MSG_SOLICITDELETABLEPAYMENTLABELFILTER_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::SolicitDeletablePaymentLabelFilter 7 | * 8 | * @brief Broadcast over the bus to ask for filter functions 9 | * to determine if we should delete a completed/failed 10 | * payment. 11 | * Clients should respond with 12 | * `Boss::Msg::ProvideDeletablePaymentLabelFilter`. 13 | */ 14 | struct SolicitDeletablePaymentLabelFilter {}; 15 | 16 | }} 17 | 18 | #endif /* !defined(BOSS_MSG_SOLICITDELETABLEPAYMENTLABELFILTER_HPP) */ 19 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitHtlcAcceptedDeferrer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITHTLCACCEPTEDDEFERRER_HPP 2 | #define BOSS_MSG_SOLICITHTLCACCEPTEDDEFERRER_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::SolicitHtlcAcceptedDeferrer 7 | * 8 | * @brief broadcast to inform all modules that we want to 9 | * get `Boss::Msg::ProvideHtlcAcceptedDeferrer` messages. 10 | * Modules that want to register their deferrer functions 11 | * should synchronously reply to this message. 12 | */ 13 | struct SolicitHtlcAcceptedDeferrer {}; 14 | 15 | }} 16 | 17 | #endif /* !defined(BOSS_MSG_SOLICITHTLCACCEPTEDDEFERRER_HPP) */ 18 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitPeerComplaints.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITPEERCOMPLAINTS_HPP 2 | #define BOSS_MSG_SOLICITPEERCOMPLAINTS_HPP 3 | 4 | #include"Boss/Msg/PeerMetrics.hpp" 5 | #include"Ln/NodeId.hpp" 6 | #include 7 | 8 | namespace Boss { namespace Msg { 9 | 10 | /** struct Boss::Msg::SolicitPeerComplaints 11 | * 12 | * @brief emitted periodically to solicit complaints about bad 13 | * peers from our modules. 14 | * Modules should emit `Boss::Msg::RaisePeerComplaint` messages 15 | * in direct reaction to this message. 16 | * 17 | * @desc This message also contains the latest peer metrics, for 18 | * the convenience of modules which just use the peer metrics. 19 | */ 20 | struct SolicitPeerComplaints { 21 | std::map day3; 22 | std::map weeks2; 23 | std::map month1; 24 | }; 25 | 26 | }} 27 | 28 | #endif /* !defined(BOSS_MSG_SOLICITPEERCOMPLAINTS_HPP) */ 29 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitStatus.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITSTATUS 2 | #define BOSS_MSG_SOLICITSTATUS 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::SolicitStatus 7 | * 8 | * @brief emitted whenever the user issues a 9 | * `clboss-status` command. 10 | * Modules should respond synchronously with 11 | * `Boss::Msg::ProvideStatus` messages. 12 | */ 13 | struct SolicitStatus {}; 14 | 15 | }} 16 | 17 | #endif /* !defined(BOSS_MSG_SOLICITSTATUS) */ 18 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitSwapQuotation.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITSWAPQUOTATION_HPP 2 | #define BOSS_MSG_SOLICITSWAPQUOTATION_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::SolicitSwapQuotation 9 | * 10 | * @brief Broadcasted whenever the swap manager wants to get 11 | * quotes on swapping offchain funds for onchain funds. 12 | * Modules listening to this message must reply synchronously 13 | * with `Boss::Msg::ProvideSwapQuotation` messages. 14 | */ 15 | struct SolicitSwapQuotation { 16 | /* How much offchain amount we want to send out. */ 17 | Ln::Amount offchain_amount; 18 | /* The module asking for quotation. 19 | * This is replicated as well in the 20 | * `Boss::Msg::ProvideSwapQuotation` 21 | * message to indicate which solicit 22 | * is being responded to. 23 | */ 24 | void* solicitor; 25 | }; 26 | 27 | }} 28 | 29 | #endif /* !defined(BOSS_MSG_SOLICITSWAPQUOTATION_HPP) */ 30 | -------------------------------------------------------------------------------- /Boss/Msg/SolicitUnmanagement.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SOLICITUNMANAGEMENT_HPP 2 | #define BOSS_MSG_SOLICITUNMANAGEMENT_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::SolicitUnmanagement 7 | * 8 | * @brief Asks other modules to register their unmanagement tags to the 9 | * `Boss::Mod::UnmanagedManager`. 10 | * Modules should immediately respond with a `ProvideUnmanagement` 11 | * message. 12 | */ 13 | struct SolicitUnmanagement { }; 14 | 15 | }} 16 | 17 | #endif /* !defined(BOSS_MSG_SOLICITUNMANAGEMENT_HPP) */ 18 | -------------------------------------------------------------------------------- /Boss/Msg/StatusListpays.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_STATUSLISTPAYS_HPP 2 | #define BOSS_MSG_STATUSLISTPAYS_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** enum Boss::Msg::StatusListpays 7 | * 8 | * @brief the possible status of some payment. 9 | */ 10 | enum StatusListpays 11 | { StatusListpays_nonexistent 12 | , StatusListpays_success 13 | , StatusListpays_pending 14 | , StatusListpays_failed 15 | }; 16 | 17 | }} 18 | 19 | #endif /* !defined(BOSS_MSG_STATUSLISTPAYS_HPP) */ 20 | -------------------------------------------------------------------------------- /Boss/Msg/SwapCompleted.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_SWAPCOMPLETED_HPP 2 | #define BOSS_MSG_SWAPCOMPLETED_HPP 3 | 4 | #include"Ln/Amount.hpp" 5 | #include 6 | 7 | namespace Sqlite3 { class Tx; } 8 | 9 | namespace Boss { namespace Msg { 10 | 11 | /** struct Boss::Msg::SwapCompleted 12 | * 13 | * @brief broadcasted whenever the `SwapManager` has 14 | * finished a swap. 15 | */ 16 | struct SwapCompleted { 17 | /* Database transaction initiated by the `SwapManager`. 18 | * It will be committed by the `SwapManager` after the 19 | * broadcast. 20 | */ 21 | std::shared_ptr dbtx; 22 | 23 | /* The amount that was swapped out. */ 24 | Ln::Amount amount_sent; 25 | /* The amount we got. */ 26 | Ln::Amount amount_received; 27 | 28 | /* The swap provider name. */ 29 | std::string provider_name; 30 | }; 31 | 32 | }} 33 | 34 | #endif /* !defined(BOSS_MSG_SWAPCOMPLETED_HPP) */ 35 | -------------------------------------------------------------------------------- /Boss/Msg/TaskCompletion.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_TASKCOMPLETION_HPP 2 | #define BOSS_MSG_TASKCOMPLETION_HPP 3 | 4 | #include 5 | 6 | namespace Boss { namespace Msg { 7 | 8 | /** struct Boss::Msg::TaskCompletion 9 | * 10 | * @brief signals completion of some task. 11 | * 12 | * @desc This is generally used in testing. 13 | */ 14 | struct TaskCompletion { 15 | /* Some description of the task that was completed. */ 16 | std::string comment; 17 | /* Usually the address of the module that completed a task. */ 18 | void *identifier; 19 | /* True if the task failed. */ 20 | bool failed; 21 | }; 22 | 23 | }} 24 | 25 | #endif /* !defined(BOSS_MSG_TASKCOMPLETION_HPP) */ 26 | -------------------------------------------------------------------------------- /Boss/Msg/Timer10Minutes.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_TIMER10MINUTES_HPP 2 | #define BOSS_MSG_TIMER10MINUTES_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::Timer10Minutes 7 | * 8 | * @brief emitted every 10 minutes. 9 | */ 10 | struct Timer10Minutes { }; 11 | 12 | }} 13 | 14 | #endif /* !defined(BOSS_MSG_TIMER10MINUTES_HPP) */ 15 | -------------------------------------------------------------------------------- /Boss/Msg/TimerRandomDaily.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_TIMERRANDOMDAILY_HPP 2 | #define BOSS_MSG_TIMERRANDOMDAILY_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::TimerRandomDaily 7 | * 8 | * @brief emitted approximately once a day, 9 | * but with mild randomness. 10 | */ 11 | struct TimerRandomDaily { }; 12 | 13 | }} 14 | 15 | #endif /* !defined(BOSS_MSG_TIMERRANDOMDAILY_HPP) */ 16 | -------------------------------------------------------------------------------- /Boss/Msg/TimerRandomHourly.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_TIMERRANDOMHOURLY_HPP 2 | #define BOSS_MSG_TIMERRANDOMHOURLY_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::TimerRandomHourly 7 | * 8 | * @brief emitted approximately once an 9 | * hour, but with some randomness. 10 | */ 11 | struct TimerRandomHourly { }; 12 | 13 | }} 14 | 15 | #endif /* !defined(BOSS_MSG_TIMERRANDOMHOURLY_HPP) */ 16 | -------------------------------------------------------------------------------- /Boss/Msg/TimerTwiceDaily.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_MSG_TIMERTWICEDAILY_HPP 2 | #define BOSS_MSG_TIMERTWICEDAILY_HPP 3 | 4 | namespace Boss { namespace Msg { 5 | 6 | /** struct Boss::Msg::TimerTwiceDaily 7 | * 8 | * @brief emitted about twice a day. 9 | * If more than half a day has gone since the 10 | * previous emission, emitted asynchronously 11 | * at `Init`. 12 | */ 13 | struct TimerTwiceDaily {}; 14 | 15 | }} 16 | 17 | #endif /* !defined(BOSS_MSG_TIMERTWICEDAILY_HPP) */ 18 | -------------------------------------------------------------------------------- /Boss/Shutdown.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_SHUTDOWN_HPP 2 | #define BOSS_SHUTDOWN_HPP 3 | 4 | namespace Boss { 5 | 6 | /** struct Boss::Shutdown 7 | * 8 | * @brief exception thrown by blocking Ev::Io 9 | * operations when the operator is being 10 | * destructed. 11 | */ 12 | struct Shutdown {}; 13 | 14 | } 15 | 16 | #endif /* !defined(BOSS_SHUTDOWN_HPP) */ 17 | -------------------------------------------------------------------------------- /Boss/concurrent.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/Shutdown.hpp" 2 | #include"Boss/concurrent.hpp" 3 | #include"Ev/Io.hpp" 4 | #include"Ev/concurrent.hpp" 5 | 6 | namespace Boss { 7 | 8 | Ev::Io concurrent(Ev::Io io) { 9 | return Ev::concurrent(std::move(io).catching([](Boss::Shutdown _) { 10 | return Ev::lift(); 11 | })); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Boss/concurrent.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_CONCURRENT_HPP 2 | #define BOSS_CONCURRENT_HPP 3 | 4 | namespace Ev { template class Io; } 5 | 6 | namespace Boss { 7 | 8 | /** Boss::concurrent. 9 | * 10 | * @brief Like Ev::concurrent except it ignores 11 | * Boss::Shutdown exceptions in the new greenthread. 12 | * 13 | * @desc Schedules a new greenthread for launching 14 | * later. 15 | * Boss::Shutdown exceptions in the new greenthread 16 | * are ignored. 17 | */ 18 | Ev::Io concurrent(Ev::Io); 19 | 20 | } 21 | 22 | #endif /* !defined(BOSS_CONCURRENT_HPP) */ 23 | -------------------------------------------------------------------------------- /Boss/log.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_LOG_HPP 2 | #define BOSS_LOG_HPP 3 | 4 | #ifdef HAVE_CONFIG_H 5 | # include"config.h" 6 | #endif 7 | 8 | namespace Ev { template class Io; } 9 | namespace S { class Bus; } 10 | 11 | namespace Boss { 12 | 13 | enum LogLevel { 14 | Debug, 15 | Info, 16 | Warn, 17 | Error 18 | }; 19 | 20 | Ev::Io log(S::Bus& bus, LogLevel l, const char *fmt, ...) 21 | #if HAVE_ATTRIBUTE_FORMAT 22 | __attribute__ ((format (printf, 3, 4))) 23 | #endif 24 | ; 25 | 26 | } 27 | 28 | #endif /* BOSS_LOG_HPP */ 29 | -------------------------------------------------------------------------------- /Boss/open_rpc_socket.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_OPEN_RPC_SOCKET_HPP 2 | #define BOSS_OPEN_RPC_SOCKET_HPP 3 | 4 | #include 5 | 6 | namespace Net { class Fd; } 7 | 8 | namespace Boss { 9 | 10 | /** Boss::open_rpc_socket() 11 | * 12 | * @brief changes to the given directory, and 13 | * attempts to open the given socket. 14 | * 15 | * @desc Function to change to the given directory 16 | * and open the given socket. 17 | * This is a separate function in order to let it 18 | * be replaced with a different function for 19 | * testing. 20 | */ 21 | Net::Fd open_rpc_socket( std::string const& lightning_dir = "." 22 | , std::string const& rpc_file = "lightning-rpc" 23 | ); 24 | 25 | } 26 | 27 | #endif /* !defined(BOSS_OPEN_RPC_SOCKET_HPP) */ 28 | -------------------------------------------------------------------------------- /Boss/random_engine.cpp: -------------------------------------------------------------------------------- 1 | #include"Boss/random_engine.hpp" 2 | #include"Net/Fd.hpp" 3 | #include"Util/BacktraceException.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace { 13 | 14 | std::default_random_engine initialize_random_engine() { 15 | auto seed = std::default_random_engine::result_type(0); 16 | 17 | auto dr = Net::Fd(); 18 | do { 19 | dr = Net::Fd(open("/dev/random", O_RDONLY)); 20 | } while (!dr && errno == EINTR); 21 | if (!dr) 22 | throw Util::BacktraceException( 23 | std::string("open /dev/random: ") + 24 | strerror(errno) 25 | ); 26 | 27 | if (read(dr.get(), &seed, sizeof(seed)) < 0) 28 | /*Nothing*/ ; 29 | 30 | return std::default_random_engine(seed); 31 | } 32 | 33 | } 34 | 35 | namespace Boss { 36 | 37 | std::default_random_engine random_engine = initialize_random_engine(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Boss/random_engine.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOSS_RANDOM_ENGINE_HPP 2 | #define BOSS_RANDOM_ENGINE_HPP 3 | 4 | #include 5 | 6 | namespace Boss { 7 | 8 | extern std::default_random_engine random_engine; 9 | 10 | } 11 | 12 | #endif /* !defined(BOSS_RANDOM_ENGINE_HPP) */ 13 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | CHANGELOG.md -------------------------------------------------------------------------------- /DnsSeed/Detail/decode_bech32_node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DNSSEED_DETAIL_DECODE_BECH32_NODE_HPP 2 | #define DNSSEED_DETAIL_DECODE_BECH32_NODE_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace DnsSeed { namespace Detail { 9 | 10 | /** DnsSeed::Detail::decode_bech32_node 11 | * 12 | * @brief decode a bech32-encoded node ID. 13 | * 14 | * @desc Decode a bech32-encoded node ID, returning 15 | * the raw Lightning node ID. 16 | * 17 | * WARNING this does not actually check the checksum. 18 | * Our assumption is that these pieces of text come from 19 | * DNS, not from a human that might make mistakes, and 20 | * that the DNS server is trusted to give the correct 21 | * public key anyway. 22 | * 23 | * Throws an std::runtime_error in case of a parse 24 | * error. 25 | */ 26 | std::vector decode_bech32_node(std::string const&); 27 | 28 | }} 29 | 30 | #endif /* !defined(DNSSEED_DETAIL_DECODE_BECH32_NODE_HPP) */ 31 | -------------------------------------------------------------------------------- /DnsSeed/Detail/parse_dig_srv.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DNSSEED_DETAIL_PARSE_DIG_SRV_HPP 2 | #define DNSSEED_DETAIL_PARSE_DIG_SRV_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace DnsSeed { namespace Detail { 9 | 10 | struct Record { 11 | std::string nodeid; 12 | std::uint16_t port; 13 | std::string hostname; 14 | }; 15 | 16 | /** DnsSeed::Detail::parse_dig_srv 17 | * 18 | * @brief parses the output of a `dig SRV` command, extracting 19 | * the node ID, port, and hostname of each entry returned. 20 | */ 21 | std::vector parse_dig_srv(std::string const&); 22 | 23 | }} 24 | 25 | #endif /* !defined(DNSSEED_DETAIL_PARSE_DIG_SRV_HPP) */ 26 | -------------------------------------------------------------------------------- /Ev/concurrent.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EV_CONCURRENT_HPP 2 | #define EV_CONCURRENT_HPP 3 | 4 | namespace Ev { template class Io; } 5 | 6 | namespace Ev { 7 | 8 | /** Ev::concurrent 9 | * 10 | * @brief causes the given IO action to be 11 | * invoked later when the current greenthread 12 | * yields. 13 | * Starts a new greenthread with that IO 14 | * action. 15 | */ 16 | Ev::Io concurrent(Ev::Io io); 17 | 18 | } 19 | 20 | #endif /* EV_CONCURRENT_HPP */ 21 | -------------------------------------------------------------------------------- /Ev/now.cpp: -------------------------------------------------------------------------------- 1 | #include"Ev/now.hpp" 2 | #include 3 | 4 | namespace Ev { 5 | 6 | double now() { 7 | return ev_now(EV_DEFAULT); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Ev/now.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EV_NOW_HPP 2 | #define EV_NOW_HPP 3 | 4 | namespace Ev { 5 | 6 | /** Ev::now 7 | * 8 | * @brief returns the current time, in seconds 9 | * from the epoch. 10 | */ 11 | double now(); 12 | 13 | } 14 | 15 | #endif /* !defined(EV_NOW_HPP) */ 16 | -------------------------------------------------------------------------------- /Ev/runcmd.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EV_RUNCMD_HPP 2 | #define EV_RUNCMD_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Ev { template class Io; } 8 | 9 | namespace Ev { 10 | 11 | /** Ev::runcmd 12 | * 13 | * @brief run the given command, and returns its 14 | * output as a string. 15 | * 16 | * @desc This action does not return until the 17 | * given command closes its stdout, which should 18 | * normally happen when it terminates. 19 | * All output is returned in the string. 20 | * Its input is redirected from `/dev/null`. 21 | * 22 | * stderr may be captured in the same pipe as 23 | * stdout, or may be preserved to be the same 24 | * as in the current process. 25 | */ 26 | Ev::Io runcmd( std::string command 27 | , std::vector argv 28 | , bool capture_stderr = false 29 | ); 30 | 31 | } 32 | 33 | #endif /* !defined(EV_RUNCMD_HPP) */ 34 | -------------------------------------------------------------------------------- /Ev/start.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EV_START_HPP 2 | #define EV_START_HPP 3 | 4 | namespace Ev { template class Io; } 5 | 6 | namespace Ev { 7 | 8 | int start(Ev::Io); 9 | 10 | } 11 | 12 | #endif /* EV_START_HPP */ 13 | -------------------------------------------------------------------------------- /Ev/yield.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EV_YIELD_HPP 2 | #define EV_YIELD_HPP 3 | 4 | #include 5 | 6 | namespace Ev { template class Io; } 7 | 8 | namespace Ev { 9 | 10 | /** Ev::yield 11 | * 12 | * @brief Does nothing, but allows other Ev::Io greenthreads 13 | * to continue processing. 14 | * 15 | * @desc A yield point, where other concurrent tasks may execute. 16 | * 17 | * Recommended to put at each loop. 18 | * 19 | * Because other concurrent tasks may execute while your task 20 | * goes through this function, you should be aware that variables 21 | * you are using may change. 22 | * This warning applies to all yield points, and other functions 23 | * should mention whether they are yield points and have this 24 | * property as well. 25 | * 26 | * @param num_yields - How many times to yield. 27 | * Usually omitted (meaning just yield once); this is generally 28 | * only used in testcases to allow modules to operate. 29 | */ 30 | Ev::Io yield(); 31 | 32 | Ev::Io yield(std::size_t num_yields); 33 | 34 | } 35 | 36 | #endif /* !defined(EV_YIELD_HPP) */ 37 | -------------------------------------------------------------------------------- /Graph/TreeNode.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GRAPH_TREENODE_HPP 2 | #define GRAPH_TREENODE_HPP 3 | 4 | #include 5 | 6 | namespace Graph { 7 | 8 | /** struct Graph::TreeNode 9 | * 10 | * @brief generic n-ary tree node, with 11 | * associated data on the nodes. 12 | */ 13 | template 14 | struct TreeNode { 15 | a data; 16 | TreeNode const* parent; 17 | std::vector children; 18 | }; 19 | 20 | } 21 | 22 | #endif /* !defined(GRAPH_TREENODE_HPP) */ 23 | -------------------------------------------------------------------------------- /Jsmn/Detail/Iterator.cpp: -------------------------------------------------------------------------------- 1 | #include"Jsmn/Detail/Iterator.hpp" 2 | #include"Jsmn/Detail/ParseResult.hpp" 3 | #include"Jsmn/Detail/Token.hpp" 4 | #include"Jsmn/Object.hpp" 5 | 6 | namespace Jsmn { namespace Detail { 7 | 8 | Iterator::Iterator() : r(), i(0) { } 9 | 10 | Iterator& Iterator::operator++() { 11 | Token const* tok = &r->tokens[i]; 12 | Token const* ntok = tok; 13 | Token::next(ntok); 14 | i += (ntok - tok); 15 | 16 | return *this; 17 | } 18 | Jsmn::Object Iterator::operator*() const { 19 | return Jsmn::Object(r, i); 20 | } 21 | 22 | }} 23 | -------------------------------------------------------------------------------- /Jsmn/Detail/ParseResult.hpp: -------------------------------------------------------------------------------- 1 | #ifndef JSMN_DETAIL_PARSERESULT_HPP 2 | #define JSMN_DETAIL_PARSERESULT_HPP 3 | 4 | #include 5 | #include 6 | #include"Jsmn/Detail/Token.hpp" 7 | 8 | namespace Jsmn { namespace Detail { 9 | 10 | struct ParseResult { 11 | std::string orig_string; 12 | std::vector tokens; 13 | }; 14 | 15 | }} 16 | 17 | #endif /* !defined(JSMN_DETAIL_PARSERESULT_HPP) */ 18 | -------------------------------------------------------------------------------- /Jsmn/Detail/Str.hpp: -------------------------------------------------------------------------------- 1 | #ifndef JSMN_DETAIL_STR_HPP 2 | #define JSMN_DETAIL_STR_HPP 3 | 4 | #include 5 | 6 | namespace Jsmn { namespace Detail { namespace Str { 7 | 8 | /* Process a "raw" string and insert escape codes. */ 9 | std::string to_escaped(std::string const&); 10 | /* Process an escaped string and return "raw" string. */ 11 | std::string from_escaped(std::string const&); 12 | 13 | /* Parse and serialize doubles, in a JSON-compatible way. */ 14 | double to_double(std::string const&); 15 | std::string from_double(double); 16 | 17 | }}} 18 | 19 | #endif /* !defined(JSMN_DETAIL_STR_HPP) */ 20 | -------------------------------------------------------------------------------- /Jsmn/Detail/Token.cpp: -------------------------------------------------------------------------------- 1 | #include"Jsmn/Detail/Token.hpp" 2 | 3 | namespace Jsmn { namespace Detail { 4 | 5 | void Token::next(Token const*& tokptr) { 6 | auto t = (Token const*) nullptr; 7 | auto i = (int) 0; 8 | for (t = tokptr + 1, i = 0; i < tokptr->size; ++i) 9 | next(t); 10 | tokptr = t; 11 | } 12 | 13 | }} 14 | -------------------------------------------------------------------------------- /Jsmn/Detail/Token.hpp: -------------------------------------------------------------------------------- 1 | #ifndef JSMN_DETAIL_TOKEN_HPP 2 | #define JSMN_DETAIL_TOKEN_HPP 3 | 4 | #include"Jsmn/Detail/Type.hpp" 5 | 6 | namespace Jsmn { namespace Detail { 7 | 8 | struct Token { 9 | Type type; 10 | int start; 11 | int end; 12 | int size; 13 | 14 | static void next(Token const*& tokptr); 15 | }; 16 | 17 | }} 18 | 19 | #endif /* !defined(JSMN_DETAIL_TOKEN_HPP) */ 20 | -------------------------------------------------------------------------------- /Jsmn/Detail/Type.hpp: -------------------------------------------------------------------------------- 1 | #ifndef JSMN_DETAIL_TYPE_HPP 2 | #define JSMN_DETAIL_TYPE_HPP 3 | 4 | namespace Jsmn { namespace Detail { 5 | 6 | enum Type { 7 | Undefined, Object, Array, String, Primitive 8 | }; 9 | 10 | }} 11 | 12 | #endif /* !defined(JSMN_DETAIL_TYPE_HPP) */ 13 | -------------------------------------------------------------------------------- /Jsmn/ParseError.cpp: -------------------------------------------------------------------------------- 1 | #include"Jsmn/ParseError.hpp" 2 | 3 | namespace Jsmn { 4 | 5 | std::string ParseError::enmessage(std::string const& input, unsigned int i) { 6 | /* FIXME: Show context around error. */ 7 | char cs[2]; 8 | cs[0] = input[i]; 9 | cs[1] = 0; 10 | return std::string("Parse error near character '") + cs 11 | + std::string("'") 12 | ; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Jsmn/ParseError.hpp: -------------------------------------------------------------------------------- 1 | #ifndef JSMN_PARSEERROR_HPP 2 | #define JSMN_PARSEERROR_HPP 3 | 4 | #include"Util/BacktraceException.hpp" 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Jsmn { 10 | 11 | /* Thrown on JSON parsing failure. */ 12 | class ParseError : public Util::BacktraceException { 13 | private: 14 | std::string input; 15 | unsigned int i; 16 | 17 | static 18 | std::string enmessage(std::string const& input, unsigned int i); 19 | 20 | public: 21 | ParseError() =delete; 22 | ParseError( std::string input_ 23 | , unsigned int i_ 24 | ) : Util::BacktraceException(enmessage(input_, i_)) 25 | , input(std::move(input_)) 26 | , i(i_) 27 | { 28 | input = std::move(input_); 29 | i = i_; 30 | } 31 | }; 32 | 33 | } 34 | 35 | #endif /* !defined(JSMN_PARSEERROR_HPP) */ 36 | -------------------------------------------------------------------------------- /Jsmn/jsonify_string.cpp: -------------------------------------------------------------------------------- 1 | #include"Jsmn/Detail/Str.hpp" 2 | #include"Jsmn/jsonify_string.hpp" 3 | 4 | namespace Jsmn { 5 | 6 | std::string jsonify_string(std::string const& s) { 7 | return "\"" + Detail::Str::to_escaped(s) + "\""; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Jsmn/jsonify_string.hpp: -------------------------------------------------------------------------------- 1 | #ifndef JSMN_JSONIFY_STRING_HPP 2 | #define JSMN_JSONIFY_STRING_HPP 3 | 4 | #include 5 | 6 | namespace Jsmn { 7 | 8 | /* Transform an ordinary C++ string to a string which, 9 | * when printed, is a valid JSON string. 10 | */ 11 | std::string jsonify_string(std::string const& s); 12 | 13 | } 14 | 15 | #endif /* !defined(JSMN_JSONIFY_STRING_HPP) */ 16 | -------------------------------------------------------------------------------- /Ln/CommandId.cpp: -------------------------------------------------------------------------------- 1 | #include"Jsmn/Object.hpp" 2 | #include"Ln/CommandId.hpp" 3 | #include"Util/make_unique.hpp" 4 | #include 5 | 6 | namespace { 7 | 8 | std::uint64_t string_to_u64(std::string const& s) { 9 | auto is = std::istringstream(s); 10 | auto num = std::uint64_t(); 11 | is >> num; 12 | return num; 13 | } 14 | 15 | } 16 | 17 | namespace Ln { 18 | 19 | std::unique_ptr 20 | command_id_from_jsmn_object(Jsmn::Object const& j) { 21 | if (j.is_number()) { 22 | auto s_id = j.direct_text(); 23 | return Util::make_unique( 24 | CommandId::left(string_to_u64(s_id)) 25 | ); 26 | } else if (j.is_string()) { 27 | return Util::make_unique( 28 | CommandId::right(std::string(j)) 29 | ); 30 | } 31 | return nullptr; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Ln/CommandId.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LN_COMMANDID_HPP 2 | #define LN_COMMANDID_HPP 3 | 4 | #include"Util/Either.hpp" 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Jsmn { class Object; } 10 | 11 | namespace Ln { 12 | 13 | typedef Util::Either CommandId; 14 | 15 | std::unique_ptr 16 | command_id_from_jsmn_object(Jsmn::Object const&); 17 | 18 | } 19 | 20 | #endif /* !defined(LN_COMMANDID_HPP) */ 21 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZmnSCPxj/clboss/5fea90e3a74c05fc98cba3391894fa82855c5556/NEWS -------------------------------------------------------------------------------- /Net/Connector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NET_CONNECTOR_HPP 2 | #define NET_CONNECTOR_HPP 3 | 4 | #include 5 | 6 | namespace Net { class SocketFd; } 7 | 8 | namespace Net { 9 | 10 | /* Interface to an entity that is capable of connecting 11 | * to a host:port. 12 | * This is an abstract interface since we might want to 13 | * use a proxy of some kind. 14 | */ 15 | class Connector { 16 | public: 17 | virtual ~Connector() { } 18 | 19 | /* Returns null if failed to connect. */ 20 | virtual 21 | Net::SocketFd 22 | connect(std::string const& host, int port) =0; 23 | }; 24 | 25 | } 26 | 27 | #endif /* NET_CONNECTOR_HPP */ 28 | -------------------------------------------------------------------------------- /Net/Detail/AddrInfoReleaser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"Net/Detail/AddrInfoReleaser.hpp" 3 | 4 | namespace Net { namespace Detail { 5 | 6 | AddrInfoReleaser::~AddrInfoReleaser() { 7 | if (addrs) 8 | freeaddrinfo(addrs); 9 | } 10 | 11 | }} 12 | -------------------------------------------------------------------------------- /Net/Detail/AddrInfoReleaser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NET_DETAIL_ADDRINFORELEASER_HPP 2 | #define NET_DETAIL_ADDRINFORELEASER_HPP 3 | 4 | extern "C" { struct addrinfo; } 5 | 6 | namespace Net { namespace Detail { 7 | 8 | /* RAII class to release addrinfo structures. */ 9 | class AddrInfoReleaser { 10 | private: 11 | addrinfo* addrs; 12 | 13 | public: 14 | AddrInfoReleaser() : addrs(nullptr) { } 15 | AddrInfoReleaser(AddrInfoReleaser const&) =delete; 16 | AddrInfoReleaser(AddrInfoReleaser&& o) { 17 | addrs = o.addrs; 18 | o.addrs = nullptr; 19 | } 20 | ~AddrInfoReleaser(); 21 | addrinfo*& get() { return addrs; } 22 | }; 23 | 24 | }} 25 | 26 | #endif /* NET_DETAIL_ADDRINFORELEASER_HPP */ 27 | -------------------------------------------------------------------------------- /Net/DirectConnector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NET_DIRECTCONNECTOR_HPP 2 | #define NET_DIRECTCONNECTOR_HPP 3 | 4 | #include"Net/Connector.hpp" 5 | 6 | namespace Net { 7 | 8 | /* A Connector that just connects directly to 9 | * the specified host:port. 10 | */ 11 | class DirectConnector : public Connector { 12 | public: 13 | Net::SocketFd 14 | connect(std::string const& host, int port) override; 15 | }; 16 | 17 | } 18 | 19 | #endif /* NET_DIRECTCONNECTOR_HPP */ 20 | -------------------------------------------------------------------------------- /Net/Fd.cpp: -------------------------------------------------------------------------------- 1 | #include"Net/Fd.hpp" 2 | #include 3 | #include 4 | 5 | namespace Net { 6 | 7 | Fd::~Fd() { 8 | if (fd >= 0) { 9 | /* Ignore errors. */ 10 | auto err = errno; 11 | close(fd); 12 | errno = err; 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Net/IPBinnerBySubnet.cpp: -------------------------------------------------------------------------------- 1 | #include"Net/IPAddr.hpp" 2 | #include"Net/IPBinnerBySubnet.hpp" 3 | 4 | namespace { 5 | 6 | /* How many bytes to get for IPv4 and IPv6. */ 7 | auto prefix_length_4 = std::size_t(2); 8 | auto prefix_length_6 = std::size_t(3); 9 | 10 | } 11 | 12 | namespace Net { 13 | 14 | IPBin IPBinnerBySubnet::get_bin_of(Net::IPAddr const& ip) const { 15 | auto& data = ip.raw_data(); 16 | auto prefix_length = ip.is_ipv4() ? prefix_length_4 : prefix_length_6; 17 | 18 | auto rv = std::uint64_t(0); 19 | for (auto i = std::size_t(0); i < prefix_length; ++i) { 20 | rv = rv << 8; 21 | if (i < data.size()) 22 | rv += std::uint64_t(data[i]); 23 | } 24 | 25 | return rv; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Net/IPBinnerBySubnet.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NET_IPBINNERBYSUBNET_HPP 2 | #define NET_IPBINNERBYSUBNET_HPP 3 | 4 | #include"Net/IPBinnerIF.hpp" 5 | 6 | namespace Net { 7 | 8 | /** class Net::IPBinnerBySubnet 9 | * 10 | * @brief an IP binner that bins by the first few 11 | * bytes of an IP address. 12 | */ 13 | class IPBinnerBySubnet : public IPBinnerIF { 14 | public: 15 | IPBinnerBySubnet() =default; 16 | ~IPBinnerBySubnet() =default; 17 | 18 | IPBinnerBySubnet(IPBinnerBySubnet const&) =default; 19 | IPBinnerBySubnet(IPBinnerBySubnet&&) =default; 20 | 21 | IPBin get_bin_of(Net::IPAddr const&) const override; 22 | }; 23 | 24 | } 25 | 26 | #endif /* !defined(NET_IPBINNERBYSUBNET_HPP) */ 27 | -------------------------------------------------------------------------------- /Net/IPBinnerIF.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NET_IPBINNERIF_HPP 2 | #define NET_IPBINNERIF_HPP 3 | 4 | #include 5 | 6 | namespace Net { class IPAddr; } 7 | 8 | namespace Net { 9 | 10 | typedef std::uint64_t IPBin; 11 | 12 | /** class Net::IPBinnerIF 13 | * 14 | * @brief Abstract interface to an object that classifies IP addresses 15 | * to bins. 16 | */ 17 | class IPBinnerIF { 18 | public: 19 | virtual ~IPBinnerIF() { } 20 | 21 | /* Get bin of the given IP address. */ 22 | virtual 23 | IPBin get_bin_of(Net::IPAddr const&) const =0; 24 | }; 25 | 26 | } 27 | 28 | #endif /* !defined(NET_IPBINNERIF_HPP) */ 29 | -------------------------------------------------------------------------------- /Net/ProxyConnector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NET_PROXYCONNECTOR_HPP 2 | #define NET_PROXYCONNECTOR_HPP 3 | 4 | #include 5 | #include 6 | #include"Net/Connector.hpp" 7 | 8 | namespace Net { 9 | 10 | class ProxyConnector : public Connector { 11 | private: 12 | std::unique_ptr base; 13 | std::string proxy_host; 14 | int proxy_port; 15 | 16 | public: 17 | ProxyConnector() =delete; 18 | explicit ProxyConnector( std::unique_ptr base_ 19 | , std::string proxy_host_ 20 | , int proxy_port_ 21 | ) : base(std::move(base_)) 22 | , proxy_host(std::move(proxy_host_)) 23 | , proxy_port(proxy_port_) 24 | { } 25 | 26 | Net::SocketFd 27 | connect(std::string const& host, int port) override; 28 | }; 29 | 30 | } 31 | 32 | #endif /* NET_PROXYCONNECTOR_HPP */ 33 | -------------------------------------------------------------------------------- /Net/get_bin_of_onion.cpp: -------------------------------------------------------------------------------- 1 | #include"Net/get_bin_of_onion.hpp" 2 | #include"Sha256/Hash.hpp" 3 | #include"Sha256/fun.hpp" 4 | 5 | namespace Net { 6 | 7 | IPBin get_bin_of_onion( std::function tweak_hash 8 | , std::string const& onion 9 | ) { 10 | auto hash = Sha256::fun(&onion[0], onion.size()); 11 | std::uint8_t buff[32]; 12 | hash.to_buffer(buff); 13 | if (tweak_hash) 14 | tweak_hash(buff); 15 | return 0xFFFFFFFFFFFFFFFC + (buff[0] & 0x03); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Net/get_bin_of_onion.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NET_GET_BIN_OF_ONION_HPP 2 | #define NET_GET_BIN_OF_ONION_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Net { 9 | 10 | typedef std::uint64_t IPBin; 11 | 12 | /** Net::get_bin_of_onion 13 | * 14 | * @brief common code to invent a bin for onion addresses. 15 | */ 16 | IPBin get_bin_of_onion( std::function tweak_hash 17 | , std::string const& onion 18 | ); 19 | 20 | } 21 | 22 | #endif /* !defined(NET_GET_BIN_OF_ONION_HPP) */ 23 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /Ripemd160/Hasher.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RIPEMD160_HASHER_HPP 2 | #define RIPEMD160_HASHER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Ripemd160 { class Hash; } 8 | 9 | namespace Ripemd160 { 10 | 11 | /** class Ripemd160::Hasher 12 | * 13 | * @brief object that lets you stream bytes 14 | * into it, then generate the hash of all 15 | * the bytes streamed in. 16 | */ 17 | class Hasher { 18 | private: 19 | class Impl; 20 | std::unique_ptr pimpl; 21 | 22 | public: 23 | Hasher(); 24 | Hasher(Hasher&&); 25 | ~Hasher(); 26 | /* Duplicates midstate! */ 27 | Hasher(Hasher const&); 28 | 29 | Hasher& operator=(Hasher&&); 30 | Hasher& operator=(Hasher const&); 31 | 32 | explicit 33 | operator bool() const; 34 | bool operator!() const { 35 | return !bool(*this); 36 | } 37 | 38 | void feed(void const* p, std::size_t size); 39 | 40 | Ripemd160::Hash finalize()&&; 41 | Ripemd160::Hash get() const; 42 | }; 43 | 44 | } 45 | 46 | #endif /* !defined(RIPEMD160_HASHER_HPP) */ 47 | -------------------------------------------------------------------------------- /S/Bus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace S { 7 | 8 | class Bus::Impl { 9 | private: 10 | std::unordered_map< std::type_index 11 | , std::unique_ptr 12 | > signals; 13 | 14 | public: 15 | S::Detail::SignalBase& 16 | get_signal( std::type_index type 17 | , std::function< std::unique_ptr() 18 | > make 19 | ) { 20 | auto it = signals.find(type); 21 | if (it == signals.end()) { 22 | auto ins = signals.emplace(type, make()); 23 | it = ins.first; 24 | } 25 | return *it->second; 26 | } 27 | }; 28 | 29 | Bus::~Bus() { } 30 | Bus::Bus() : pimpl(Util::make_unique()) { } 31 | Bus::Bus(Bus&& o) : pimpl(std::move(o.pimpl)) { } 32 | 33 | S::Detail::SignalBase& 34 | Bus::get_signal( std::type_index type 35 | , std::function< std::unique_ptr() 36 | > make 37 | ) { 38 | assert(pimpl); 39 | return pimpl->get_signal(type, std::move(make)); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /S/Detail/SignalBase.hpp: -------------------------------------------------------------------------------- 1 | #ifndef S_DETAIL_SIGNALBASE_HPP 2 | #define S_DETAIL_SIGNALBASE_HPP 3 | 4 | namespace S { namespace Detail { 5 | 6 | /* Common base class for all S::Detail::Signal<>. */ 7 | struct SignalBase { 8 | virtual ~SignalBase() { } 9 | }; 10 | 11 | }} 12 | 13 | #endif /* !defined(S_DETAIL_SIGNALBASE_HPP) */ 14 | -------------------------------------------------------------------------------- /Secp256k1/Detail/context.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include"Secp256k1/Detail/context.hpp" 5 | #include"Util/BacktraceException.hpp" 6 | 7 | namespace { 8 | 9 | /* Called due to illegal inputs to the library. */ 10 | void illegal_callback(const char* msg, void*) { 11 | throw Util::BacktraceException(std::string("SECP256K1: ") + msg); 12 | } 13 | 14 | std::shared_ptr create_secp256k1_context() { 15 | auto ctx = secp256k1_context_create( SECP256K1_CONTEXT_SIGN 16 | | SECP256K1_CONTEXT_VERIFY 17 | ); 18 | auto ret = std::shared_ptr( ctx 19 | , &secp256k1_context_destroy 20 | ); 21 | secp256k1_context_set_illegal_callback( ret.get() 22 | , &illegal_callback 23 | , nullptr 24 | ); 25 | return ret; 26 | } 27 | 28 | } 29 | 30 | namespace Secp256k1 { 31 | namespace Detail { 32 | std::shared_ptr const context 33 | = create_secp256k1_context(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Secp256k1/Detail/context.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_DETAIL_CONTEXT_HPP 2 | #define SECP256K1_DETAIL_CONTEXT_HPP 3 | 4 | #include 5 | 6 | extern "C" { 7 | struct secp256k1_context_struct; 8 | } 9 | 10 | namespace Secp256k1 { 11 | namespace Detail { 12 | 13 | /* A shared pointer is mildly overweight for this purpose, 14 | * but the struct definition is hidden inside libsecp256k1 15 | * (so cannot instantiate directly), a plain pointer will 16 | * not have a destructor, a unique_ptr would need to expose 17 | * the deletor type here as well. 18 | * A shared pointer has the nice property of also hiding 19 | * the deletor type (it is hidden in the management object 20 | * maintained by shared pointers). 21 | */ 22 | extern std::shared_ptr const context; 23 | 24 | } 25 | } 26 | 27 | #endif /* SECP256K1_DETAIL_CONTEXT_HPP */ 28 | -------------------------------------------------------------------------------- /Secp256k1/G.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_G_HPP 2 | #define SECP256K1_G_HPP 3 | 4 | namespace Secp256k1 { class PubKey; } 5 | namespace Secp256k1 { extern PubKey G; } 6 | 7 | #endif /* SECP256K1_G_HPP */ 8 | -------------------------------------------------------------------------------- /Secp256k1/Random.cpp: -------------------------------------------------------------------------------- 1 | #include"Secp256k1/Random.hpp" 2 | #include"Util/make_unique.hpp" 3 | #include 4 | 5 | namespace Secp256k1 { 6 | 7 | class Random::Impl { 8 | private: 9 | unsigned int num; 10 | std::uint8_t buffer[64]; 11 | 12 | public: 13 | Impl() : num(64) { } 14 | std::uint8_t get() { 15 | if (num >= 64) { 16 | BASICSECURE_RAND(buffer, 64); 17 | num = 0; 18 | } 19 | return buffer[num++]; 20 | } 21 | }; 22 | 23 | Random::Random() : pimpl(Util::make_unique()) { } 24 | Random::~Random() { } 25 | 26 | std::uint8_t Random::get() { 27 | return pimpl->get(); 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Secp256k1/Random.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_RANDOM_HPP 2 | #define SECP256K1_RANDOM_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Secp256k1 { 8 | 9 | /* A source of random data. */ 10 | class Random { 11 | private: 12 | class Impl; 13 | 14 | std::unique_ptr pimpl; 15 | 16 | public: 17 | Random(); 18 | Random(Random&&) =delete; 19 | Random(Random const&) =delete; 20 | ~Random(); 21 | 22 | std::uint8_t get(); 23 | }; 24 | 25 | } 26 | 27 | #endif /* SECP256K1_RANDOM_HPP */ 28 | -------------------------------------------------------------------------------- /Sha256/fun.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHA256_FUN_HPP 2 | #define SHA256_FUN_HPP 3 | 4 | #include"Sha256/Hash.hpp" 5 | #include"Sha256/Hasher.hpp" 6 | 7 | namespace Sha256 { 8 | 9 | inline 10 | Sha256::Hash fun(void const* p, std::size_t len) { 11 | auto hasher = Sha256::Hasher(); 12 | hasher.feed(p, len); 13 | return std::move(hasher).finalize(); 14 | } 15 | /* Convenience version for double-sha256. */ 16 | inline 17 | Sha256::Hash fun(Sha256::Hash h) { 18 | std::uint8_t buf[32]; 19 | h.to_buffer(buf); 20 | auto hasher = Sha256::Hasher(); 21 | hasher.feed(buf, sizeof(buf)); 22 | return std::move(hasher).finalize(); 23 | } 24 | 25 | } 26 | 27 | #endif /* !defined(SHA256_FUN_HPP) */ 28 | -------------------------------------------------------------------------------- /Sqlite3.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SQLITE3_HPP 2 | #define SQLITE3_HPP 3 | 4 | #include"Sqlite3/Db.hpp" 5 | #include"Sqlite3/Query.hpp" 6 | #include"Sqlite3/Result.hpp" 7 | #include"Sqlite3/Tx.hpp" 8 | 9 | #endif /* !defined(SQLITE3_HPP) */ 10 | -------------------------------------------------------------------------------- /Sqlite3/Detail/columns.cpp: -------------------------------------------------------------------------------- 1 | #include"Sqlite3/Detail/columns.hpp" 2 | #include 3 | #include 4 | 5 | namespace Sqlite3 { namespace Detail { 6 | 7 | double column_d(void* stmt, int c) { 8 | return sqlite3_column_double((sqlite3_stmt*) stmt, c); 9 | } 10 | std::int64_t column_i(void* stmt, int c) { 11 | return sqlite3_column_int64((sqlite3_stmt*) stmt, c); 12 | } 13 | std::string column_s(void* vstmt, int c) { 14 | auto stmt = (sqlite3_stmt*) vstmt; 15 | auto len = sqlite3_column_bytes(stmt, c); 16 | auto dat = sqlite3_column_text(stmt, c); 17 | 18 | auto s = std::string(); 19 | s.resize(len); 20 | std::copy(dat, dat + len, s.begin()); 21 | 22 | return s; 23 | } 24 | 25 | }} 26 | -------------------------------------------------------------------------------- /Sqlite3/Result.cpp: -------------------------------------------------------------------------------- 1 | #include"Util/BacktraceException.hpp" 2 | #include"Sqlite3/Db.hpp" 3 | #include"Sqlite3/Result.hpp" 4 | #include 5 | 6 | namespace Sqlite3 { 7 | 8 | Result::Result(Sqlite3::Db const& db_, void* stmt_ 9 | ) : db(db_), stmt(stmt_) { 10 | advance(); 11 | } 12 | Result::Result(Result&& o) { 13 | db = std::move(o.db); 14 | stmt = o.stmt; 15 | o.stmt = nullptr; 16 | } 17 | Result::~Result() { 18 | if (stmt) 19 | sqlite3_finalize((sqlite3_stmt*) stmt); 20 | } 21 | 22 | bool Result::advance() { 23 | auto ss = (sqlite3_stmt*) stmt; 24 | auto res = sqlite3_step(ss); 25 | if (res == SQLITE_DONE) { 26 | sqlite3_finalize((sqlite3_stmt*) stmt); 27 | stmt = nullptr; 28 | return false; 29 | } else if (res == SQLITE_ROW) 30 | return true; 31 | else { 32 | auto connection = (sqlite3*) db.get_connection(); 33 | auto err = std::string(sqlite3_errmsg(connection)); 34 | throw Util::BacktraceException( 35 | std::string("Sqlite3::Result: ") + err 36 | ); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Stats/RunningMean.cpp: -------------------------------------------------------------------------------- 1 | #include"Stats/RunningMean.hpp" 2 | #include"Util/Str.hpp" 3 | #include 4 | 5 | namespace { 6 | 7 | union UD { 8 | std::uint64_t u; 9 | double d; 10 | }; 11 | 12 | } 13 | 14 | namespace Stats { 15 | 16 | std::ostream& operator<<(std::ostream& os, RunningMean& m) { 17 | union UD dat; 18 | dat.d = m.mean; 19 | 20 | os << std::hex << dat.u << " " << m.samples << " "; 21 | 22 | return os; 23 | } 24 | 25 | std::istream& operator>>(std::istream& is, RunningMean& m) { 26 | union UD dat; 27 | 28 | is >> std::hex >> dat.u >> m.samples; 29 | m.mean = dat.d; 30 | 31 | return is; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Util/Compiler.hpp: -------------------------------------------------------------------------------- 1 | #ifndef COMPILER_H_ 2 | #define COMPILER_H_ 3 | 4 | #if defined(__GNUC__) && (__GNUC__ >= 13) 5 | // We need a GCC patch here due the following bug 6 | // 7 | #include 8 | #endif 9 | 10 | #endif // COMPILER_H_ 11 | -------------------------------------------------------------------------------- /Util/Rw.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CLDCB_COMMON_UTIL_RW_HPP 2 | #define CLDCB_COMMON_UTIL_RW_HPP 3 | 4 | #include 5 | 6 | namespace Util { namespace Rw { 7 | 8 | /* Return true if successful, false if not. */ 9 | bool write_all(int fd, void const* p, std::size_t size); 10 | 11 | /* Return true if successful, false if not. 12 | * size is modified depending on actual number of 13 | * bytes read. 14 | * It is possible to fail with some number of 15 | * bytes already read. 16 | */ 17 | bool read_all(int fd, void* p, std::size_t& size); 18 | 19 | 20 | }} 21 | 22 | #endif /* CLDCB_COMMON_UTIL_RW_HPP */ 23 | -------------------------------------------------------------------------------- /Util/date.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_DATE_HPP 2 | #define UTIL_DATE_HPP 3 | 4 | #include 5 | 6 | namespace Util { 7 | 8 | /** Util::date 9 | * 10 | * @brief Returns a simple date representation 11 | * of the given Unix Epoch time. 12 | * 13 | * @desc This function may only be called from the main thread 14 | * of the program. 15 | * If used with `Ev`, do not call this function from a function 16 | * you pass to `Ev::ThreadPool`. 17 | */ 18 | std::string date(double epoch); 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Util/duration.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_DURATION_HPP 2 | #define UTIL_DURATION_HPP 3 | 4 | #include 5 | 6 | namespace Util { 7 | 8 | /** Util::duration 9 | * 10 | * @brief Provides a human-readable description of a 11 | * duration given in seconds. 12 | */ 13 | std::string duration(double duration); 14 | 15 | } 16 | 17 | #endif /* !defined (UTIL_DURATION_HPP) */ 18 | -------------------------------------------------------------------------------- /Util/format.cpp: -------------------------------------------------------------------------------- 1 | #include"Util/format.hpp" 2 | #include"Util/make_unique.hpp" 3 | #include 4 | #include 5 | 6 | namespace Util { 7 | 8 | std::string vformat(char const* fmt, va_list ap_orig) { 9 | va_list ap; 10 | 11 | auto written = size_t(0); 12 | auto size = size_t(42); 13 | auto buf = std::unique_ptr(); 14 | do { 15 | if (size <= written) 16 | size = written + 1; 17 | buf = Util::make_unique(size); 18 | va_copy(ap, ap_orig); 19 | written = size_t(vsnprintf(buf.get(), size, fmt, ap)); 20 | va_end(ap); 21 | } while (size <= written); 22 | 23 | return std::string(buf.get()); 24 | } 25 | std::string format(char const* fmt, ...) { 26 | va_list ap; 27 | va_start(ap, fmt); 28 | auto rv = vformat(fmt, ap); 29 | va_end(ap); 30 | return rv; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Util/format.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_FORMAT_HPP 2 | #define UTIL_FORMAT_HPP 3 | 4 | #ifdef HAVE_CONFIG_H 5 | # include"config.h" 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | namespace Util { 12 | 13 | /** Util::format 14 | * 15 | * @brief Like `sprintf`, but returns `std::string`. 16 | */ 17 | std::string format(char const* fmt, ...) 18 | #if HAVE_ATTRIBUTE_FORMAT 19 | __attribute__ ((format (printf, 1, 2))) 20 | #endif 21 | ; 22 | /** Util::vformat 23 | * 24 | * @brief Like `Util::format`, but accepts `va_list`. 25 | */ 26 | std::string vformat(char const* fmt, va_list ap); 27 | 28 | } 29 | 30 | #endif /* UTIL_FORMAT_HPP */ 31 | -------------------------------------------------------------------------------- /Util/stream_elements.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_STREAM_ELEMENTS_HPP 2 | #define UTIL_STREAM_ELEMENTS_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Util { 8 | 9 | template 10 | std::ostream& stream_elements(std::ostream& os, Container const& v) { 11 | os << "["; 12 | auto it = std::begin(v); 13 | auto end = std::end(v); 14 | if (it != end) { 15 | os << *it; 16 | ++it; 17 | } 18 | for (; it != end; ++it) { 19 | os << ", " << *it; 20 | } 21 | os << "]"; 22 | return os; 23 | } 24 | 25 | } 26 | 27 | #endif /* !defined(UTIL_STREAM_ELEMENTS_HPP) */ 28 | -------------------------------------------------------------------------------- /Util/stringify.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_STRINGIFY_HPP 2 | #define UTIL_STRINGIFY_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace Util { 8 | 9 | template 10 | std::string stringify(a const& v) { 11 | auto os = std::ostringstream(); 12 | os << v; 13 | return os. str(); 14 | } 15 | 16 | } 17 | 18 | #endif /* !defined(UTIL_STRINGIFY_HPP) */ 19 | -------------------------------------------------------------------------------- /contrib-shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import (builtins.fetchTarball { 2 | url = "https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz"; 3 | }) {} }: 4 | 5 | let 6 | poetry2nix = import (builtins.fetchGit { 7 | url = "https://github.com/nix-community/poetry2nix"; 8 | }) { inherit pkgs; }; 9 | in 10 | 11 | pkgs.mkShell { 12 | buildInputs = [ 13 | pkgs.poetry 14 | (poetry2nix.mkPoetryEnv { 15 | projectDir = ./contrib; 16 | }) 17 | ]; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /contrib/clboss/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZmnSCPxj/clboss/5fea90e3a74c05fc98cba3391894fa82855c5556/contrib/clboss/__init__.py -------------------------------------------------------------------------------- /contrib/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "contrib" 3 | version = "0.1.0" 4 | description = "A project to help manage CLBOSS contrib python dependencies" 5 | authors = ["Ken Sedgwick "] 6 | readme = "README.md" 7 | 8 | [tool.poetry.dependencies] 9 | python = "^3.9" 10 | tabulate = "^0.9.0" 11 | wcwidth = "^0.2.13" 12 | 13 | 14 | [build-system] 15 | requires = ["poetry-core"] 16 | build-backend = "poetry.core.masonry.api" 17 | -------------------------------------------------------------------------------- /create-tarball.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | PACKAGE_VERSION="@PACKAGE_VERSION@" 4 | 5 | if test $# '==' 0 || test 'x'"$1" '==' x--help; then 6 | echo Usage: $0 name [id] 7 | exit 0 8 | fi 9 | NAME="$1" 10 | ID="${2:+-}${2}" 11 | 12 | make distdir 13 | mv clboss-$PACKAGE_VERSION clboss-"$NAME$ID" 14 | tar czf clboss-$NAME$ID.tar.gz clboss-"$NAME$ID" 15 | rm -rf clboss-"$NAME$ID" 16 | echo clboss-"$NAME$ID".tar.gz 17 | -------------------------------------------------------------------------------- /docs/earnings_tracker.md: -------------------------------------------------------------------------------- 1 | # CLBOSS Earnings Tracker 2 | 3 | ```mermaid 4 | %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% 5 | 6 | flowchart TB 7 | 8 | style EarningsTracker fill:#9fb,stroke:#333,stroke-width:4px 9 | Initiator-->|DbResource|EarningsTracker 10 | ForwardFeeMonitor-->|ForwardFee|EarningsTracker 11 | EarningsRebalancer-->|RequestMoveFunds|EarningsTracker 12 | FundsMover_Runner-->|ResponseMoveFunds|EarningsTracker 13 | EarningsRebalancer-->|RequestEarningsInfo|EarningsTracker 14 | InitialRebalancer-->|RequestEarningsInfo|EarningsTracker 15 | JitRebalancer-->|RequestEarningsInfo|EarningsTracker 16 | StatusCommand-->|SolicitStatus|EarningsTracker 17 | EarningsTracker-->|ResponseEarningsInfo|EarningsRebalancer 18 | EarningsTracker-->|ResponseEarningsInfo|InitialRebalancer 19 | EarningsTracker-->|ResponseEarningsInfo|JitRebalancer 20 | EarningsTracker-->|ProvideStatus|StatusCommand 21 | ``` 22 | -------------------------------------------------------------------------------- /external/basicsecure/.gitignore: -------------------------------------------------------------------------------- 1 | basicsecure_config.h 2 | basicsecure_config.h.in 3 | -------------------------------------------------------------------------------- /external/basicsecure/COPYING: -------------------------------------------------------------------------------- 1 | This library was created by ZmnSCPxj and is placed in the public domain. 2 | -------------------------------------------------------------------------------- /external/basicsecure/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libbasicsecure.la 2 | 3 | libbasicsecure_la_SOURCES = \ 4 | basicsecure.c \ 5 | basicsecure.h 6 | 7 | ACLOCAL_AMFLAGS = -I m4 8 | 9 | LDADD = libbasicsecure.la 10 | TESTS = test_general \ 11 | test_clear 12 | check_PROGRAMS = $(TESTS) 13 | -------------------------------------------------------------------------------- /external/basicsecure/test_general.c: -------------------------------------------------------------------------------- 1 | /* This library was written by ZmnSCPxj and is placed in the public domain. */ 2 | #undef NDEBUG 3 | #include"basicsecure.h" 4 | #include 5 | #include 6 | 7 | /* VERY basic tests of functionality. */ 8 | int main() { 9 | int a[999]; 10 | int b[999]; 11 | 12 | BASICSECURE_RAND(a, sizeof(a)); 13 | BASICSECURE_RAND(b, sizeof(b)); 14 | /* Highly unlikely. */ 15 | assert(!basicsecure_eq(a, b, sizeof(a))); 16 | 17 | memcpy(a, b, sizeof(a)); 18 | assert(basicsecure_eq(a, b, sizeof(a))); 19 | 20 | basicsecure_clear(a, sizeof(a)); 21 | assert(!basicsecure_eq(a, b, sizeof(a))); 22 | /* Smoke tests. */ 23 | assert(a[0] == 0); 24 | assert(a[998] == 0); 25 | 26 | basicsecure_clear(b, sizeof(b)); 27 | assert(basicsecure_eq(a, b, sizeof(a))); 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /external/bitcoin-ripemd160/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libbitcoin-ripemd160.la 2 | libbitcoin_ripemd160_la_SOURCES = \ 3 | crypto/common.h \ 4 | crypto/ripemd160.cpp \ 5 | crypto/ripemd160.h 6 | AM_CPPFLAGS = -I $(top_srcdir) 7 | -------------------------------------------------------------------------------- /external/bitcoin-ripemd160/README.md: -------------------------------------------------------------------------------- 1 | This is the RIPEMD160 implementation copied from the 2 | obscure project https://github.com/bitcoin/bitcoin . 3 | 4 | Specifically, the files `crypto/ripemd160.cpp` and 5 | `crypto/ripemd160.h` are copied verbatim, while the 6 | file `crypto/common.h` is a minimal shim to get the 7 | RIPEMD160 implementation working. 8 | -------------------------------------------------------------------------------- /external/bitcoin-ripemd160/crypto/common.h: -------------------------------------------------------------------------------- 1 | /* This code was replaced by ZmnSCPxj for the CLBOSS project. */ 2 | #include 3 | 4 | #include"Util/Str.hpp" 5 | #include 6 | 7 | namespace { 8 | 9 | void WriteLE64(unsigned char* ptr, uint64_t x) { 10 | *(ptr++) = uint8_t((x >> 0) & 0xFF); 11 | *(ptr++) = uint8_t((x >> 8) & 0xFF); 12 | *(ptr++) = uint8_t((x >> 16) & 0xFF); 13 | *(ptr++) = uint8_t((x >> 24) & 0xFF); 14 | *(ptr++) = uint8_t((x >> 32) & 0xFF); 15 | *(ptr++) = uint8_t((x >> 40) & 0xFF); 16 | *(ptr++) = uint8_t((x >> 48) & 0xFF); 17 | *(ptr++) = uint8_t((x >> 56) & 0xFF); 18 | } 19 | void WriteLE32(unsigned char* ptr, uint32_t x) { 20 | *(ptr++) = uint8_t((x >> 0) & 0xFF); 21 | *(ptr++) = uint8_t((x >> 8) & 0xFF); 22 | *(ptr++) = uint8_t((x >> 16) & 0xFF); 23 | *(ptr++) = uint8_t((x >> 24) & 0xFF); 24 | } 25 | uint32_t ReadLE32(unsigned char const* ptr) { 26 | return (uint32_t(ptr[0]) << 0) 27 | | (uint32_t(ptr[1]) << 8) 28 | | (uint32_t(ptr[2]) << 16) 29 | | (uint32_t(ptr[3]) << 24) 30 | ; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /external/bitcoin-ripemd160/crypto/ripemd160.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2016 The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef BITCOIN_CRYPTO_RIPEMD160_H 6 | #define BITCOIN_CRYPTO_RIPEMD160_H 7 | 8 | #include 9 | #include 10 | 11 | /** A hasher class for RIPEMD-160. */ 12 | class CRIPEMD160 13 | { 14 | private: 15 | uint32_t s[5]; 16 | unsigned char buf[64]; 17 | uint64_t bytes; 18 | 19 | public: 20 | static const size_t OUTPUT_SIZE = 20; 21 | 22 | CRIPEMD160(); 23 | CRIPEMD160& Write(const unsigned char* data, size_t len); 24 | void Finalize(unsigned char hash[OUTPUT_SIZE]); 25 | CRIPEMD160& Reset(); 26 | }; 27 | 28 | #endif // BITCOIN_CRYPTO_RIPEMD160_H 29 | -------------------------------------------------------------------------------- /external/bitcoin-sha256/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libbitcoin-sha256.la 2 | libbitcoin_sha256_la_SOURCES = \ 3 | compat/cpuid.h \ 4 | crypto/common.h \ 5 | crypto/sha256.cpp \ 6 | crypto/sha256.h 7 | AM_CPPFLAGS = -I $(top_srcdir) 8 | -------------------------------------------------------------------------------- /external/bitcoin-sha256/README.md: -------------------------------------------------------------------------------- 1 | This is the SHA256 implementation copied from the 2 | obscure project https://github.com/bitcoin/bitcoin . 3 | 4 | Specifically, the files `crypto/sha256.cpp` and 5 | `crypto/sha256.h` are copied verbatim, while the 6 | files `crypto/common.h` and `compat/cpuid.h` are minimal 7 | shims to get the SHA256 implementation working. 8 | -------------------------------------------------------------------------------- /external/bitcoin-sha256/compat/cpuid.h: -------------------------------------------------------------------------------- 1 | #ifndef BITCOIN_SHA256_COMPAT_CPUID_H 2 | #define BITCOIN_SHA256_COMPAT_CPUID_H 3 | 4 | /* Created by ZmnSCPxj as a minimal compatibility shim. */ 5 | 6 | #endif /* !defined(BITCOIN_SHA256_COMPAT_CPUID_H) */ 7 | -------------------------------------------------------------------------------- /external/secp256k1/.gitattributes: -------------------------------------------------------------------------------- 1 | src/precomputed_ecmult.c linguist-generated 2 | src/precomputed_ecmult_gen.c linguist-generated 3 | -------------------------------------------------------------------------------- /external/secp256k1/CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0}, 3 | "version": 3, 4 | "configurePresets": [ 5 | { 6 | "name": "dev-mode", 7 | "displayName": "Development mode (intended only for developers of the library)", 8 | "cacheVariables": { 9 | "SECP256K1_EXPERIMENTAL": "ON", 10 | "SECP256K1_ENABLE_MODULE_RECOVERY": "ON", 11 | "SECP256K1_BUILD_EXAMPLES": "ON" 12 | }, 13 | "warnings": { 14 | "dev": true, 15 | "uninitialized": true 16 | } 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /external/secp256k1/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | To report security issues send an email to secp256k1-security@bitcoincore.org (not for support). 6 | 7 | The following keys may be used to communicate sensitive information to developers: 8 | 9 | | Name | Fingerprint | 10 | |------|-------------| 11 | | Pieter Wuille | 133E AC17 9436 F14A 5CF1 B794 860F EB80 4E66 9320 | 12 | | Jonas Nick | 36C7 1A37 C9D9 88BD E825 08D9 B1A7 0E4F 8DCD 0366 | 13 | | Tim Ruffing | 09E0 3F87 1092 E40E 106E 902B 33BC 86AB 80FF 5516 | 14 | 15 | You can import a key by running the following command with that individual’s fingerprint: `gpg --keyserver hkps://keys.openpgp.org --recv-keys ""` Ensure that you put quotes around fingerprints containing spaces. 16 | -------------------------------------------------------------------------------- /external/secp256k1/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | autoreconf -if --warnings=all 4 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/CheckArm32Assembly.cmake: -------------------------------------------------------------------------------- 1 | function(check_arm32_assembly) 2 | try_compile(HAVE_ARM32_ASM 3 | ${CMAKE_BINARY_DIR}/check_arm32_assembly 4 | SOURCES ${CMAKE_SOURCE_DIR}/cmake/source_arm32.s 5 | ) 6 | endfunction() 7 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/CheckStringOptionValue.cmake: -------------------------------------------------------------------------------- 1 | function(check_string_option_value option) 2 | get_property(expected_values CACHE ${option} PROPERTY STRINGS) 3 | if(expected_values) 4 | if(${option} IN_LIST expected_values) 5 | return() 6 | endif() 7 | message(FATAL_ERROR "${option} value is \"${${option}}\", but must be one of ${expected_values}.") 8 | endif() 9 | message(AUTHOR_WARNING "The STRINGS property must be set before invoking `check_string_option_value' function.") 10 | endfunction() 11 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/CheckX86_64Assembly.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCSourceCompiles) 2 | 3 | function(check_x86_64_assembly) 4 | check_c_source_compiles(" 5 | #include 6 | 7 | int main() 8 | { 9 | uint64_t a = 11, tmp; 10 | __asm__ __volatile__(\"movq $0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\"); 11 | } 12 | " HAVE_X86_64_ASM) 13 | set(HAVE_X86_64_ASM ${HAVE_X86_64_ASM} PARENT_SCOPE) 14 | endfunction() 15 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/TryAppendCFlags.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCCompilerFlag) 2 | 3 | function(secp256k1_check_c_flags_internal flags output) 4 | string(MAKE_C_IDENTIFIER "${flags}" result) 5 | string(TOUPPER "${result}" result) 6 | set(result "C_SUPPORTS_${result}") 7 | if(NOT MSVC) 8 | set(CMAKE_REQUIRED_FLAGS "-Werror") 9 | endif() 10 | 11 | # This avoids running a linker. 12 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 13 | check_c_compiler_flag("${flags}" ${result}) 14 | 15 | set(${output} ${${result}} PARENT_SCOPE) 16 | endfunction() 17 | 18 | # Append flags to the COMPILE_OPTIONS directory property if CC accepts them. 19 | macro(try_append_c_flags) 20 | secp256k1_check_c_flags_internal("${ARGV}" result) 21 | if(result) 22 | add_compile_options(${ARGV}) 23 | endif() 24 | endmacro() 25 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/arm-linux-gnueabihf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) 4 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") 4 | 5 | check_required_components(@PROJECT_NAME@) 6 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/source_arm32.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .eabi_attribute 24, 1 3 | .eabi_attribute 25, 1 4 | .text 5 | .global main 6 | main: 7 | ldr r0, =0x002A 8 | mov r7, #1 9 | swi 0 10 | -------------------------------------------------------------------------------- /external/secp256k1/cmake/x86_64-w64-mingw32.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Windows) 2 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 3 | set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) 4 | -------------------------------------------------------------------------------- /external/secp256k1/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(example INTERFACE) 2 | target_include_directories(example INTERFACE 3 | ${PROJECT_SOURCE_DIR}/include 4 | ) 5 | target_link_libraries(example INTERFACE 6 | secp256k1 7 | $<$:bcrypt> 8 | ) 9 | if(NOT BUILD_SHARED_LIBS AND MSVC) 10 | target_link_options(example INTERFACE /IGNORE:4217) 11 | endif() 12 | 13 | add_executable(ecdsa_example ecdsa.c) 14 | target_link_libraries(ecdsa_example example) 15 | add_test(NAME ecdsa_example COMMAND ecdsa_example) 16 | 17 | if(SECP256K1_ENABLE_MODULE_ECDH) 18 | add_executable(ecdh_example ecdh.c) 19 | target_link_libraries(ecdh_example example) 20 | add_test(NAME ecdh_example COMMAND ecdh_example) 21 | endif() 22 | 23 | if(SECP256K1_ENABLE_MODULE_SCHNORRSIG) 24 | add_executable(schnorr_example schnorr.c) 25 | target_link_libraries(schnorr_example example) 26 | add_test(NAME schnorr_example COMMAND schnorr_example) 27 | endif() 28 | -------------------------------------------------------------------------------- /external/secp256k1/libsecp256k1.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libsecp256k1 7 | Description: Optimized C library for EC operations on curve secp256k1 8 | URL: https://github.com/bitcoin-core/secp256k1 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lsecp256k1 12 | 13 | -------------------------------------------------------------------------------- /external/secp256k1/src/ecmult_gen_compute_table.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H 8 | #define SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H 9 | 10 | #include "ecmult_gen.h" 11 | 12 | static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, const secp256k1_ge* gen, int bits); 13 | 14 | #endif /* SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H */ 15 | -------------------------------------------------------------------------------- /external/secp256k1/src/int128_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_INT128_IMPL_H 2 | #define SECP256K1_INT128_IMPL_H 3 | 4 | #include "util.h" 5 | 6 | #include "int128.h" 7 | 8 | #if defined(SECP256K1_WIDEMUL_INT128) 9 | # if defined(SECP256K1_INT128_NATIVE) 10 | # include "int128_native_impl.h" 11 | # elif defined(SECP256K1_INT128_STRUCT) 12 | # include "int128_struct_impl.h" 13 | # else 14 | # error "Please select int128 implementation" 15 | # endif 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /external/secp256k1/src/int128_native.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_INT128_NATIVE_H 2 | #define SECP256K1_INT128_NATIVE_H 3 | 4 | #include 5 | #include "util.h" 6 | 7 | #if !defined(UINT128_MAX) && defined(__SIZEOF_INT128__) 8 | SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t; 9 | SECP256K1_GNUC_EXT typedef __int128 int128_t; 10 | # define UINT128_MAX ((uint128_t)(-1)) 11 | # define INT128_MAX ((int128_t)(UINT128_MAX >> 1)) 12 | # define INT128_MIN (-INT128_MAX - 1) 13 | /* No (U)INT128_C macros because compilers providing __int128 do not support 128-bit literals. */ 14 | #endif 15 | 16 | typedef uint128_t secp256k1_uint128; 17 | typedef int128_t secp256k1_int128; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /external/secp256k1/src/int128_struct.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_INT128_STRUCT_H 2 | #define SECP256K1_INT128_STRUCT_H 3 | 4 | #include 5 | #include "util.h" 6 | 7 | typedef struct { 8 | uint64_t lo; 9 | uint64_t hi; 10 | } secp256k1_uint128; 11 | 12 | typedef secp256k1_uint128 secp256k1_int128; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /external/secp256k1/src/modules/ecdh/Makefile.am.include: -------------------------------------------------------------------------------- 1 | noinst_HEADERS += include/secp256k1_ecdh.h 2 | noinst_HEADERS += src/modules/ecdh/main_impl.h 3 | noinst_HEADERS += src/modules/ecdh/tests_impl.h 4 | noinst_HEADERS += src/modules/ecdh/bench_impl.h 5 | -------------------------------------------------------------------------------- /external/secp256k1/src/modules/extrakeys/Makefile.am.include: -------------------------------------------------------------------------------- 1 | noinst_HEADERS += include/secp256k1_extrakeys.h 2 | noinst_HEADERS += src/modules/extrakeys/tests_impl.h 3 | noinst_HEADERS += src/modules/extrakeys/tests_exhaustive_impl.h 4 | noinst_HEADERS += src/modules/extrakeys/main_impl.h 5 | -------------------------------------------------------------------------------- /external/secp256k1/src/modules/recovery/Makefile.am.include: -------------------------------------------------------------------------------- 1 | noinst_HEADERS += include/secp256k1_recovery.h 2 | noinst_HEADERS += src/modules/recovery/main_impl.h 3 | noinst_HEADERS += src/modules/recovery/tests_impl.h 4 | noinst_HEADERS += src/modules/recovery/tests_exhaustive_impl.h 5 | noinst_HEADERS += src/modules/recovery/bench_impl.h 6 | -------------------------------------------------------------------------------- /external/secp256k1/src/modules/schnorrsig/Makefile.am.include: -------------------------------------------------------------------------------- 1 | noinst_HEADERS += include/secp256k1_schnorrsig.h 2 | noinst_HEADERS += src/modules/schnorrsig/main_impl.h 3 | noinst_HEADERS += src/modules/schnorrsig/tests_impl.h 4 | noinst_HEADERS += src/modules/schnorrsig/tests_exhaustive_impl.h 5 | noinst_HEADERS += src/modules/schnorrsig/bench_impl.h 6 | -------------------------------------------------------------------------------- /external/secp256k1/src/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_SCALAR_REPR_H 8 | #define SECP256K1_SCALAR_REPR_H 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif /* SECP256K1_SCALAR_REPR_H */ 20 | -------------------------------------------------------------------------------- /external/secp256k1/src/scalar_8x32.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_SCALAR_REPR_H 8 | #define SECP256K1_SCALAR_REPR_H 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint32_t d[8]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} 18 | 19 | #endif /* SECP256K1_SCALAR_REPR_H */ 20 | -------------------------------------------------------------------------------- /external/secp256k1/src/scalar_low.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_SCALAR_REPR_H 8 | #define SECP256K1_SCALAR_REPR_H 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef uint32_t secp256k1_scalar; 14 | 15 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) (d0) 16 | 17 | #endif /* SECP256K1_SCALAR_REPR_H */ 18 | -------------------------------------------------------------------------------- /external/update-secp256k1.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | REPO="https://github.com/bitcoin-core/secp256k1" 4 | EXTNAME="secp256k1" 5 | COMMIT="acf5c55ae6a94e5ca847e07def40427547876101" 6 | 7 | DIR=`mktemp -d` 8 | 9 | if git clone ${REPO} "$DIR"; then 10 | : 11 | else 12 | printf 'Failed to clone "%s".\n' "${REPO}" 1>&2 13 | exit 1 14 | fi 15 | 16 | ORIGDIR="`pwd`/external" 17 | 18 | cd ${DIR} 19 | 20 | if git reset --hard ${COMMIT}; then 21 | : 22 | else 23 | printf 'Failed to find commit "%s".\n' "${COMMIT}" 1>&2 24 | cd "$ORIGDIR" 25 | rm -rf "${DIR}" 26 | exit 1 27 | fi 28 | 29 | find '(' -name '.git' ')' -exec rm -rf '{}' ';' 30 | 31 | if patch -p1 < "${ORIGDIR}"/"${EXTNAME}.patch"; then 32 | : 33 | else 34 | printf 'Failed to apply patch "%s".\n' "${ORIGDIR}"/"${EXTNAME}.patch" 1>&2 35 | cd "$ORIGDIR" 36 | rm -rf ${DIR} 37 | exit 1 38 | fi 39 | 40 | cd "$ORIGDIR" 41 | rm -rf "${EXTNAME}" > /dev/null 2>&1 42 | cp -r "${DIR}" "${EXTNAME}" 43 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "CLBOSS Automated Core Lightning Node Manager"; 3 | nixConfig.bash-prompt = "\[nix-develop\]$ "; 4 | 5 | inputs = { 6 | nixpkgs.url = "github:nixos/nixpkgs"; 7 | flake-utils.url = "github:numtide/flake-utils"; 8 | }; 9 | 10 | outputs = { self, nixpkgs, flake-utils }: 11 | flake-utils.lib.eachDefaultSystem (system: 12 | let pkgs = nixpkgs.legacyPackages.${system}; 13 | in { 14 | packages = { 15 | default = pkgs.neofetch; 16 | }; 17 | 18 | formatter = pkgs.nixpkgs-fmt; 19 | devShell = pkgs.mkShell { 20 | buildInputs = with pkgs; [ 21 | gcc 22 | pkg-config 23 | libev 24 | libevdev 25 | curl 26 | libunwind 27 | sqlite 28 | bind 29 | autoconf 30 | autoconf-archive 31 | libtool 32 | automake 33 | git 34 | 35 | # editor support 36 | bear 37 | ]; 38 | }; 39 | } 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /generate_commit_hash.sh: -------------------------------------------------------------------------------- 1 | # generate_commit_hash.sh 2 | echo "#pragma once" > commit_hash.h 3 | echo "#define GIT_COMMIT_HASH \"$(git rev-parse HEAD)\"" >> commit_hash.h 4 | echo "#define GIT_DESCRIBE \"$(git describe --tags --long --always --match=v*.* --dirty)\"" >> commit_hash.h 5 | -------------------------------------------------------------------------------- /reproducible/.gitignore: -------------------------------------------------------------------------------- 1 | clboss-* 2 | manifest.scm 3 | tmp 4 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | (import 2 | ( 3 | let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in 4 | fetchTarball { 5 | url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; 6 | sha256 = lock.nodes.flake-compat.locked.narHash; 7 | } 8 | ) 9 | { src = ./.; } 10 | # Since a lot of existing CI tests is based on `shell.nix` 11 | # we forward to the integrationTests shell, instead of the 12 | # default (developer) shell. 13 | ).shellNix.devShells."${builtins.currentSystem}".integrationTests 14 | -------------------------------------------------------------------------------- /tests/dnsseed/test_get.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"DnsSeed/get.hpp" 3 | #include"Ev/Io.hpp" 4 | #include"Ev/start.hpp" 5 | #include 6 | 7 | int main() { 8 | auto code = Ev::lift().then([]() { 9 | return DnsSeed::can_get(); 10 | }).then([&](std::string err) { 11 | if (err != "") 12 | /* Trivial exit. */ 13 | return Ev::lift(0); 14 | return Ev::lift().then([]() { 15 | return DnsSeed::get("lseed.bitcoinstats.com"); 16 | }).then([](std::vector results) { 17 | /* Nothing to check, mostly just a 18 | * "does not crash" test. */ 19 | 20 | return DnsSeed::get("lseed.darosior.ninja", "8.8.8.8"); 21 | }).then([](std::vector results) { 22 | 23 | return Ev::lift(0); 24 | }); 25 | }); 26 | return Ev::start(code); 27 | } 28 | -------------------------------------------------------------------------------- /tests/ev/test_concurrent_simple.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include 3 | #include"Ev/Io.hpp" 4 | #include"Ev/concurrent.hpp" 5 | #include"Ev/start.hpp" 6 | #include"Ev/yield.hpp" 7 | 8 | int main() { 9 | auto flag1 = bool(false); 10 | auto flag2 = bool(false); 11 | auto ec = Ev::start(Ev::yield().then([&]() { 12 | return Ev::concurrent(Ev::yield().then([&]() { 13 | flag1 = true; 14 | return Ev::lift(); 15 | })); 16 | }).then([&]() { 17 | /* Concurrent task not started yet. */ 18 | assert(!flag1); 19 | flag2 = true; 20 | return Ev::lift(0); 21 | })); 22 | assert(flag1); 23 | assert(flag2); 24 | 25 | return ec; 26 | } 27 | -------------------------------------------------------------------------------- /tests/ev/test_throw_in_then.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Ev/Io.hpp" 3 | #include"Ev/start.hpp" 4 | #include"Ev/yield.hpp" 5 | #include 6 | 7 | int main() { 8 | auto code = Ev::yield().then([]() { 9 | throw int(42); 10 | return Ev::lift(1); 11 | }).catching([](int _) { 12 | return Ev::lift(0); 13 | }); 14 | return Ev::start(code); 15 | } 16 | -------------------------------------------------------------------------------- /tests/jsmn/test_iterator.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Jsmn/Object.hpp" 3 | #include"Jsmn/Parser.hpp" 4 | #include"Util/stringify.hpp" 5 | #include 6 | #include 7 | 8 | int main() { 9 | auto vectors = std::vector{ 10 | R"JSON( 11 | [ 0 12 | , 1 13 | , 2 14 | , 3 15 | ] 16 | )JSON", 17 | R"JSON( 18 | [ {"asdf": 42} 19 | , {"nested" : {"nested": {"leaf": 0}}} 20 | , [0, 1, 2, {}] 21 | , 3 22 | ] 23 | )JSON", 24 | R"JSON( 25 | [] 26 | )JSON", 27 | }; 28 | for (auto const& v: vectors) { 29 | Jsmn::Parser p; 30 | auto jv = p.feed(v); 31 | assert(jv.size() == 1); 32 | auto js = jv[0]; 33 | 34 | auto i = std::size_t(0); 35 | for (auto entry: js) { 36 | auto a = Util::stringify(entry); 37 | auto b = Util::stringify(js[i]); 38 | assert(a == b); 39 | ++i; 40 | } 41 | assert(i == js.size()); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /tests/ln/test_commandid.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Ln/CommandId.hpp" 3 | #include"Jsmn/Object.hpp" 4 | #include 5 | #include 6 | 7 | namespace { 8 | 9 | std::unique_ptr 10 | from_json(std::string jtxt) { 11 | auto jobj = Jsmn::Object(); 12 | auto is = std::istringstream(jtxt + "\n"); 13 | is >> jobj; 14 | return Ln::command_id_from_jsmn_object(jobj); 15 | } 16 | 17 | } 18 | 19 | int main() { 20 | using Ln::CommandId; 21 | 22 | { 23 | auto cid = from_json("{}"); 24 | assert(!cid); 25 | 26 | cid = from_json("42"); 27 | assert(cid); 28 | assert(*cid == CommandId::left(42)); 29 | 30 | cid = from_json("\"a string key\""); 31 | assert(cid); 32 | assert(*cid == CommandId::right("a string key")); 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /tests/ln/test_scid.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Ln/Scid.hpp" 3 | #include 4 | 5 | int main() { 6 | auto a = Ln::Scid("1x1x1"); 7 | auto b = Ln::Scid("1x1x2"); 8 | assert(a != b); 9 | b = a; 10 | assert(a == b); 11 | 12 | assert(!Ln::Scid::valid_string("garbage")); 13 | assert(Ln::Scid::valid_string("85824x235x3")); 14 | 15 | a = Ln::Scid("94x2x3"); 16 | b = Ln::Scid("0x2x3"); 17 | assert(b < a); 18 | assert(a > b); 19 | assert(b <= a); 20 | assert(a >= b); 21 | assert(!(a <= b)); 22 | assert(!(b >= a)); 23 | b = a; 24 | assert(b <= a); 25 | assert(a >= b); 26 | 27 | /* Out of range. */ 28 | assert(!Ln::Scid::valid_string("1x1x65537")); 29 | assert(!Ln::Scid::valid_string("1x16777777x1")); 30 | assert(!Ln::Scid::valid_string("16777777x1x1")); 31 | 32 | /* Strings. */ 33 | assert(std::string(Ln::Scid("5x4x1")) == "5x4x1"); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/stats/test_running_mean.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Stats/RunningMean.cpp" 3 | #include 4 | #include 5 | 6 | int main() { 7 | auto m1 = Stats::RunningMean(); 8 | 9 | m1.sample(1.0); 10 | assert(m1.get() == 1.0); 11 | m1.sample(2.0); 12 | assert(m1.get() == 1.5); 13 | m1.sample(3.0); 14 | assert(m1.get() == 2.0); 15 | m1.sample(4.0); 16 | assert(m1.get() == 2.5); 17 | m1.sample(1.0); 18 | assert(m1.get() == 2.2); 19 | 20 | /* Check serialize/deserialize code. */ 21 | auto ss = std::stringstream(); 22 | ss << m1; 23 | auto m2 = Stats::RunningMean(); 24 | ss >> m2; 25 | m1.sample(4.0); m2.sample(4.0); 26 | assert(m1.get() == m2.get()); 27 | m1.sample(1.0); m2.sample(1.0); 28 | assert(m1.get() == m2.get()); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/test_uuid.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Uuid.hpp" 3 | #include 4 | 5 | int main() { 6 | auto a = Uuid(); 7 | auto b = Uuid(); 8 | assert(a == b); 9 | assert(Uuid() == b); 10 | assert(a == Uuid()); 11 | assert(!a); 12 | 13 | a = Uuid::random(); 14 | assert(a); /* With very high probability, at least. */ 15 | assert(a != b); 16 | b = a; 17 | assert(a == b); 18 | assert(std::hash()(a) == std::hash()(b)); 19 | 20 | b = (Uuid)(std::string)a; 21 | assert(a == b); 22 | assert(std::hash()(a) == std::hash()(b)); 23 | 24 | a = Uuid("00112233445566778899aabbccddeeff"); 25 | b = Uuid("00112233445566778899aabbccddeeff"); 26 | assert(a == b); 27 | assert(a); 28 | assert(b); 29 | assert(std::hash()(a) == std::hash()(b)); 30 | assert(std::string(a) == "00112233445566778899aabbccddeeff"); 31 | 32 | b = Uuid("00112233445566778899aabbccddeefe"); 33 | assert(a != b); 34 | 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /tests/util/test_date.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Util/date.hpp" 3 | #include 4 | 5 | int main() { 6 | assert(Util::date(0.0) == "UTC 1970-01-01 00:00:00.000"); 7 | assert(Util::date(1.1) == "UTC 1970-01-01 00:00:01.100"); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/util/test_format.cpp: -------------------------------------------------------------------------------- 1 | #undef NDEBUG 2 | #include"Util/format.hpp" 3 | #include 4 | 5 | int main() { 6 | assert(Util::format("foo") == "foo"); 7 | assert(Util::format("foo %d", 42) == "foo 42"); 8 | assert(Util::format("foo %d %0.1f", 42, double(0.0)) == "foo 42 0.0"); 9 | assert(Util::format("foo %s batz", "bar") == "foo bar batz"); 10 | 11 | return 0; 12 | } 13 | --------------------------------------------------------------------------------