From c906f2c5d3c9714f6599d0a9c6ced9a5b9082b6c Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 27 May 2019 23:42:15 +0200 Subject: [PATCH] tcp --- src/monitoring_experiments.ml | 9 ++++++++- src/monitoring_experiments.mli | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/monitoring_experiments.ml b/src/monitoring_experiments.ml index 1e24a28..7a32bdf 100644 --- a/src/monitoring_experiments.ml +++ b/src/monitoring_experiments.ml @@ -204,7 +204,7 @@ jfuLKkCfGcw9A8o= |} in X509.Encoding.Pem.Certificate.of_pem_cstruct1 data - let create s ?(port = 8093) ?hostname ?(interval = 10) certificates = + let create_tls ?(port = 8093) ?hostname ?(interval = 10) s certificates = Metrics.enable_all (); let flows = I.create ~interval ?hostname () in Lwt.async (L.collect (fun () -> T.sleep_ns (Duration.of_sec interval))); @@ -217,6 +217,13 @@ jfuLKkCfGcw9A8o= TLS.server_of_flow server flow >|= function | Ok tls -> I.add_flow flows tls | Error e -> Log.err (fun m -> m "TLS error %a" TLS.pp_write_error e)) + + module TC = Pull(T)(C)(S.TCPV4) + let create_tcp ?(port = 8093) ?hostname ?(interval = 10) s = + Metrics.enable_all (); + let flows = TC.create ~interval ?hostname () in + Lwt.async (L.collect (fun () -> T.sleep_ns (Duration.of_sec interval))); + S.listen_tcpv4 s ~port (fun flow -> Lwt.return (TC.add_flow flows flow)) end end diff --git a/src/monitoring_experiments.mli b/src/monitoring_experiments.mli index ae43e4f..5fc6182 100644 --- a/src/monitoring_experiments.mli +++ b/src/monitoring_experiments.mli @@ -38,6 +38,7 @@ module M : sig end module S (T : Mirage_time_lwt.S) (P : Mirage_clock.PCLOCK) (C : Mirage_clock.MCLOCK) (S : Mirage_stack_lwt.V4) : sig - val create : S.t -> ?port:int -> ?hostname:string -> ?interval:int -> Tls.Config.own_cert -> unit + val create_tls : ?port:int -> ?hostname:string -> ?interval:int -> S.t -> Tls.Config.own_cert -> unit + val create_tcp : ?port:int -> ?hostname:string -> ?interval:int -> S.t -> unit end end