Up

module Conduit_lwt_unix

: sig

Connection establishment using the Lwt_unix library

Core types

#
type client_tls_config = [
| `Hostname of string
] * [
| `IP of Ipaddr.t
] * [
| `Port of int
]

Configuration fragment for a TLS client connecting to a remote endpoint

#
type client = [
| `TLS_native of client_tls_config
| `OpenSSL of client_tls_config
| `TCP of [
| `IP of Ipaddr.t
] * [
| `Port of int
]
| `Unix_domain_socket of [
| `File of string
]
| `Vchan_direct of [
| `Domid of int
] * [
| `Port of string
]
| `Vchan_domain_socket of [
| `Domain_name of string
] * [
| `Port of string
]
]

Set of supported client connections that are supported by this module.

#
type server_tls_config = [
| `Crt_file_path of string
] * [
| `Key_file_path of string
] * [
| `Password of bool -> string
| `No_password
] * [
| `Port of int
]

Configuration fragment for a listening TLS server

#
type server = [
| `OpenSSL of server_tls_config
| `TLS_native of server_tls_config
| `TCP of [
| `Port of int
]
| `Unix_domain_socket of [
| `File of string
]
| `Vchan_direct of int * string
| `Vchan_domain_socket of string * string
]

Set of supported listening mechanisms that are supported by this module.

#
type 'a io = 'a Lwt.t
#
type ic = Lwt_io.input_channel
#
#
type tcp_flow = private {
# fd
: Lwt_unix.file_descr Sexplib.Conv.sexp_opaque;
# ip
: Ipaddr.t;
# port
: int;
}

tcp_flow contains the state of a single TCP connection.

#
type domain_flow = private {
# fd
: Lwt_unix.file_descr Sexplib.Conv.sexp_opaque;
# path
: string;
}

domain_flow contains the state of a single Unix domain socket connection.

#
type vchan_flow = private {
# domid
: int;
# port
: string;
}

vchan_flow contains the state of a single Vchan shared memory connection.

#
type flow = private
# | TCP of tcp_flow
# | Domain_socket of domain_flow
# | Vchan of vchan_flow

A flow contains the state of a single connection, over a specific transport method.

#
type tls_server_key = [
| `None
| `TLS of [
| `Crt_file_path of string
] * [
| `Key_file_path of string
] * [
| `Password of bool -> string
| `No_password
]
]

Type describing where to locate a PEM key in the filesystem

#
type ctx

State handler for an active conduit

Connection and listening

#
val default_ctx : ctx

Default context that listens on all source addresses with no TLS certificate associated with the Conduit

#
val init : ?src:string -> ?tls_server_key:tls_server_key -> unit -> ctx io

init ?src ?tls_server_key () will initialize a Unix conduit that binds to the src interface if specified. If TLS server connections are used, then tls_server_key must contain a valid certificate to be used to advertise a TLS connection

#
val connect : ctx:ctx -> client -> (flow * ic * oc) io

connect ~ctx client establishes an outgoing connection via the ctx context to the endpoint described by client

#
val serve : ?timeout:int -> ?stop:unit io -> ctx:ctx -> mode:server -> (flow -> ic -> oc -> unit io) -> unit io

serve ?timeout ?stop ~ctx ~mode fn establishes a listening connection of type mode, using the ctx context. The stop thread will terminate the server if it ever becomes determined. Every connection will be served in a new lightweight thread that is invoked via the fn callback

#
val endp_of_flow : flow -> Conduit.endp

endp_of_flow flow retrieves the original Conduit.endp from the established flow

#
val endp_to_client : ctx:ctx -> Conduit.endp -> client io

endp_to_client ~ctx endp converts an endp into a a concrete connection mechanism of type client

#
val endp_to_server : ctx:ctx -> Conduit.endp -> server io

endp_to_server ~ctx endp converts an endp into a a concrete connection mechanism of type client

TLS library selection

#
type tls_lib =
# | OpenSSL
(*The Lwt_ssl bindings to the C OpenSSL library*)
# | Native
(*A pure OCaml TLS implementation*)
# | No_tls
(*No TLS implementation available, so any connections will fail*)

Currently selected method of using TLS for client and servers

#
val tls_library : tls_lib Pervasives.ref

The default selection is to select OpenSSL, Native and No_tls in decreasing order of priority. The native OCaml stack can be forced by setting the CONDUIT_TLS Unix environment variable to native.

#
val client_tls_config_of_sexp : Sexplib.Sexp.t -> client_tls_config
#
val sexp_of_client_tls_config : client_tls_config -> Sexplib.Sexp.t
#
val client_of_sexp : Sexplib.Sexp.t -> client
#
val __client_of_sexp__ : Sexplib.Sexp.t -> client
#
val sexp_of_client : client -> Sexplib.Sexp.t
#
val server_tls_config_of_sexp : Sexplib.Sexp.t -> server_tls_config
#
val sexp_of_server_tls_config : server_tls_config -> Sexplib.Sexp.t
#
val server_of_sexp : Sexplib.Sexp.t -> server
#
val __server_of_sexp__ : Sexplib.Sexp.t -> server
#
val sexp_of_server : server -> Sexplib.Sexp.t
#
val sexp_of_tcp_flow : tcp_flow -> Sexplib.Sexp.t
#
val sexp_of_domain_flow : domain_flow -> Sexplib.Sexp.t
#
val sexp_of_vchan_flow : vchan_flow -> Sexplib.Sexp.t
#
val sexp_of_flow : flow -> Sexplib.Sexp.t
#
val tls_server_key_of_sexp : Sexplib.Sexp.t -> tls_server_key
#
val __tls_server_key_of_sexp__ : Sexplib.Sexp.t -> tls_server_key
#
val sexp_of_tls_server_key : tls_server_key -> Sexplib.Sexp.t
#
val sexp_of_ctx : ctx -> Sexplib.Sexp.t
end