package man_in_the_middle_debugger

  1. Overview
  2. Docs

Source file man_in_the_middle_debugger_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
open Async

(** This library helps debug a connection between two parties speaking a protocol by
    capturing the traffic that passes between them. *)

type angstrom_exit_status = (unit, string) Result.t

module Peer = struct
  type t =
    { name : string
    ; reader : Reader.t
    ; writer : Writer.t
    }
end

module type Protocol = sig
  type message

  val parser_ : message Angstrom.t
  val to_string : message -> string
end

module type S = sig
  module Peer = Peer

  type message

  (** Given a [Reader.t] and [Writer.t] connected to a peer, return a new [Reader.t] and
      [Writer.t] that represents the connection to the peer but that will run [f] on any
      messages that are read or written. *)
  val wrap_connection_to_peer
    :  Peer.t
    -> my_name:string
    -> f:([ `Sent | `Received ] -> message -> unit)
    -> (Reader.t
        * Writer.t
        * [ `Stopped_reading of angstrom_exit_status Deferred.t ]
        * [ `Stopped_writing of angstrom_exit_status Deferred.t ])
         Deferred.t

  (** Connect two peers together and listen to the messages that pass between them. Both
      readers and writers will be closed when either side closes the connection. *)
  val connect_peers_and_listen
    :  peer1:Peer.t
    -> peer2:Peer.t
    -> f:([ `Peer_1_to_2 | `Peer_2_to_1 ] -> message -> unit)
    -> ([ `Peer1 of angstrom_exit_status ] * [ `Peer2 of angstrom_exit_status ])
         Deferred.t
end

module type Man_in_the_middle_debugger = sig
  module type S = S

  module Peer = Peer
  module Make (Protocol : Protocol) : S with type message := Protocol.message
end