2018-01-22 21:58:43 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2018-01-22 21:58:43 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
module S = struct
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
let versions =
|
|
|
|
RPC_service.post_service
|
|
|
|
~description:"Supported network layer versions."
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: (Data_encoding.list P2p_version.encoding)
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "versions")
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
let stat =
|
2018-01-22 21:58:43 +04:00
|
|
|
RPC_service.post_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"Global network bandwidth statistics in B/s."
|
2018-01-22 21:58:43 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
2018-02-08 13:51:02 +04:00
|
|
|
~output: P2p_stat.encoding
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "stat")
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
let events =
|
2018-01-22 21:58:43 +04:00
|
|
|
RPC_service.post_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"Stream of all network events"
|
2018-01-22 21:58:43 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
2018-02-08 13:51:02 +04:00
|
|
|
~output: P2p_connection.Pool_event.encoding
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "log")
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
let connect =
|
2018-01-22 21:58:43 +04:00
|
|
|
RPC_service.post_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"Connect to a peer"
|
2018-01-22 21:58:43 +04:00
|
|
|
~query: RPC_query.empty
|
2018-02-08 13:51:02 +04:00
|
|
|
~input: Data_encoding.(obj1 (dft "timeout" float 5.))
|
2018-02-11 22:17:39 +04:00
|
|
|
~output: Data_encoding.empty
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "connect" /: P2p_point.Id.rpc_arg)
|
2018-01-22 21:58:43 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
open RPC_context
|
|
|
|
let stat ctxt = make_call S.stat ctxt () () ()
|
|
|
|
let versions ctxt = make_call S.versions ctxt () () ()
|
|
|
|
let events ctxt = make_streamed_call S.events ctxt () () ()
|
|
|
|
let connect ctxt ~timeout peer_id =
|
2018-02-11 22:17:39 +04:00
|
|
|
make_call1 S.connect ctxt peer_id () timeout
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
let monitor_encoding = Data_encoding.(obj1 (dft "monitor" bool false))
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
module Connections = struct
|
|
|
|
|
|
|
|
module S = struct
|
|
|
|
|
|
|
|
let list =
|
|
|
|
RPC_service.post_service
|
|
|
|
~description:"List the running P2P connection."
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: (Data_encoding.list P2p_connection.Info.encoding)
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "connections")
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
let info =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: P2p_connection.Info.encoding
|
|
|
|
~description:"Details about the current P2P connection to the given peer."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "connections" /: P2p_peer.Id.rpc_arg)
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
let kick =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.(obj1 (req "wait" bool))
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Forced close of the current P2P connection to the given peer."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "connections" /: P2p_peer.Id.rpc_arg / "kick")
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
let list ctxt = make_call S.list ctxt () () ()
|
|
|
|
let info ctxt peer_id = make_call1 S.info ctxt peer_id () ()
|
|
|
|
let kick ctxt ?(wait = false) peer_id = make_call1 S.kick ctxt peer_id () wait
|
2018-01-22 21:58:43 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
module Points = struct
|
|
|
|
|
|
|
|
module S = struct
|
|
|
|
|
|
|
|
let info =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: P2p_point.Info.encoding
|
|
|
|
~description: "Details about a given `IP:addr`."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg)
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
let events =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: monitor_encoding
|
|
|
|
~output: (Data_encoding.list
|
|
|
|
P2p_point.Pool_event.encoding)
|
|
|
|
~description: "Monitor network events related to an `IP:addr`."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "log")
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
let list =
|
|
|
|
let filter =
|
|
|
|
let open Data_encoding in
|
|
|
|
obj1 (dft "filter" (list P2p_point.State.encoding) []) in
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: filter
|
|
|
|
~output:
|
|
|
|
Data_encoding.(list (tup2
|
|
|
|
P2p_point.Id.encoding
|
|
|
|
P2p_point.Info.encoding))
|
|
|
|
~description:"List the pool of known `IP:port` \
|
2018-02-22 18:35:50 +04:00
|
|
|
used for establishing P2P connections."
|
|
|
|
RPC_path.(root / "network" / "points")
|
|
|
|
|
|
|
|
let forget =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Remove the given address from the whitelist/blacklist."
|
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "forget" )
|
|
|
|
|
|
|
|
let ban =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-03-11 18:02:59 +04:00
|
|
|
~description:"Blacklist the given address."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "ban" )
|
|
|
|
|
|
|
|
let trust =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Trust a given address permanently. \
|
|
|
|
Connections from this address can still be closed \
|
2018-03-11 18:02:59 +04:00
|
|
|
on authentication if the peer is blacklisted or greylisted."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "trust" )
|
|
|
|
|
2018-03-11 18:02:59 +04:00
|
|
|
let banned =
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.bool
|
2018-03-11 18:02:59 +04:00
|
|
|
~description:"Check is a given address is blacklisted or \
|
|
|
|
greylisted."
|
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "banned" )
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
open RPC_context
|
|
|
|
let info ctxt peer_id = make_call1 S.info ctxt peer_id () ()
|
|
|
|
let events ctxt point =
|
|
|
|
make_streamed_call S.events ctxt ((), point) () true
|
|
|
|
let list ?(filter = []) ctxt = make_call S.list ctxt () () filter
|
2018-02-22 18:35:50 +04:00
|
|
|
let forget ctxt peer_id = make_call1 S.forget ctxt peer_id () ()
|
|
|
|
let ban ctxt peer_id = make_call1 S.ban ctxt peer_id () ()
|
|
|
|
let trust ctxt peer_id = make_call1 S.trust ctxt peer_id () ()
|
2018-03-11 18:02:59 +04:00
|
|
|
let banned ctxt peer_id = make_call1 S.banned ctxt peer_id () ()
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
end
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
module Peers = struct
|
|
|
|
|
|
|
|
module S = struct
|
|
|
|
|
|
|
|
let info =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
2018-05-22 21:00:20 +04:00
|
|
|
~output: (P2p_peer.Info.encoding Connection_metadata.encoding)
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"Details about a given peer."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg)
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
let events =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: monitor_encoding
|
|
|
|
~output: (Data_encoding.list
|
|
|
|
P2p_peer.Pool_event.encoding)
|
|
|
|
~description:"Monitor network events related to a given peer."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "log")
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
let list =
|
|
|
|
let filter =
|
|
|
|
let open Data_encoding in
|
|
|
|
obj1 (dft "filter" (list P2p_peer.State.encoding) []) in
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: filter
|
|
|
|
~output:
|
|
|
|
Data_encoding.(list (tup2
|
|
|
|
P2p_peer.Id.encoding
|
2018-05-22 21:00:20 +04:00
|
|
|
(P2p_peer.Info.encoding Connection_metadata.encoding)))
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"List the peers the node ever met."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "peers")
|
|
|
|
|
|
|
|
let forget =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Remove the given peer from the whitelist/blacklist."
|
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "forget" )
|
|
|
|
|
|
|
|
let ban =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-03-11 18:02:59 +04:00
|
|
|
~description:"Blacklist the given peer."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "ban" )
|
|
|
|
|
|
|
|
let trust =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-03-11 18:02:59 +04:00
|
|
|
~description:"Trust a given peer permanently: the peer cannot \
|
|
|
|
be blocked (but its host IP still can)."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "trust" )
|
|
|
|
|
2018-03-11 18:02:59 +04:00
|
|
|
let banned =
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.bool
|
2018-03-11 18:02:59 +04:00
|
|
|
~description:"Check if a given peer is blacklisted or \
|
|
|
|
greylisted."
|
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "banned" )
|
2018-02-08 13:51:02 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
let info ctxt peer_id = make_call1 S.info ctxt peer_id () ()
|
|
|
|
let events ctxt point =
|
|
|
|
make_streamed_call S.events ctxt ((), point) () true
|
|
|
|
let list ?(filter = []) ctxt = make_call S.list ctxt () () filter
|
2018-02-22 18:35:50 +04:00
|
|
|
let forget ctxt point_id = make_call1 S.forget ctxt point_id () ()
|
|
|
|
let ban ctxt point_id = make_call1 S.ban ctxt point_id () ()
|
|
|
|
let trust ctxt point_id = make_call1 S.trust ctxt point_id () ()
|
2018-03-11 18:02:59 +04:00
|
|
|
let banned ctxt point_id = make_call1 S.banned ctxt point_id () ()
|
2018-02-22 18:35:50 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-03-11 18:02:59 +04:00
|
|
|
module ACL = struct
|
2018-02-22 18:35:50 +04:00
|
|
|
|
|
|
|
module S = struct
|
|
|
|
|
|
|
|
let clear =
|
|
|
|
RPC_service.post_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~input: Data_encoding.empty
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Clear all greylists tables."
|
|
|
|
RPC_path.(root / "network" / "greylist" / "clear" )
|
|
|
|
end
|
|
|
|
|
|
|
|
let clear ctxt = make_call S.clear ctxt () ()
|
2018-01-22 21:58:43 +04:00
|
|
|
|
|
|
|
end
|