Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions unikernel/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ when we want to start an HTTP(S) server.

### The config.ml

The MirageOS manifest describes 3 things:
The MirageOS manifest describes 2 things:

- How to make a simple `Paf` module (which provides `request`)
- How to make a simple `Paf_cohttp` module (which provides `Cohttp_lwt.S.Client`
plus _metadata_)
- How to make a simple `Paf` module (which provides HTTP and HTTPS connections)
- How to make a simple DNS client (with `ocaml-dns`)

It requires an `uri` argument such as:
Expand Down
2 changes: 1 addition & 1 deletion unikernel/client/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let uri =
let minipaf =
foreign "Unikernel.Make"
~keys:[ Key.abstract uri ]
~packages:[ package "paf" ~sublibs:[ "cohttp" ]
~packages:[ package "paf-cohttp"
; package "ca-certs-nss" ]
(console @-> time @-> pclock @-> stackv4v6 @-> dns @-> paf @-> job)

Expand Down
22 changes: 13 additions & 9 deletions unikernel/client/unikernel.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[@@@warning "-45"]

module type DNS = sig
type t

Expand Down Expand Up @@ -26,7 +28,7 @@ module Make
(Console : Mirage_console.S)
(Time : Mirage_time.S)
(Pclock : Mirage_clock.PCLOCK)
(Stack : Mirage_stack.V4V6)
(_ : Mirage_stack.V4V6)
(Dns : DNS) (* XXX(dinosaure): ask @hannesm to provide a signature. *)
(Paf : Paf_mirage.S) = struct
module Client = Paf_cohttp
Expand All @@ -44,23 +46,24 @@ module Make
let k scheme stack ipaddr port = match scheme with
| `HTTP -> Lwt.return_some (stack, ipaddr, port) | _ -> Lwt.return_none in
Mimic.(fold Paf.tcp_edn Fun.[ req Client.scheme
; req stack
; req Client.ipaddr
; dft Client.port 80 ] ~k ctx)
; req stack
; req Client.ipaddr
; dft Client.port 80 ] ~k ctx)

let with_tls ctx =
let k scheme domain_name cfg stack ipaddr port = match scheme with
| `HTTPS -> Lwt.return_some (domain_name, cfg, stack, ipaddr, port) | _ -> Lwt.return_none in
Mimic.(fold Paf.tls_edn Fun.[ req Client.scheme
; opt Client.domain_name
; dft tls default_tls_cfg
; req stack
; req Client.ipaddr
; dft Client.port 443 ] ~k ctx)
; opt Client.domain_name
; dft tls default_tls_cfg
; req stack
; req Client.ipaddr
; dft Client.port 443 ] ~k ctx)

let dns = Mimic.make ~name:"dns"

let with_dns v ctx = Mimic.add dns v ctx
let with_sleep ctx = Mimic.add Paf_cohttp.sleep Time.sleep_ns ctx

let with_resolv ctx =
let k dns domain_name =
Expand All @@ -75,6 +78,7 @@ module Make
let uri = Uri.of_string (Key_gen.uri ()) in
let ctx =
Mimic.empty
|> with_sleep
|> with_tcp (* stack -> ipaddr -> port => (stack * ipaddr * port) *)
|> with_tls (* domain_name -> tls -> stack -> ipaddr -> port => (domain_name * tls * stack * ipaddr * port) *)
|> with_resolv (* domain_name => ipaddr *)
Expand Down
3 changes: 2 additions & 1 deletion unikernel/server/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ let minipaf =
~packages:[ package "ca-certs-nss"
; package "dns-client.mirage"
; package "paf"
; package "paf" ~sublibs:[ "le"; "mirage" ]
; package "paf" ~sublibs:[ "mirage" ]
; package "paf-le"
; package "rock" ]
(console @-> random @-> time @-> mclock @-> pclock @-> stackv4v6 @-> job)

Expand Down
4 changes: 2 additions & 2 deletions unikernel/server/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let app =
App.create ~handler ()

module Make
(Console : Mirage_console.S)
(_ : Mirage_console.S)
(Random : Mirage_random.S)
(Time : Mirage_time.S)
(Mclock : Mirage_clock.MCLOCK)
Expand Down Expand Up @@ -70,7 +70,7 @@ module Make
HTTPS (Option.value ~default:443 port, { Letsencrypt.hostname; email; seed; certificate_seed; })
| None -> failwith "Missing hostname"

let start console _random _time _mclock _pclock stackv4v6 =
let start _console _random _time _mclock _pclock stackv4v6 =
let email = Option.bind (Key_gen.email ()) (Rresult.R.to_option <.> Emile.of_string) in
let hostname = Option.bind (Key_gen.hostname ()) (Rresult.R.(to_option <.> host)) in
let cfg = cfg ?port:(Key_gen.port ())
Expand Down