diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -239,7 +239,9 @@ RWCollection queries; - /** The key used to sign responses. */ + /** Data required to participate. */ + struct PeerData; + std::unique_ptr peerData; CKey sessionKey; /** Event loop machinery. */ @@ -270,7 +272,7 @@ const Delegation &delegation); bool forNode(NodeId nodeid, std::function func) const; - CPubKey getSessionPubKey() const { return sessionKey.GetPubKey(); } + CPubKey getSessionPubKey() const; bool startEventLoop(CScheduler &scheduler); bool stopEventLoop(); diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -4,6 +4,7 @@ #include +#include #include #include #include // For DecodeSecret @@ -134,6 +135,11 @@ return true; } +struct Processor::PeerData { + Proof proof; + Delegation delegation; +}; + class Processor::NotificationsHandler : public interfaces::Chain::Notifications { Processor *m_processor; @@ -157,6 +163,27 @@ sessionKey.MakeNewKey(true); } + if (gArgs.IsArgSet("-avaproof")) { + peerData = std::make_unique(); + + { + // The proof. + CDataStream stream(ParseHex(gArgs.GetArg("-avaproof", "")), + SER_NETWORK, 0); + stream >> peerData->proof; + LOCK(cs_peerManager); + peerManager->getPeer(peerData->proof); + } + + // Generate the delegation to the session key. + DelegationBuilder dgb(peerData->proof); + if (sessionKey.GetPubKey() != peerData->proof.getMaster()) { + dgb.addLevel(DecodeSecret(gArgs.GetArg("-avamasterkey", "")), + sessionKey.GetPubKey()); + } + peerData->delegation = dgb.build(); + } + // Make sure we get notified of chain state changes. chainNotificationsHandler = chain.handleNotifications(std::make_shared(this)); @@ -364,6 +391,10 @@ return peerManager->forNode(nodeid, std::move(func)); } +CPubKey Processor::getSessionPubKey() const { + return sessionKey.GetPubKey(); +} + bool Processor::startEventLoop(CScheduler &scheduler) { return eventLoop.startEventLoop( scheduler, [this]() { this->runEventLoop(); }, AVALANCHE_TIME_STEP); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1195,6 +1195,13 @@ strprintf("Mandatory cooldown between two avapoll (default: %u)", AVALANCHE_DEFAULT_COOLDOWN), ArgsManager::ALLOW_ANY, OptionsCategory::AVALANCHE); + gArgs.AddArg("-avaproof", + "Avalanche proof to be used by this node (default: none)", + ArgsManager::ALLOW_ANY, OptionsCategory::AVALANCHE); + gArgs.AddArg("-avamasterkey", + "Master key associated with the proof. If a proof is " + "required, this is mandatory.", + ArgsManager::ALLOW_ANY, OptionsCategory::AVALANCHE); gArgs.AddArg("-avasessionkey", "Avalanche session key (default: random)", ArgsManager::ALLOW_ANY, OptionsCategory::AVALANCHE);