// Copyright (c) 2012-2014, The CryptoNote developers, The Bytecoin developers // // This file is part of Bytecoin. // // Bytecoin is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Bytecoin is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with Bytecoin. If not, see . #pragma once #include #include #include #include "common/ObserverManager.h" #include "include_base_utils.h" #include "net/http_client.h" #include "InitState.h" #include "INode.h" namespace cryptonote { class NodeRpcProxy : public CryptoNote::INode { public: NodeRpcProxy(const std::string& nodeHost, unsigned short nodePort); virtual ~NodeRpcProxy(); virtual bool addObserver(CryptoNote::INodeObserver* observer); virtual bool removeObserver(CryptoNote::INodeObserver* observer); virtual void init(const Callback& callback); virtual bool shutdown(); virtual size_t getPeerCount() const; virtual uint64_t getLastLocalBlockHeight() const; virtual uint64_t getLastKnownBlockHeight() const; virtual void relayTransaction(const cryptonote::transaction& transaction, const Callback& callback); virtual void getRandomOutsByAmounts(std::vector&& amounts, uint64_t outsCount, std::vector& result, const Callback& callback); virtual void getNewBlocks(std::list&& knownBlockIds, std::list& newBlocks, uint64_t& startHeight, const Callback& callback); virtual void getTransactionOutsGlobalIndices(const crypto::hash& transactionHash, std::vector& outsGlobalIndices, const Callback& callback); unsigned int rpcTimeout() const { return m_rpcTimeout; } void rpcTimeout(unsigned int val) { m_rpcTimeout = val; } private: void resetInternalState(); void workerThread(const Callback& initialized_callback); void pullNodeStatusAndScheduleTheNext(); void updateNodeStatus(); void updatePeerCount(); void doRelayTransaction(const cryptonote::transaction& transaction, const Callback& callback); void doGetRandomOutsByAmounts(std::vector& amounts, uint64_t outsCount, std::vector& result, const Callback& callback); void doGetNewBlocks(std::list& knownBlockIds, std::list& newBlocks, uint64_t& startHeight, const Callback& callback); void doGetTransactionOutsGlobalIndices(const crypto::hash& transactionHash, std::vector& outsGlobalIndices, const Callback& callback); private: tools::InitState m_initState; std::thread m_workerThread; boost::asio::io_service m_ioService; tools::ObserverManager m_observerManager; std::string m_nodeAddress; unsigned int m_rpcTimeout; epee::net_utils::http::http_simple_client m_httpClient; boost::asio::deadline_timer m_pullTimer; uint64_t m_pullInterval; // Internal state size_t m_peerCount; uint64_t m_nodeHeight; uint64_t m_networkHeight; crypto::hash m_lastKnowHash; }; }