This repository was archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathAdminNet.cpp
More file actions
85 lines (75 loc) · 2.01 KB
/
AdminNet.cpp
File metadata and controls
85 lines (75 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <jsonrpccpp/common/exception.h>
#include <libwebthree/WebThree.h>
#include <libdevcore/CommonJS.h>
#include <libethcore/Common.h>
#include "AdminNet.h"
#include "SessionManager.h"
#include "JsonHelper.h"
using namespace std;
using namespace dev;
using namespace dev::rpc;
AdminNet::AdminNet(NetworkFace& _network, SessionManager& _sm): m_network(_network), m_sm(_sm) {}
bool AdminNet::admin_net_start(std::string const& _session)
{
RPC_ADMIN;
m_network.startNetwork();
return true;
}
bool AdminNet::admin_net_stop(std::string const& _session)
{
RPC_ADMIN;
m_network.stopNetwork();
return true;
}
bool AdminNet::admin_net_connect(std::string const& _node, std::string const& _session)
{
RPC_ADMIN;
return admin_addPeer(_node);
}
Json::Value AdminNet::admin_net_peers(std::string const& _session)
{
RPC_ADMIN;
return admin_peers();
}
Json::Value AdminNet::admin_net_nodeInfo(std::string const& _session)
{
RPC_ADMIN;
Json::Value ret;
p2p::NodeInfo i = m_network.nodeInfo();
ret["name"] = i.version;
ret["port"] = i.port;
ret["address"] = i.address;
ret["listenAddr"] = i.address + ":" + toString(i.port);
ret["id"] = i.id.hex();
ret["enode"] = i.enode();
return ret;
}
Json::Value AdminNet::admin_nodeInfo()
{
Json::Value ret;
p2p::NodeInfo i = m_network.nodeInfo();
ret["name"] = i.version;
ret["ports"] = Json::objectValue;
// Both ports are equal as of 2016-02-04, migt change later
ret["ports"]["discovery"] = i.port;
ret["ports"]["listener"] = i.port;
ret["ip"] = i.address;
ret["listenAddr"] = i.address + ":" + toString(i.port);
ret["id"] = i.id.hex();
ret["enode"] = i.enode();
ret["protocols"] = Json::objectValue;
ret["protocols"]["eth"] = Json::objectValue; //@todo fill with information
return ret;
}
Json::Value AdminNet::admin_peers()
{
Json::Value ret;
for (p2p::PeerSessionInfo const& peer: m_network.peers())
ret.append(toJson(peer));
return ret;
}
bool AdminNet::admin_addPeer(string const& _node)
{
m_network.addPeer(p2p::NodeSpec(_node), p2p::PeerType::Required);
return true;
}