Shell: export P2p.gid
This commit is contained in:
parent
41d5bbe989
commit
dc2084d993
@ -63,6 +63,8 @@ let gid_length = 16
|
|||||||
let pp_gid ppf gid =
|
let pp_gid ppf gid =
|
||||||
Format.pp_print_string ppf (Hex_encode.hex_encode gid)
|
Format.pp_print_string ppf (Hex_encode.hex_encode gid)
|
||||||
|
|
||||||
|
let zero_gid = String.make 16 '\x00'
|
||||||
|
|
||||||
(* the common version for a pair of peers, if any, is the maximum one,
|
(* the common version for a pair of peers, if any, is the maximum one,
|
||||||
in lexicographic order *)
|
in lexicographic order *)
|
||||||
let common_version la lb =
|
let common_version la lb =
|
||||||
@ -280,6 +282,7 @@ module Make (P: PARAMS) = struct
|
|||||||
outside world. Hidden Lwt workers are associated to a net at its
|
outside world. Hidden Lwt workers are associated to a net at its
|
||||||
creation and can be killed using the shutdown callback. *)
|
creation and can be killed using the shutdown callback. *)
|
||||||
type net = {
|
type net = {
|
||||||
|
gid : gid ;
|
||||||
recv_from : unit -> (peer * P.msg) Lwt.t ;
|
recv_from : unit -> (peer * P.msg) Lwt.t ;
|
||||||
send_to : peer -> P.msg -> unit Lwt.t ;
|
send_to : peer -> P.msg -> unit Lwt.t ;
|
||||||
try_send_to : peer -> P.msg -> bool ;
|
try_send_to : peer -> P.msg -> bool ;
|
||||||
@ -1317,7 +1320,7 @@ module Make (P: PARAMS) = struct
|
|||||||
and set_metadata _gid _meta = () (* TODO: implement *)
|
and set_metadata _gid _meta = () (* TODO: implement *)
|
||||||
in
|
in
|
||||||
let net =
|
let net =
|
||||||
{ shutdown ; peers ; find_peer ;
|
{ gid = my_gid ; shutdown ; peers ; find_peer ;
|
||||||
recv_from ; send_to ; try_send_to ; broadcast ;
|
recv_from ; send_to ; try_send_to ; broadcast ;
|
||||||
blacklist ; whitelist ; maintain ; roll ;
|
blacklist ; whitelist ; maintain ; roll ;
|
||||||
peer_info ; get_metadata ; set_metadata } in
|
peer_info ; get_metadata ; set_metadata } in
|
||||||
@ -1327,6 +1330,7 @@ module Make (P: PARAMS) = struct
|
|||||||
Lwt.return net
|
Lwt.return net
|
||||||
|
|
||||||
let faked_network =
|
let faked_network =
|
||||||
|
let gid = String.make 16 '\000' in
|
||||||
let infinity, wakeup = Lwt.wait () in
|
let infinity, wakeup = Lwt.wait () in
|
||||||
let shutdown () =
|
let shutdown () =
|
||||||
Lwt.wakeup_exn wakeup Lwt_stream.Empty;
|
Lwt.wakeup_exn wakeup Lwt_stream.Empty;
|
||||||
@ -1344,13 +1348,14 @@ module Make (P: PARAMS) = struct
|
|||||||
let peer_info _ = assert false in
|
let peer_info _ = assert false in
|
||||||
let get_metadata _ = None in
|
let get_metadata _ = None in
|
||||||
let set_metadata _ _ = () in
|
let set_metadata _ _ = () in
|
||||||
{ shutdown ; peers ; find_peer ;
|
{ gid ; shutdown ; peers ; find_peer ;
|
||||||
recv_from ; send_to ; try_send_to ; broadcast ;
|
recv_from ; send_to ; try_send_to ; broadcast ;
|
||||||
blacklist ; whitelist ; maintain ; roll ;
|
blacklist ; whitelist ; maintain ; roll ;
|
||||||
peer_info ; get_metadata ; set_metadata }
|
peer_info ; get_metadata ; set_metadata }
|
||||||
|
|
||||||
|
|
||||||
(* Plug toplevel functions to callback calls. *)
|
(* Plug toplevel functions to callback calls. *)
|
||||||
|
let gid net = net.gid
|
||||||
let shutdown net = net.shutdown ()
|
let shutdown net = net.shutdown ()
|
||||||
let peers net = net.peers ()
|
let peers net = net.peers ()
|
||||||
let find_peer net gid = net.find_peer gid
|
let find_peer net gid = net.find_peer gid
|
||||||
|
@ -55,6 +55,7 @@ type limits = {
|
|||||||
|
|
||||||
(** A global identifier for a peer, a.k.a. an identity *)
|
(** A global identifier for a peer, a.k.a. an identity *)
|
||||||
type gid
|
type gid
|
||||||
|
val pp_gid : Format.formatter -> gid -> unit
|
||||||
|
|
||||||
type 'msg encoding = Encoding : {
|
type 'msg encoding = Encoding : {
|
||||||
tag: int ;
|
tag: int ;
|
||||||
@ -97,6 +98,9 @@ module Make (P : PARAMS) : sig
|
|||||||
(** Main network initialisation function *)
|
(** Main network initialisation function *)
|
||||||
val bootstrap : config:config -> limits:limits -> net Lwt.t
|
val bootstrap : config:config -> limits:limits -> net Lwt.t
|
||||||
|
|
||||||
|
(** Return one's gid *)
|
||||||
|
val gid : net -> gid
|
||||||
|
|
||||||
(** A maintenance operation : try and reach the ideal number of peers *)
|
(** A maintenance operation : try and reach the ideal number of peers *)
|
||||||
val maintain : net -> unit Lwt.t
|
val maintain : net -> unit Lwt.t
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user