Module Upsycle_router.Commons

Contains shared types and values which are used throughout the application.

Convenience types.

type result_msg = Rresult.R.msg
type 'a rresult = ('a, result_msg) Stdlib.result
type 'a to_yaml = 'a -> Yaml.value
type 'a of_yaml = Yaml.value -> 'a rresult
type 'a sencode = 'a -> Seaboar.Encode.value
type 'a sdecode = 'a Seaboar.Decode.t

Basic types.

type privkey_25519 = Mirage_crypto_ec.Ed25519.priv

These are the base types we use for private and public keys; no need to try and hide the implementation.

type pubkey_25519 = Mirage_crypto_ec.Ed25519.pub
type privkey
type pubkey
type ip
type port
type ip_port
type host_port
type command
type multicast_group_pubkey
type multicast_group_privkey
type multicast_group_rw

A multicast group for which we have both a public and private key.

type multicast_group_ro

A multicast group for which we only have a public key.

type multicast_group = [
  1. | `Rw of multicast_group_rw
  2. | `Ro of multicast_group_ro
]

Types used for configuration and choices. *

type msg_id_hash_function = [
  1. | `Blake2b_256
  2. | `Blake2b_32
  3. | `Blake2s_128
  4. | `Blake2s_32
]

Used for choosing the Blake2 hash function for calculating message IDs.

type multicast_requestor = [
  1. | `Peerkey
  2. | `Src
]

When the message router receives a JOIN request whose src field doesn't match the actual public key of the peer, it needs to decide which one to actually add to the group. By default this is set to `Src in the configurations, but `Peerkey can be useful for testing or experimenting.

type print_messages_on_console = [
  1. | `Long
  2. | `None
  3. | `Short
]

Configures whether or not to dump the contents of every message received by the message router to the console.

type multicast_subscriber

Types used for configuring the initial state of the message router.

type multicast_table = (multicast_group_pubkey, multicast_subscriber BatSet.t) BatMap.t
type remote_router = private {
  1. pubkey : pubkey;
  2. ip : ip;
  3. port : port;
  4. routername : string;
}

The functions in T are just function versions of the constructors of various types, which provides a convenient way of constructing types in many situations.

module T : sig ... end
module Pp : sig ... end
module Encode : sig ... end
module Decode : sig ... end
module Crypto : sig ... end
module Yaml : sig ... end
module Mk : sig ... end
module Acc : sig ... end
val keys_common : string -> char -> unit Lwt.t

Provides handlers for the keys 'q', '\n', and an unknown key press, to be used in the key thread.

Miscellaneous helpers.

val mk_random_ttl : [< `Medium | `Short ] -> int

Returns a random integer for use in the `ttl` field.

mk_random_ttl `Short produces an integer in the range [3, 10].

mk_random_ttl `Medium produces an integer in the range [10, 30].

val mk_random_expiry : unit -> int

Returns a random integer representing minutes elapsed since 2020-01-01 00:00 UTC, for use in the `expiry` field.

val mk_random_revision : unit -> int

Returns a random integer in the range [0, 19], for use in the `revision` field.

val ip_of_string_result : string -> ip rresult

Converts a string to our internal ip type.

val to_yaml_noop : 'a Util_yaml.to_yaml

ppx_deriving_yaml requires both an x_to_yaml and x_of_yaml function for a type x in order to be able produce derivations for types which include x. However the 'of_yaml' variant is never used in this library so there's no sense in writing it; this function can be provided instead to satisfy the requirements.

val error_msg : string -> string rresult

Convenience for generating Error (`Msg s) from a string s.

val pubkey_of_multicast_group : multicast_group -> pubkey
val string_list_of_command : command -> string list
val pp_comma_list : 'a Fmt.t -> 'a list Fmt.t