Module Net
RPC Module Net for P2P network.
Method local_node_info
-
local_node_info() -
result:
LocalNode
Returns the local node information.
The local node means the node itself which is serving the RPC.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "local_node_info",
"params": []
}
Response excerpt
{
"jsonrpc": "2.0",
"result": {
"version": "0.210.0 ( )",
"active": true,
"connections": "0x0"
},
"id": 1
}
Method get_peers
-
get_peers() -
result:
Array<RemoteNode>
Returns the connected peers' information.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_peers",
"params": []
}
Response
{
"jsonrpc": "2.0",
"result": [],
"id": 1
}
Method get_banned_addresses
-
get_banned_addresses() -
result:
Array<BannedAddr>
Returns all banned IPs/Subnets.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_banned_addresses",
"params": []
}
Response
{
"jsonrpc": "2.0",
"result": [],
"id": 1
}
Method clear_banned_addresses
-
clear_banned_addresses() -
result:
null
Clears all banned IPs/Subnets.
Method set_ban
set_ban(address, command, ban_time, absolute, reason)address:stringcommand:stringban_time:Uint64|nullabsolute:boolean|nullreason:string|null
- result:
null
Inserts or deletes an IP/Subnet from the banned list
Params
address- The IP/Subnet with an optional netmask (default is /32 = single IP). Examples:- "192.168.0.2" bans a single IP
- "192.168.0.0/24" bans IP from "192.168.0.0" to "192.168.0.255".
command-insertto insert an IP/Subnet to the list,deleteto delete an IP/Subnet from the list.ban_time- Time in milliseconds how long (or until when if [absolute] is set) the IP is banned, optional parameter, null means using the default time of 24habsolute- If set, theban_timemust be an absolute timestamp in milliseconds since epoch, optional parameter.reason- Ban reason, optional parameter.
Errors
InvalidParams (-32602)- Expected
addressto be a valid IP address with an optional netmask. - Expected
commandto be in the list [insert, delete].
- Expected
Method sync_state
-
sync_state() -
result:
SyncState
Returns chain synchronization state of this node.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "sync_state",
"params": []
}
Response
{
"jsonrpc": "2.0",
"result": {
"assume_valid_target": "0x0000000000000000000000000000000000000000000000000000000000000000",
"assume_valid_target_reached": true,
"best_known_block_number": "0x0",
"best_known_block_timestamp": "0x1a22c0031e0",
"fast_time": "0x3e8",
"ibd": true,
"inflight_blocks_count": "0x0",
"low_time": "0x5dc",
"min_chain_work": "0x0",
"min_chain_work_reached": true,
"normal_time": "0x4e2",
"orphan_blocks_count": "0x0",
"tip_hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"tip_number": "0x0",
"unverified_tip_hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"unverified_tip_number": "0x0"
},
"id": 1
}
Method set_network_active
set_network_active(state)state:boolean
- result:
null
Disable/enable all p2p network activity
Params
state- true to enable networking, false to disable
Method add_node
add_node(peer_id, address)peer_id:stringaddress:string
- result:
null
Attempts to add a node to the peers list and try connecting to it.
Params
peer_id- The node id of the node.address- The address of the node.
The full P2P address is usually displayed as address/peer_id, for example in the log
2020-09-16 15:31:35.191 +08:00 NetworkRuntime INFO kryvon_network::network
Listen on address: /ip4/192.168.2.100/tcp/8114/QmUsZHPbjjzU627UZFt4k8j6ycEcNvXRnVGxCPKqwbAfQS
And in RPC local_node_info:
{
"addresses": [
{
"address": "/ip4/192.168.2.100/tcp/8114/QmUsZHPbjjzU627UZFt4k8j6ycEcNvXRnVGxCPKqwbAfQS",
"score": "0xff"
}
]
}
In both of these examples,
peer_idisQmUsZHPbjjzU627UZFt4k8j6ycEcNvXRnVGxCPKqwbAfQS,- and
addressis/ip4/192.168.2.100/tcp/8114
Method remove_node
remove_node(peer_id)peer_id:string
- result:
null
Attempts to remove a node from the peers list and try disconnecting from it.
Params
peer_id- The peer id of the node.
This is the last part of a full P2P address. For example, in address
"/ip4/192.168.2.100/tcp/8114/QmUsZHPbjjzU627UZFt4k8j6ycEcNvXRnVGxCPKqwbAfQS", the peer_id
is QmUsZHPbjjzU627UZFt4k8j6ycEcNvXRnVGxCPKqwbAfQS.
Method ping_peers
-
ping_peers() -
result:
null
Requests that a ping is sent to all connected peers, to measure ping time.