2018-06-29 16:08:08 +04:00
|
|
|
(*****************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Open Source License *)
|
|
|
|
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
|
|
|
(* copy of this software and associated documentation files (the "Software"),*)
|
|
|
|
(* to deal in the Software without restriction, including without limitation *)
|
|
|
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
|
|
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
|
|
|
(* Software is furnished to do so, subject to the following conditions: *)
|
|
|
|
(* *)
|
|
|
|
(* The above copyright notice and this permission notice shall be included *)
|
|
|
|
(* in all copies or substantial portions of the Software. *)
|
|
|
|
(* *)
|
|
|
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
|
|
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
|
|
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
|
|
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
|
|
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
|
|
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
|
|
|
(* DEALINGS IN THE SOFTWARE. *)
|
|
|
|
(* *)
|
|
|
|
(*****************************************************************************)
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-04-21 14:46:33 +04:00
|
|
|
let wait_query =
|
|
|
|
let open RPC_query in
|
|
|
|
query (fun wait -> object
|
|
|
|
method wait = wait
|
|
|
|
end)
|
|
|
|
|+ flag "wait" (fun t -> t#wait)
|
|
|
|
|> seal
|
|
|
|
|
|
|
|
let monitor_query =
|
|
|
|
let open RPC_query in
|
|
|
|
query (fun monitor -> object
|
|
|
|
method monitor = monitor
|
|
|
|
end)
|
|
|
|
|+ flag "monitor" (fun t -> t#monitor)
|
|
|
|
|> seal
|
|
|
|
|
|
|
|
let timeout_query =
|
|
|
|
let open RPC_query in
|
|
|
|
query (fun timeout -> object
|
|
|
|
method timeout = timeout
|
|
|
|
end)
|
|
|
|
|+ field "timeout" RPC_arg.float 10. (fun t -> t#timeout)
|
|
|
|
|> seal
|
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
module S = struct
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-08-08 16:10:47 +04:00
|
|
|
let self =
|
2018-06-13 18:03:19 +04:00
|
|
|
RPC_service.get_service
|
2018-08-08 16:10:47 +04:00
|
|
|
~description:"Return the node's peer id"
|
2018-06-13 18:03:19 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: P2p_peer.Id.encoding
|
2018-08-08 16:10:47 +04:00
|
|
|
RPC_path.(root / "network" / "self")
|
2018-06-13 18:03:19 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
let versions =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"Supported network layer versions."
|
|
|
|
~query: RPC_query.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-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_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
|
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-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_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
|
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-04-21 14:46:33 +04:00
|
|
|
RPC_service.put_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"Connect to a peer"
|
2018-04-21 14:46:33 +04:00
|
|
|
~query: timeout_query
|
|
|
|
~input: Data_encoding.empty
|
2018-02-11 22:17:39 +04:00
|
|
|
~output: Data_encoding.empty
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_path.(root / "network" / "points" /: 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
|
2018-08-08 16:10:47 +04:00
|
|
|
let self ctxt = make_call S.self ctxt () () ()
|
2018-02-08 13:51:02 +04:00
|
|
|
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-04-21 14:46:33 +04:00
|
|
|
make_call1 S.connect ctxt peer_id (object method timeout = timeout end) ()
|
2018-01-22 21:58:43 +04:00
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
module Connections = struct
|
|
|
|
|
2018-06-05 03:45:43 +04:00
|
|
|
type connection_info = Connection_metadata.t P2p_connection.Info.t
|
|
|
|
|
|
|
|
let connection_info_encoding =
|
|
|
|
P2p_connection.Info.encoding Connection_metadata.encoding
|
|
|
|
|
2018-02-08 13:51:02 +04:00
|
|
|
module S = struct
|
|
|
|
|
|
|
|
let list =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~description:"List the running P2P connection."
|
|
|
|
~query: RPC_query.empty
|
2018-06-05 03:45:43 +04:00
|
|
|
~output: (Data_encoding.list 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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~query: RPC_query.empty
|
2018-06-05 03:45:43 +04:00
|
|
|
~output: connection_info_encoding
|
2018-02-08 13:51:02 +04:00
|
|
|
~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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.delete_service
|
|
|
|
~query: wait_query
|
2018-02-08 13:51:02 +04:00
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Forced close of the current P2P connection to the given peer."
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_path.(root / "network" / "connections" /: P2p_peer.Id.rpc_arg)
|
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 () ()
|
2018-04-21 14:46:33 +04:00
|
|
|
let kick ctxt ?(wait = false) peer_id =
|
|
|
|
make_call1 S.kick ctxt peer_id (object method wait = wait end) ()
|
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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~query: RPC_query.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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
|
|
|
~query: monitor_query
|
2018-02-08 13:51:02 +04:00
|
|
|
~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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
let filter_query =
|
|
|
|
let open RPC_query in
|
|
|
|
query (fun filters -> object
|
|
|
|
method filters = filters
|
|
|
|
end)
|
|
|
|
|+ multi_field "filter" P2p_point.Filter.rpc_arg (fun t -> t#filters)
|
|
|
|
|> seal in
|
|
|
|
RPC_service.get_service
|
|
|
|
~query: filter_query
|
2018-02-08 13:51:02 +04:00
|
|
|
~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")
|
|
|
|
|
2018-10-10 16:21:27 +04:00
|
|
|
let ban =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-10-10 16:21:27 +04:00
|
|
|
~description:"Blacklist the given address and remove it from the \
|
|
|
|
whitelist if present."
|
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "ban" )
|
2018-02-22 18:35:50 +04:00
|
|
|
|
2018-10-10 16:21:27 +04:00
|
|
|
let unban =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-10-10 16:21:27 +04:00
|
|
|
~description:"Remove an address from the blacklist."
|
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "unban" )
|
2018-02-22 18:35:50 +04:00
|
|
|
|
|
|
|
let trust =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-10-10 16:21:27 +04:00
|
|
|
~description:"Trust a given address permanently and remove it \
|
|
|
|
from the blacklist if present. Connections from \
|
|
|
|
this address can still be closed on \
|
|
|
|
authentication if the peer is greylisted."
|
2018-02-22 18:35:50 +04:00
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "trust" )
|
|
|
|
|
2018-10-10 16:21:27 +04:00
|
|
|
let untrust =
|
|
|
|
RPC_service.get_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Remove an address from the whitelist."
|
|
|
|
RPC_path.(root / "network" / "points" /: P2p_point.Id.rpc_arg / "untrust" )
|
|
|
|
|
2018-03-11 18:02:59 +04:00
|
|
|
let banned =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
make_streamed_call S.events ctxt ((), point)
|
|
|
|
(object method monitor = true end) ()
|
|
|
|
let list ?(filter = []) ctxt = make_call S.list ctxt ()
|
|
|
|
(object method filters = filter end) ()
|
2018-02-22 18:35:50 +04:00
|
|
|
let ban ctxt peer_id = make_call1 S.ban ctxt peer_id () ()
|
2018-10-10 16:21:27 +04:00
|
|
|
let unban ctxt peer_id = make_call1 S.unban ctxt peer_id () ()
|
2018-02-22 18:35:50 +04:00
|
|
|
let trust ctxt peer_id = make_call1 S.trust ctxt peer_id () ()
|
2018-10-10 16:21:27 +04:00
|
|
|
let untrust ctxt peer_id = make_call1 S.untrust 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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-08 13:51:02 +04:00
|
|
|
~query: RPC_query.empty
|
2018-07-25 20:00:22 +04:00
|
|
|
~output: (P2p_peer.Info.encoding Peer_metadata.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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
|
|
|
~query: monitor_query
|
2018-02-08 13:51:02 +04:00
|
|
|
~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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
let open RPC_query in
|
|
|
|
query (fun filters -> object
|
|
|
|
method filters = filters
|
|
|
|
end)
|
|
|
|
|+ multi_field "filter" P2p_peer.Filter.rpc_arg (fun t -> t#filters)
|
|
|
|
|> seal in
|
|
|
|
RPC_service.get_service
|
|
|
|
~query: filter
|
2018-02-08 13:51:02 +04:00
|
|
|
~output:
|
|
|
|
Data_encoding.(list (tup2
|
|
|
|
P2p_peer.Id.encoding
|
2018-07-25 20:00:22 +04:00
|
|
|
(P2p_peer.Info.encoding Peer_metadata.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")
|
|
|
|
|
2018-10-10 16:21:27 +04:00
|
|
|
let ban =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-10-10 16:21:27 +04:00
|
|
|
~description:"Blacklist the given peer and remove it from the \
|
|
|
|
whitelist if present."
|
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "ban" )
|
2018-02-22 18:35:50 +04:00
|
|
|
|
2018-10-10 16:21:27 +04:00
|
|
|
let unban =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-10-10 16:21:27 +04:00
|
|
|
~description:"Remove the given peer from the blacklist."
|
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "unban" )
|
2018-02-22 18:35:50 +04:00
|
|
|
|
|
|
|
let trust =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
2018-10-10 16:21:27 +04:00
|
|
|
~description:"Whitelist a given peer permanently and remove it \
|
|
|
|
from the blacklist if present. The peer cannot \
|
2018-03-11 18:02:59 +04:00
|
|
|
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-10-10 16:21:27 +04:00
|
|
|
let untrust =
|
|
|
|
RPC_service.get_service
|
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Remove a given peer from the whitelist."
|
|
|
|
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg / "untrust" )
|
|
|
|
|
2018-03-11 18:02:59 +04:00
|
|
|
let banned =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
make_streamed_call S.events ctxt ((), point)
|
|
|
|
(object method monitor = true end) ()
|
|
|
|
let list ?(filter = []) ctxt =
|
|
|
|
make_call S.list ctxt () (object method filters = filter end) ()
|
2018-02-22 18:35:50 +04:00
|
|
|
let ban ctxt point_id = make_call1 S.ban ctxt point_id () ()
|
2018-10-10 16:21:27 +04:00
|
|
|
let unban ctxt point_id = make_call1 S.unban ctxt point_id () ()
|
2018-02-22 18:35:50 +04:00
|
|
|
let trust ctxt point_id = make_call1 S.trust ctxt point_id () ()
|
2018-10-10 16:21:27 +04:00
|
|
|
let untrust ctxt point_id = make_call1 S.untrust 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 =
|
2018-04-21 14:46:33 +04:00
|
|
|
RPC_service.get_service
|
2018-02-22 18:35:50 +04:00
|
|
|
~query: RPC_query.empty
|
|
|
|
~output: Data_encoding.empty
|
|
|
|
~description:"Clear all greylists tables."
|
|
|
|
RPC_path.(root / "network" / "greylist" / "clear" )
|
2018-04-21 14:46:33 +04:00
|
|
|
|
2018-02-22 18:35:50 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
let clear ctxt = make_call S.clear ctxt () ()
|
2018-01-22 21:58:43 +04:00
|
|
|
|
|
|
|
end
|