Skip to content

Commit

Permalink
random: use the right rng device by default
Browse files Browse the repository at this point in the history
When users provide mclock and time, build a default random generator
using these.
  • Loading branch information
samoht committed Jun 9, 2020
1 parent 5e0dd51 commit 4a301c7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions lib/mirage/mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ val tcpv4 : tcpv4 typ
val tcpv6 : tcpv6 typ

val direct_tcp :
?clock:mclock impl ->
?random:random impl ->
?mclock:mclock impl ->
?time:time impl ->
?random:random impl ->
'a ip impl ->
'a tcp impl

Expand All @@ -379,9 +379,9 @@ val stackv4 : stackv4 typ
(** Implementation of the [Mirage_types.STACKV4] signature. *)

val direct_stackv4 :
?clock:mclock impl ->
?random:random impl ->
?mclock:mclock impl ->
?time:time impl ->
?random:random impl ->
network impl ->
ethernet impl ->
arpv4 impl ->
Expand Down Expand Up @@ -446,9 +446,9 @@ val resolver : resolver typ
val resolver_dns :
?ns:Ipaddr.V4.t ->
?ns_port:int ->
?random:random impl ->
?time:time impl ->
?mclock:mclock impl ->
?random:random impl ->
stackv4 impl ->
resolver impl

Expand Down
4 changes: 2 additions & 2 deletions lib/mirage/mirage_impl_resolver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ let resolver_dns_conf ~ns ~ns_port =
impl ~packages ~keys ~connect "Resolver_mirage.Make_with_stack"
(random @-> time @-> mclock @-> stackv4 @-> resolver)

let resolver_dns ?ns ?ns_port ?(random = default_random) ?(time = default_time)
?(mclock = default_monotonic_clock) stack =
let resolver_dns ?ns ?ns_port ?(time = default_time)
?(mclock = default_monotonic_clock) ?(random = rng ~time ~mclock ()) stack =
let ns = Key.resolver ?default:ns ()
and ns_port = Key.resolver_port ?default:ns_port () in
resolver_dns_conf ~ns ~ns_port $ random $ time $ mclock $ stack
2 changes: 1 addition & 1 deletion lib/mirage/mirage_impl_resolver.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ val resolver : resolver typ
val resolver_dns :
?ns:Ipaddr.V4.t ->
?ns_port:int ->
?random:random impl ->
?time:time impl ->
?mclock:mclock impl ->
?random:random impl ->
Mirage_impl_stackv4.stackv4 impl ->
resolver impl

Expand Down
6 changes: 3 additions & 3 deletions lib/mirage/mirage_impl_stackv4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ let stackv4_direct_conf () =
@-> tcpv4
@-> stackv4 )

let direct_stackv4 ?(clock = default_monotonic_clock) ?(random = default_random)
?(time = default_time) network eth arp ip =
let direct_stackv4 ?(mclock = default_monotonic_clock) ?(time = default_time)
?(random = rng ~time ~mclock ()) network eth arp ip =
stackv4_direct_conf ()
$ time
$ random
Expand All @@ -47,7 +47,7 @@ let direct_stackv4 ?(clock = default_monotonic_clock) ?(random = default_random)
$ ip
$ Mirage_impl_icmp.direct_icmpv4 ip
$ direct_udp ~random ip
$ direct_tcp ~clock ~random ~time ip
$ direct_tcp ~mclock ~random ~time ip

let dhcp_ipv4_stack ?(random = default_random) ?(time = default_time)
?(arp = arp ?time:None) tap =
Expand Down
4 changes: 2 additions & 2 deletions lib/mirage/mirage_impl_stackv4.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ type stackv4
val stackv4 : stackv4 Functoria.typ

val direct_stackv4 :
?clock:Mirage_impl_mclock.mclock Functoria.impl ->
?random:Mirage_impl_random.random Functoria.impl ->
?mclock:Mirage_impl_mclock.mclock Functoria.impl ->
?time:Mirage_impl_time.time Functoria.impl ->
?random:Mirage_impl_random.random Functoria.impl ->
Mirage_impl_network.network Functoria.impl ->
Mirage_impl_ethernet.ethernet Functoria.impl ->
Mirage_impl_arpv4.arpv4 Functoria.impl ->
Expand Down
6 changes: 3 additions & 3 deletions lib/mirage/mirage_impl_tcp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ let tcp_direct_func () =
impl ~packages_v ~connect "Tcp.Flow.Make"
(ip @-> time @-> mclock @-> random @-> tcp)

let direct_tcp ?(clock = default_monotonic_clock) ?(random = default_random)
?(time = default_time) ip =
tcp_direct_func () $ ip $ time $ clock $ random
let direct_tcp ?(mclock = default_monotonic_clock) ?(time = default_time)
?(random = rng ~time ~mclock ()) ip =
tcp_direct_func () $ ip $ time $ mclock $ random

let tcpv4_socket_conf ipv4_key =
let keys = [ Key.v ipv4_key ] in
Expand Down
4 changes: 2 additions & 2 deletions lib/mirage/mirage_impl_tcp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ val tcpv4 : tcpv4 Functoria.typ
val tcpv6 : tcpv6 Functoria.typ

val direct_tcp :
?clock:Mirage_impl_mclock.mclock Functoria.impl ->
?random:Mirage_impl_random.random Functoria.impl ->
?mclock:Mirage_impl_mclock.mclock Functoria.impl ->
?time:Mirage_impl_time.time Functoria.impl ->
?random:Mirage_impl_random.random Functoria.impl ->
'a Mirage_impl_ip.ip Functoria.impl ->
'a tcp Functoria.impl

Expand Down

0 comments on commit 4a301c7

Please sign in to comment.