P2p, client: fix network protocol version negociation
This commit is contained in:
parent
bde9ba771b
commit
7051325ba4
@ -97,7 +97,7 @@ let check_network ctxt =
|
||||
default () ;
|
||||
Lwt.return_none
|
||||
| Ok versions ->
|
||||
match String.split_on_char '_' (List.hd versions).name with
|
||||
match String.split_on_char '_' (P2p_version.best versions).name with
|
||||
| "SANDBOXED" :: _ ->
|
||||
sandbox () ;
|
||||
Lwt.return_some `Sandbox
|
||||
|
@ -42,8 +42,6 @@ let encoding =
|
||||
(req "major" uint16)
|
||||
(req "minor" uint16))
|
||||
|
||||
(* the common version for a pair of peers, if any, is the maximum one,
|
||||
in lexicographic order *)
|
||||
let common la lb =
|
||||
let la = List.sort (fun l r -> compare r l) la in
|
||||
let lb = List.sort (fun l r -> compare r l) lb in
|
||||
@ -51,6 +49,12 @@ let common la lb =
|
||||
| [], _ | _, [] -> None
|
||||
| ((a :: ta) as la), ((b :: tb) as lb) ->
|
||||
if a = b then Some a
|
||||
else if a < b then find (ta, lb)
|
||||
else if a > b then find (ta, lb)
|
||||
else find (la, tb)
|
||||
in find (la, lb)
|
||||
|
||||
let best lv =
|
||||
if lv = [] then
|
||||
invalid_arg "P2p_version.best"
|
||||
else
|
||||
List.hd (List.sort (fun l r -> compare r l) lv)
|
||||
|
@ -23,16 +23,24 @@
|
||||
(* *)
|
||||
(*****************************************************************************)
|
||||
|
||||
(** Protocol version *)
|
||||
(** Network protocol version. *)
|
||||
|
||||
(** Type of a network protocol version. *)
|
||||
type t = {
|
||||
name : string ;
|
||||
major : int ;
|
||||
minor : int ;
|
||||
}
|
||||
(** Type of a protocol version. *)
|
||||
|
||||
val pp : Format.formatter -> t -> unit
|
||||
val encoding : t Data_encoding.t
|
||||
|
||||
(** Selects the prefered common version for a pair of version
|
||||
lists. Used during network protocol negociation. If any, it is the
|
||||
maximum one, in lexicographic order (name, then major, minor). *)
|
||||
val common : t list -> t list -> t option
|
||||
|
||||
(** Gives the prefered version in a list: the one selected by
|
||||
{!common} among the list of compatible ones. *)
|
||||
val best : t list -> t
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user