objective categorical abstract machine language personal data server
65
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix TID monotonicity

futurGH 04c19333 fa456b0c

+48 -19
+19 -2
dune-project
··· 21 21 (name mist) 22 22 (synopsis "Atproto repo functionality") 23 23 (allow_empty) 24 - (depends ocaml dune (cborl (>= 0.1.0)) (cid (>= 0.1.0)) (hacl-star (>= 0.7.2)) lwt (mtime (>= 2.1.0)) (multihash (>= 0.1.0)) (re (>= 1.13.2)) (yojson (>= 3.0.0)) (alcotest :with-test))) 24 + (depends 25 + ocaml 26 + dune 27 + (core_unix (>= 0.17.1)) 28 + (cborl (>= 0.1.0)) 29 + (cid (>= 0.1.0)) 30 + (hacl-star (>= 0.7.2)) 31 + lwt 32 + (mtime (>= 2.1.0)) 33 + (multihash (>= 0.1.0)) 34 + (re (>= 1.13.2)) 35 + (yojson (>= 3.0.0)) 36 + (alcotest :with-test))) 25 37 26 38 (package 27 39 (name ipld) 28 40 (synopsis "A DASL-compliant implementation of some IPLD formats") 29 41 (description "Currently includes DAG-CBOR and CIDv1") 30 42 (allow_empty) 31 - (depends ocaml dune (digestif (>= 1.2.0)) (multibase (>= 0.1.0)) (alcotest :with-test))) 43 + (depends 44 + ocaml 45 + dune 46 + (digestif (>= 1.2.0)) 47 + (multibase (>= 0.1.0)) 48 + (alcotest :with-test)))
+1
mist.opam
··· 9 9 depends: [ 10 10 "ocaml" 11 11 "dune" {>= "3.14"} 12 + "core_unix" {>= "0.17.1"} 12 13 "cborl" {>= "0.1.0"} 13 14 "cid" {>= "0.1.0"} 14 15 "hacl-star" {>= "0.7.2"}
+2
mist/lib/dune
··· 1 1 (library 2 2 (name mist) 3 3 (libraries 4 + core_unix.time_stamp_counter 5 + core_unix.time_ns_unix 4 6 digestif 5 7 hacl-star 6 8 ipld
+26 -17
mist/lib/tid.ml
··· 20 20 else if not (Re.execp tid_regexp tid) then 21 21 raise (Invalid_argument (Format.sprintf "invalid tid format: %s" tid)) 22 22 23 - let _encode (n : int64) : t = 24 - let rec _encode ~tid n = 23 + let s32_encode (n : int64) : t = 24 + let rec s32_encode ~tid n = 25 25 match n with 26 26 | 0L -> 27 27 tid 28 28 | n -> 29 - _encode 29 + s32_encode 30 30 ~tid:(String.make 1 charset.[Int64.to_int (Int64.rem n 32L)] ^ tid) 31 31 (Int64.unsigned_div n 32L) 32 32 in 33 - _encode ~tid:"" n 33 + s32_encode ~tid:"" n 34 34 35 - let _decode (s : t) : int64 = 36 - let rec _decode ~(n : int64) (s : string) = 35 + let s32_decode (s : t) : int64 = 36 + let rec s32_decode ~(n : int64) (s : string) = 37 37 match s with 38 38 | s when String.length s > 0 -> 39 39 let c = s.[0] in 40 40 let cs = String.sub s 1 (String.length s - 1) in 41 - _decode 41 + s32_decode 42 42 ~n: 43 43 (Int64.add (Int64.mul n 32L) 44 44 (Int64.of_int (String.index charset c)) ) ··· 46 46 | _ -> 47 47 n 48 48 in 49 - _decode ~n:0L s 49 + s32_decode ~n:0L s 50 50 51 - let of_timestamp_us (timestamp : int64) ~(clockid : int) : t = 51 + let of_timestamp_us ?(clockid = Random.int_in_range ~min:0 ~max:1023) 52 + (timestamp : int64) : t = 52 53 if timestamp < 0L || timestamp >= Int64.shift_left 1L 53 then 53 54 raise (Invalid_argument "timestamp must be within range [0, 2^53)") ; 54 55 if clockid < 0 || clockid > 1023 then ··· 56 57 let rec pad str len = 57 58 if String.length str >= len then str else pad ("2" ^ str) len 58 59 in 59 - pad (_encode timestamp) 11 ^ pad (_encode @@ Int64.of_int clockid) 2 60 + pad (s32_encode timestamp) 11 ^ pad (s32_encode @@ Int64.of_int clockid) 2 60 61 61 - let of_timestamp_ms (timestamp : int64) ~(clockid : int) : t = 62 - of_timestamp_us (Int64.mul timestamp 1000L) ~clockid 62 + let of_timestamp_ms ?(clockid = Random.int_in_range ~min:0 ~max:1023) 63 + (timestamp : int64) : t = 64 + of_timestamp_us 65 + (Int64.add (Int64.mul timestamp 1000L) (Random.int64 1000L)) 66 + ~clockid 63 67 64 68 let to_timestamp_us (tid : t) : int64 * int = 65 69 ensure_valid tid ; 66 - let timestamp = _decode (String.sub tid 0 11) in 67 - let clockid = Int64.to_int @@ _decode (String.sub tid 11 2) in 70 + let timestamp = s32_decode (String.sub tid 0 11) in 71 + let clockid = Int64.to_int @@ s32_decode (String.sub tid 11 2) in 68 72 (timestamp, clockid) 69 73 70 74 let to_timestamp_ms (tid : t) : int64 * int = 71 75 ensure_valid tid ; 72 - let timestamp = _decode (String.sub tid 0 11) in 73 - let clockid = Int64.to_int @@ _decode (String.sub tid 11 2) in 76 + let timestamp = s32_decode (String.sub tid 0 11) in 77 + let clockid = Int64.to_int @@ s32_decode (String.sub tid 11 2) in 74 78 (Int64.div timestamp 1000L, clockid) 75 79 76 80 let now () : t = 77 - Mtime_clock.now_ns () |> Int64.unsigned_div 1_000L 81 + let calibrator = Lazy.force Time_stamp_counter.calibrator in 82 + Time_stamp_counter.Calibrator.calibrate calibrator ; 83 + Time_stamp_counter.now () 84 + |> Time_stamp_counter.to_time ~calibrator 85 + |> Time_float_unix.to_span_since_epoch |> Time_float_unix.Span.to_us 86 + |> Int64.of_float 78 87 |> of_timestamp_us ~clockid:(Random.int_in_range ~min:0 ~max:1023) 79 88 80 89 let of_string (s : string) : t = ensure_valid s ; s