package tezos-dal-node-lib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file gs_logging.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2023 Nomadic Labs, <contact@nomadic-labs.com>               *)
(* Copyright (c) 2023 Functori,     <contact@functori.com>                   *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

open Gs_interface.Worker_instance

module Events = struct
  include Internal_event.Simple
  open Data_encoding

  let section = ["gossipsub"; "worker"; "event"]

  let prefix =
    let prefix = String.concat "_" section in
    fun s -> prefix ^ "-" ^ s

  let heartbeat =
    declare_0
      ~section
      ~name:(prefix "heartbeat")
      ~msg:"Process Heartbeat"
      ~level:Info
      ()

  let publish_message =
    declare_2
      ~section
      ~name:(prefix "publish_message")
      ~msg:"Process Publish_message id {message_id} with topic {topic}"
      ~level:Debug
      ~pp1:GS.Topic.pp
      ~pp2:GS.Message_id.pp
      ("topic", Types.Topic.encoding)
      ("message_id", Types.Message_id.encoding)

  let join =
    declare_1
      ~section
      ~name:(prefix "join")
      ~msg:"Process Join {topic}"
      ~level:Info
      ~pp1:GS.Topic.pp
      ("topic", Types.Topic.encoding)

  let leave =
    declare_1
      ~section
      ~name:(prefix "leave")
      ~msg:"Process Leave {topic}"
      ~level:Info
      ~pp1:GS.Topic.pp
      ("topic", Types.Topic.encoding)

  let new_connection =
    declare_4
      ~section
      ~name:(prefix "new_connection")
      ~msg:
        "Process New_connection from/to {peer} (direct={direct}, \
         trusted={trusted}, bootstrap={bootstrap})"
      ~level:Notice
      ~pp1:P2p_peer.Id.pp
      ("peer", P2p_peer.Id.encoding)
      ("direct", bool)
      ("trusted", bool)
      ("bootstrap", bool)

  let disconnection =
    declare_1
      ~section
      ~name:(prefix "disconnection")
      ~msg:"Process Disconnection of {peer}"
      ~level:Notice
      ~pp1:P2p_peer.Id.pp
      ("peer", P2p_peer.Id.encoding)

  let message_with_header =
    declare_3
      ~section
      ~name:(prefix "message_with_header")
      ~msg:
        "Process Message_with_header from {peer} with id {message_id} and \
         topic {topic}"
      ~level:Debug
      ~pp1:P2p_peer.Id.pp
      ~pp2:GS.Topic.pp
      ~pp3:GS.Message_id.pp
      ("peer", P2p_peer.Id.encoding)
      ("topic", Types.Topic.encoding)
      ("message_id", Types.Message_id.encoding)

  let subscribe =
    declare_2
      ~section
      ~name:(prefix "subscribe")
      ~msg:"Process Subscribe {peer} to {topic}"
      ~level:Info
      ~pp1:P2p_peer.Id.pp
      ~pp2:GS.Topic.pp
      ("peer", P2p_peer.Id.encoding)
      ("topic", Types.Topic.encoding)

  let unsubscribe =
    declare_2
      ~section
      ~name:(prefix "unsubscribe")
      ~msg:"Process Unsubscribe {peer} from {topic}"
      ~level:Info
      ~pp1:P2p_peer.Id.pp
      ~pp2:GS.Topic.pp
      ("peer", P2p_peer.Id.encoding)
      ("topic", Types.Topic.encoding)

  let graft =
    declare_2
      ~section
      ~name:(prefix "graft")
      ~msg:"Process Graft {peer} for {topic}"
      ~level:Info
      ~pp1:P2p_peer.Id.pp
      ~pp2:GS.Topic.pp
      ("peer", P2p_peer.Id.encoding)
      ("topic", Types.Topic.encoding)

  let prune =
    declare_4
      ~section
      ~name:(prefix "prune")
      ~msg:"Process Prune {peer} for {topic} with backoff {backoff} and px {px}"
      ~level:Info
      ~pp1:P2p_peer.Id.pp
      ~pp2:GS.Topic.pp
      ~pp3:Types.Span.pp
      ~pp4:(Format.pp_print_list P2p_peer.Id.pp)
      ("peer", P2p_peer.Id.encoding)
      ("topic", Types.Topic.encoding)
      ("backoff", Types.Span.encoding)
      ("px", list P2p_peer.Id.encoding)

  let ihave =
    declare_3
      ~section
      ~name:(prefix "ihave")
      ~msg:
        "Process IHave from {peer} for {topic} with message_ids {message_ids}"
      ~level:Info
      ~pp1:P2p_peer.Id.pp
      ~pp2:GS.Topic.pp
      ~pp3:(Format.pp_print_list GS.Message_id.pp)
      ("peer", P2p_peer.Id.encoding)
      ("topic", Types.Topic.encoding)
      ("message_ids", list Types.Message_id.encoding)

  let iwant =
    declare_2
      ~section
      ~name:(prefix "iwant")
      ~msg:"Process IWant from {peer} with message_ids {message_ids}"
      ~level:Info
      ~pp1:P2p_peer.Id.pp
      ~pp2:(Format.pp_print_list GS.Message_id.pp)
      ("peer", P2p_peer.Id.encoding)
      ("message_ids", list Types.Message_id.encoding)
end

let event =
  let open Events in
  function
  | Heartbeat -> emit heartbeat ()
  | App_input event -> (
      match event with
      | Publish_message {message = _; message_id; topic} ->
          emit publish_message (topic, message_id)
      | Join topic -> emit join topic
      | Leave topic -> emit leave topic)
  | P2P_input event -> (
      match event with
      | New_connection {peer; direct; trusted; bootstrap} ->
          emit new_connection (peer, direct, trusted, bootstrap)
      | Disconnection {peer} -> emit disconnection peer
      | In_message {from_peer; p2p_message} -> (
          match p2p_message with
          | Message_with_header {message = _; topic; message_id} ->
              emit message_with_header (from_peer, topic, message_id)
          | Subscribe {topic} -> emit subscribe (from_peer, topic)
          | Unsubscribe {topic} -> emit unsubscribe (from_peer, topic)
          | Graft {topic} -> emit graft (from_peer, topic)
          | Prune {topic; px; backoff} ->
              emit prune (from_peer, topic, backoff, List.of_seq px)
          | IHave {topic; message_ids} ->
              emit ihave (from_peer, topic, message_ids)
          | IWant {message_ids} -> emit iwant (from_peer, message_ids)))
OCaml

Innovation. Community. Security.