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

View File

@ -27,9 +27,10 @@ end
module Info : sig
type t = {
type 'conn_meta t = {
score : float ;
trusted : bool ;
conn_metadata : 'conn_meta option ;
state : State.t ;
id_point : P2p_connection.Id.t option ;
stat : P2p_stat.t ;
@ -41,7 +42,7 @@ module Info : sig
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

View File

@ -515,13 +515,19 @@ let info_of_peer_info pool i =
| Disconnected -> Disconnected, None in
let peer_id = P2p_peer_state.Info.peer_id i 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 =
match P2p_pool.Connection.find_by_peer_id pool peer_id with
match conn_opt with
| None -> P2p_stat.empty
| 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.{
score ;
trusted = trusted i ;
conn_metadata = meta_opt ;
state ;
id_point ;
stat ;

View File

@ -251,7 +251,8 @@ val on_new_connection :
('msg, 'peer_meta, 'conn_meta) net ->
(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_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 ;
} in
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) ->
let conn_metadata_cfg =
connection_metadata_cfg {

View File

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

View File

@ -141,9 +141,11 @@ module Peers : sig
val list:
?filter:(P2p_peer.State.t list) ->
#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:
#streamed -> P2p_peer.Id.t ->
@ -162,12 +164,12 @@ module Peers : sig
val list :
([ `POST ], unit,
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 :
([ `POST ], 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 :
([ `POST ], unit,