Fabcoin Core  0.16.2
P2P Digital Currency
AdminNet.cpp
Go to the documentation of this file.
1 #include <jsonrpccpp/common/exception.h>
2 #include <libwebthree/WebThree.h>
3 #include <libdevcore/CommonJS.h>
4 #include <libethcore/Common.h>
5 #include "AdminNet.h"
6 #include "SessionManager.h"
7 #include "JsonHelper.h"
8 
9 using namespace std;
10 using namespace dev;
11 using namespace dev::rpc;
12 
13 AdminNet::AdminNet(NetworkFace& _network, SessionManager& _sm): m_network(_network), m_sm(_sm) {}
14 
15 bool AdminNet::admin_net_start(std::string const& _session)
16 {
17  RPC_ADMIN;
19  return true;
20 }
21 
22 bool AdminNet::admin_net_stop(std::string const& _session)
23 {
24  RPC_ADMIN;
26  return true;
27 }
28 
29 bool AdminNet::admin_net_connect(std::string const& _node, std::string const& _session)
30 {
31  RPC_ADMIN;
32  return admin_addPeer(_node);
33 }
34 
35 Json::Value AdminNet::admin_net_peers(std::string const& _session)
36 {
37  RPC_ADMIN;
38  return admin_peers();
39 }
40 
41 Json::Value AdminNet::admin_net_nodeInfo(std::string const& _session)
42 {
43  RPC_ADMIN;
44  Json::Value ret;
46  ret["name"] = i.version;
47  ret["port"] = i.port;
48  ret["address"] = i.address;
49  ret["listenAddr"] = i.address + ":" + toString(i.port);
50  ret["id"] = i.id.hex();
51  ret["enode"] = i.enode();
52  return ret;
53 }
54 
56 {
57  Json::Value ret;
59  ret["name"] = i.version;
60  ret["ports"] = Json::objectValue;
61  // Both ports are equal as of 2016-02-04, migt change later
62  ret["ports"]["discovery"] = i.port;
63  ret["ports"]["listener"] = i.port;
64  ret["ip"] = i.address;
65  ret["listenAddr"] = i.address + ":" + toString(i.port);
66  ret["id"] = i.id.hex();
67  ret["enode"] = i.enode();
68  ret["protocols"] = Json::objectValue;
69  ret["protocols"]["eth"] = Json::objectValue; //@todo fill with information
70  return ret;
71 }
72 
74 {
75  Json::Value ret;
76  for (p2p::PeerSessionInfo const& peer: m_network.peers())
77  ret.append(toJson(peer));
78  return ret;
79 }
80 
81 bool AdminNet::admin_addPeer(string const& _node)
82 {
84  return true;
85 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
virtual bool admin_net_stop(std::string const &_session) override
Definition: AdminNet.cpp:22
unsigned port
Definition: Host.h:118
virtual bool admin_net_start(std::string const &_session) override
Definition: AdminNet.cpp:15
virtual Json::Value admin_net_peers(std::string const &_session) override
Definition: AdminNet.cpp:35
std::hash for asio::adress
Definition: Common.h:323
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
virtual bool admin_addPeer(std::string const &_node) override
Definition: AdminNet.cpp:81
std::string enode() const
Definition: Host.h:114
virtual Json::Value admin_peers() override
Definition: AdminNet.cpp:73
virtual bool admin_net_connect(std::string const &_node, std::string const &_session) override
Definition: AdminNet.cpp:29
Config::Value_type Value
#define RPC_ADMIN
Definition: SessionManager.h:5
virtual Json::Value admin_net_nodeInfo(std::string const &_session) override
Definition: AdminNet.cpp:41
virtual Json::Value admin_nodeInfo() override
Definition: AdminNet.cpp:55
Json::Value toJson(unordered_map< u256, u256 > const &_storage)
Definition: JsonHelper.cpp:41
std::string version
Definition: Host.h:119
virtual void startNetwork()=0
Start the network subsystem.
NetworkFace & m_network
Definition: AdminNet.h:32
std::string address
Definition: Host.h:117
virtual void stopNetwork()=0
Stop the network subsystem.
virtual std::vector< p2p::PeerSessionInfo > peers()=0
Get information on the current peer set.
virtual void addPeer(p2p::NodeSpec const &_node, p2p::PeerType _t)=0
Generalised peer addition.
virtual p2p::NodeInfo nodeInfo() const =0
Get information concerning this node.
std::string hex() const
Definition: FixedHash.h:130