RPC: Add conn_metadata to peer_info rpcs

This commit is contained in:
michael 2018-05-22 19:00:20 +02:00 committed by Grégoire Henry
parent df4e474577
commit aedf867e4a
7 changed files with 31 additions and 18 deletions

View File

@ -37,9 +37,10 @@ end
module Info = struct module Info = struct
type t = { type 'conn_meta t = {
score : float ; score : float ;
trusted : bool ; trusted : bool ;
conn_metadata : 'conn_meta option;
state : State.t ; state : State.t ;
id_point : P2p_connection.Id.t option ; id_point : P2p_connection.Id.t option ;
stat : P2p_stat.t ; stat : P2p_stat.t ;
@ -51,30 +52,31 @@ module Info = struct
last_miss : (P2p_connection.Id.t * Time.t) option ; last_miss : (P2p_connection.Id.t * Time.t) option ;
} }
let encoding = let encoding conn_metadata_encoding =
let open Data_encoding in let open Data_encoding in
conv conv
(fun ( (fun (
{ score ; trusted ; state ; id_point ; stat ; { score ; trusted ; conn_metadata ; state ; id_point ; stat ;
last_failed_connection ; last_rejected_connection ; last_failed_connection ; last_rejected_connection ;
last_established_connection ; last_disconnection ; last_established_connection ; last_disconnection ;
last_seen ; last_miss }) -> last_seen ; last_miss }) ->
((score, trusted, state, id_point, stat), ((score, trusted, conn_metadata, state, id_point, stat),
(last_failed_connection, last_rejected_connection, (last_failed_connection, last_rejected_connection,
last_established_connection, last_disconnection, last_established_connection, last_disconnection,
last_seen, last_miss))) last_seen, last_miss)))
(fun ((score, trusted, state, id_point, stat), (fun ((score, trusted, conn_metadata, state, id_point, stat),
(last_failed_connection, last_rejected_connection, (last_failed_connection, last_rejected_connection,
last_established_connection, last_disconnection, last_established_connection, last_disconnection,
last_seen, last_miss)) -> last_seen, last_miss)) ->
{ score ; trusted ; state ; id_point ; stat ; { score ; trusted ; conn_metadata ; state ; id_point ; stat ;
last_failed_connection ; last_rejected_connection ; last_failed_connection ; last_rejected_connection ;
last_established_connection ; last_disconnection ; last_established_connection ; last_disconnection ;
last_seen ; last_miss }) last_seen ; last_miss })
(merge_objs (merge_objs
(obj5 (obj6
(req "score" float) (req "score" float)
(req "trusted" bool) (req "trusted" bool)
(opt "conn_metadata" conn_metadata_encoding)
(req "state" State.encoding) (req "state" State.encoding)
(opt "reachable_at" P2p_connection.Id.encoding) (opt "reachable_at" P2p_connection.Id.encoding)
(req "stat" P2p_stat.encoding)) (req "stat" P2p_stat.encoding))

View File

@ -27,9 +27,10 @@ end
module Info : sig module Info : sig
type t = { type 'conn_meta t = {
score : float ; score : float ;
trusted : bool ; trusted : bool ;
conn_metadata : 'conn_meta option ;
state : State.t ; state : State.t ;
id_point : P2p_connection.Id.t option ; id_point : P2p_connection.Id.t option ;
stat : P2p_stat.t ; stat : P2p_stat.t ;
@ -41,7 +42,7 @@ module Info : sig
last_miss : (P2p_connection.Id.t * Time.t) option ; last_miss : (P2p_connection.Id.t * Time.t) option ;
} }
val encoding : t Data_encoding.t val encoding : 'conn_meta Data_encoding.t -> 'conn_meta t Data_encoding.t
end end

View File

@ -515,13 +515,19 @@ let info_of_peer_info pool i =
| Disconnected -> Disconnected, None in | Disconnected -> Disconnected, None in
let peer_id = P2p_peer_state.Info.peer_id i in let peer_id = P2p_peer_state.Info.peer_id i in
let score = P2p_pool.Peers.get_score pool peer_id in let score = P2p_pool.Peers.get_score pool peer_id in
let conn_opt = P2p_pool.Connection.find_by_peer_id pool peer_id in
let stat = let stat =
match P2p_pool.Connection.find_by_peer_id pool peer_id with match conn_opt with
| None -> P2p_stat.empty | None -> P2p_stat.empty
| Some conn -> P2p_pool.Connection.stat conn in | Some conn -> P2p_pool.Connection.stat conn in
let meta_opt =
match conn_opt with
| None -> None
| Some conn -> Some (P2p_pool.Connection.meta conn) in
P2p_peer_state.Info.{ P2p_peer_state.Info.{
score ; score ;
trusted = trusted i ; trusted = trusted i ;
conn_metadata = meta_opt ;
state ; state ;
id_point ; id_point ;
stat ; stat ;

View File

@ -251,7 +251,8 @@ val on_new_connection :
('msg, 'peer_meta, 'conn_meta) net -> ('msg, 'peer_meta, 'conn_meta) net ->
(P2p_peer.Id.t -> ('msg, 'peer_meta, 'conn_meta) connection -> unit) -> unit (P2p_peer.Id.t -> ('msg, 'peer_meta, 'conn_meta) connection -> unit) -> unit
val build_rpc_directory : _ t -> unit RPC_directory.t val build_rpc_directory :
(_, _, Connection_metadata.t) t -> unit RPC_directory.t
val greylist_addr : ('msg, 'peer_meta, 'conn_meta) net -> P2p_addr.t -> unit val greylist_addr : ('msg, 'peer_meta, 'conn_meta) net -> P2p_addr.t -> unit
val greylist_peer : ('msg, 'peer_meta, 'conn_meta) net -> P2p_peer.Id.t -> unit val greylist_peer : ('msg, 'peer_meta, 'conn_meta) net -> P2p_peer.Id.t -> unit

View File

@ -86,7 +86,8 @@ let init_p2p p2p_params =
private_node = false ; private_node = false ;
} in } in
lwt_log_notice "P2P layer is disabled" >>= fun () -> lwt_log_notice "P2P layer is disabled" >>= fun () ->
return (P2p.faked_network peer_metadata_cfg, conn_metadata_cfg) return
(P2p.faked_network peer_metadata_cfg, conn_metadata_cfg)
| Some (config, limits) -> | Some (config, limits) ->
let conn_metadata_cfg = let conn_metadata_cfg =
connection_metadata_cfg { connection_metadata_cfg {

View File

@ -181,7 +181,7 @@ module Peers = struct
RPC_service.post_service RPC_service.post_service
~query: RPC_query.empty ~query: RPC_query.empty
~input: Data_encoding.empty ~input: Data_encoding.empty
~output: P2p_peer.Info.encoding ~output: (P2p_peer.Info.encoding Connection_metadata.encoding)
~description:"Details about a given peer." ~description:"Details about a given peer."
RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg) RPC_path.(root / "network" / "peers" /: P2p_peer.Id.rpc_arg)
@ -204,7 +204,7 @@ module Peers = struct
~output: ~output:
Data_encoding.(list (tup2 Data_encoding.(list (tup2
P2p_peer.Id.encoding P2p_peer.Id.encoding
P2p_peer.Info.encoding)) (P2p_peer.Info.encoding Connection_metadata.encoding)))
~description:"List the peers the node ever met." ~description:"List the peers the node ever met."
RPC_path.(root / "network" / "peers") RPC_path.(root / "network" / "peers")

View File

@ -141,9 +141,11 @@ module Peers : sig
val list: val list:
?filter:(P2p_peer.State.t list) -> ?filter:(P2p_peer.State.t list) ->
#simple -> #simple ->
(P2p_peer.Id.t * P2p_peer.Info.t) list tzresult Lwt.t (P2p_peer.Id.t * Connection_metadata.t P2p_peer.Info.t) list tzresult Lwt.t
val info: #simple -> P2p_peer.Id.t -> P2p_peer.Info.t tzresult Lwt.t val info:
#simple -> P2p_peer.Id.t ->
Connection_metadata.t P2p_peer.Info.t tzresult Lwt.t
val events: val events:
#streamed -> P2p_peer.Id.t -> #streamed -> P2p_peer.Id.t ->
@ -162,12 +164,12 @@ module Peers : sig
val list : val list :
([ `POST ], unit, ([ `POST ], unit,
unit, unit, P2p_peer.State.t list, unit, unit, P2p_peer.State.t list,
(P2p_peer.Id.t * P2p_peer.Info.t) list) RPC_service.t (P2p_peer.Id.t * Connection_metadata.t P2p_peer.Info.t) list) RPC_service.t
val info : val info :
([ `POST ], unit, ([ `POST ], unit,
unit * P2p_peer.Id.t, unit, unit, unit * P2p_peer.Id.t, unit, unit,
P2p_peer.Info.t) RPC_service.t Connection_metadata.t P2p_peer.Info.t) RPC_service.t
val events : val events :
([ `POST ], unit, ([ `POST ], unit,