rm non-NBO Bin.t; rename time modules
This commit is contained in:
parent
4f473c003a
commit
d69b49a335
13 changed files with 306 additions and 359 deletions
|
|
@ -45,8 +45,8 @@ type key = {
|
|||
priv: RsaPrivateKey.t;
|
||||
pub: RsaPublicKey.t;
|
||||
h_pub: DenominationHash.t;
|
||||
t1: Absolute.t;
|
||||
t2: Absolute.t;
|
||||
t1: TimeAbsolute.t;
|
||||
t2: TimeAbsolute.t;
|
||||
}
|
||||
|
||||
type t = {
|
||||
|
|
@ -58,7 +58,7 @@ type t = {
|
|||
let parse_filename =
|
||||
let scan_filename s =
|
||||
Scanf.sscanf_opt s "%Lu-%Lu" (fun t1 t2 ->
|
||||
(Absolute.of_s t1, Absolute.of_s t2))
|
||||
(TimeAbsolute.of_s t1, TimeAbsolute.of_s t2))
|
||||
in
|
||||
fun fpath -> scan_filename (Fpath.filename fpath)
|
||||
|
||||
|
|
@ -125,18 +125,18 @@ let gen_key ~section_name t1 t2 =
|
|||
(DenominationHash.to_octets h_pub |> B32.encode));
|
||||
{ section_name; priv; pub; h_pub; t1; t2 }
|
||||
|
||||
let sort_keys l = List.sort (fun a b -> Absolute.compare a.t2 b.t2) l
|
||||
let sort_keys l = List.sort (fun a b -> TimeAbsolute.compare a.t2 b.t2) l
|
||||
|
||||
let split_in_periodes ~start ~end_ ~duration_withdraw =
|
||||
assert (start < end_);
|
||||
(* no overlap on first periode *)
|
||||
let t1 = start in
|
||||
let t2 = Absolute.add start duration_withdraw in
|
||||
let t2 = TimeAbsolute.add start duration_withdraw in
|
||||
let acc = [ (t1, t2) ] in
|
||||
let start = t2 in
|
||||
let rec go acc start end_ =
|
||||
let t1 = Absolute.sub start Cfg.overlap_duration in
|
||||
let t2 = Absolute.add start duration_withdraw in
|
||||
let t1 = TimeAbsolute.sub start Cfg.overlap_duration in
|
||||
let t2 = TimeAbsolute.add start duration_withdraw in
|
||||
if t2 > end_ then acc else go ((t1, t2) :: acc) t2 end_
|
||||
in
|
||||
go acc start end_
|
||||
|
|
@ -147,10 +147,10 @@ let gen_additional_keys_until_lookahead ~now ~section_name l =
|
|||
let start =
|
||||
match List.rev (sort_keys l) with
|
||||
| [] -> now
|
||||
| hd :: _ -> Absolute.sub hd.t2 Cfg.overlap_duration
|
||||
| hd :: _ -> TimeAbsolute.sub hd.t2 Cfg.overlap_duration
|
||||
in
|
||||
let end_ = Absolute.add now Cfg.lookahead_sign in
|
||||
if Absolute.compare start end_ >= 0 then []
|
||||
let end_ = TimeAbsolute.add now Cfg.lookahead_sign in
|
||||
if TimeAbsolute.compare start end_ >= 0 then []
|
||||
else
|
||||
let duration_withdraw = Cfg.duration_withdraw ~section_name in
|
||||
let periodes = split_in_periodes ~start ~end_ ~duration_withdraw in
|
||||
|
|
@ -212,7 +212,7 @@ let init () =
|
|||
let ht = Hashtbl.create 0xff in
|
||||
Ok { sm_key_priv; sm_pub; ht }
|
||||
in
|
||||
let now = Absolute.of_ptime (Ptime_clock.now ()) in
|
||||
let now = TimeAbsolute.of_ptime (Ptime_clock.now ()) in
|
||||
let all_keys = List.of_seq @@ Hashtbl.to_seq_values t.ht in
|
||||
let new_keys_l =
|
||||
List.map
|
||||
|
|
@ -228,13 +228,7 @@ let init () =
|
|||
let+ () = list_iter write_key new_keys in
|
||||
t
|
||||
|
||||
type info = string * rsa_pub * Time.Absolute.t * Time.Absolute.t
|
||||
|
||||
module Make () = struct
|
||||
type pub = RsaPublicKey.t
|
||||
type info = string * RsaPublicKey.t * Time.Absolute.t * Time.Absolute.t
|
||||
|
||||
(* --- *)
|
||||
let t =
|
||||
match init () with
|
||||
| Error e -> Fmt.failwith "secmod_rsa initialization failure: %s." e
|
||||
|
|
@ -251,7 +245,7 @@ module Make () = struct
|
|||
let _delete_outdated ~now =
|
||||
Hashtbl.to_seq t.ht
|
||||
|> List.of_seq
|
||||
|> List.filter (fun (_h_pub, k) -> Absolute.compare now k.t2 >= 0)
|
||||
|> List.filter (fun (_h_pub, k) -> TimeAbsolute.compare now k.t2 >= 0)
|
||||
|> List.map (fun (h_pub, _k) -> h_pub)
|
||||
|> list_iter delete
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue