P2P: allow to limit the size of protocols
This commit is contained in:
parent
99f6e40471
commit
fed04d4b8f
@ -53,6 +53,11 @@ let encoding =
|
||||
(req "expected_env_version" env_version_encoding)
|
||||
(req "components" (list component_encoding)))
|
||||
|
||||
let bounded_encoding ?max_size () =
|
||||
match max_size with
|
||||
| None -> encoding
|
||||
| Some max_size -> Data_encoding.check_size max_size encoding
|
||||
|
||||
let pp ppf op =
|
||||
Data_encoding.Json.pp ppf
|
||||
(Data_encoding.Json.construct encoding op)
|
||||
|
@ -29,6 +29,8 @@ include S.HASHABLE with type t := t
|
||||
and type hash := Protocol_hash.t
|
||||
val of_bytes_exn: MBytes.t -> t
|
||||
|
||||
val bounded_encoding: ?max_size:int -> unit -> t Data_encoding.t
|
||||
|
||||
module Meta: sig
|
||||
|
||||
type t = {
|
||||
|
@ -83,6 +83,16 @@ module Bounded_encoding = struct
|
||||
let operation_list = delayed (fun () -> !operation_list_cache)
|
||||
let operation_hash_list = delayed (fun () -> !operation_hash_list_cache)
|
||||
|
||||
let protocol_max_size = ref None
|
||||
let protocol_cache =
|
||||
ref (Protocol.bounded_encoding ?max_size:!protocol_max_size ())
|
||||
let update_protocol_encoding () =
|
||||
protocol_cache :=
|
||||
Protocol.bounded_encoding ?max_size:!protocol_max_size ()
|
||||
let set_protocol_max_size max =
|
||||
protocol_max_size := max
|
||||
let protocol = delayed (fun () -> !protocol_cache)
|
||||
|
||||
end
|
||||
|
||||
type t =
|
||||
@ -207,7 +217,7 @@ let encoding =
|
||||
|
||||
case ~tag:0x41
|
||||
~title:"Protocol"
|
||||
(obj1 (req "protocol" Protocol.encoding))
|
||||
(obj1 (req "protocol" Bounded_encoding.protocol))
|
||||
(function Protocol proto -> Some proto | _ -> None)
|
||||
(fun proto -> Protocol proto);
|
||||
|
||||
|
@ -47,4 +47,5 @@ module Bounded_encoding : sig
|
||||
val set_operation_list_max_size: int option -> unit
|
||||
val set_operation_list_max_length: int option -> unit
|
||||
val set_operation_max_pass: int option -> unit
|
||||
val set_protocol_max_size: int option -> unit
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user