Source file transport_layer_interface.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
module P2p_message_V1 = struct
type px_peer = {point : P2p_point.Id.t; peer : P2p_peer.Id.t}
type p2p_message =
| Graft of {topic : Gs_interface.topic}
| Prune of {
topic : Gs_interface.topic;
px : px_peer Seq.t;
backoff : Gs_interface.Span.t;
}
| IHave of {
topic : Gs_interface.topic;
message_ids : Gs_interface.message_id list;
}
| IWant of {message_ids : Gs_interface.message_id list}
| Subscribe of {topic : Gs_interface.topic}
| Unsubscribe of {topic : Gs_interface.topic}
let px_peer_encoding =
let open Data_encoding in
conv
(fun {point; peer} -> (point, peer))
(fun (point, peer) -> {point; peer})
(obj2
(req "point" P2p_point.Id.encoding)
(req "peer" P2p_peer.Id.encoding))
let encoding =
let open Data_encoding in
let case ?max_length ~tag ~title encoding unwrap wrap =
P2p_params.Encoding {tag; title; encoding; wrap; unwrap; max_length}
in
[
case
~tag:0x10
~title:"Graft"
(obj2
(req "kind" (constant "graft"))
(req "topic" Gs_interface.topic_encoding))
(function Graft {topic} -> Some ((), topic) | _ -> None)
(fun ((), topic) -> Graft {topic});
case
~tag:0x11
~title:"Prune"
(obj4
(req "kind" (constant "prune"))
(req "topic" Gs_interface.topic_encoding)
(req "px" (list px_peer_encoding))
(req "backoff" Gs_interface.span_encoding))
(function
| Prune {topic; px; backoff} ->
Some ((), topic, List.of_seq px, backoff)
| _ -> None)
(fun ((), topic, px, backoff) ->
Prune {topic; px = List.to_seq px; backoff});
case
~tag:0x12
~title:"IHave"
(obj3
(req "kind" (constant "ihave"))
(req "topic" Gs_interface.topic_encoding)
(req "message_ids" (list Gs_interface.message_id_encoding)))
(function
| IHave {topic; message_ids} -> Some ((), topic, message_ids)
| _ -> None)
(fun ((), topic, message_ids) -> IHave {topic; message_ids});
case
~tag:0x13
~title:"IWant"
(obj2
(req "kind" (constant "iwant"))
(req "message_ids" (list Gs_interface.message_id_encoding)))
(function IWant {message_ids} -> Some ((), message_ids) | _ -> None)
(fun ((), message_ids) -> IWant {message_ids});
case
~tag:0x14
~title:"Subscribe"
(obj2
(req "kind" (constant "subscribe"))
(req "topic" Gs_interface.topic_encoding))
(function Subscribe {topic} -> Some ((), topic) | _ -> None)
(fun ((), topic) -> Subscribe {topic});
case
~tag:0x15
~title:"Unsubscribe"
(obj2
(req "kind" (constant "unsubscribe"))
(req "topic" Gs_interface.topic_encoding))
(function Unsubscribe {topic} -> Some ((), topic) | _ -> None)
(fun ((), topic) -> Unsubscribe {topic});
case
~tag:0x16
~title:"Message_with_header"
(obj4
(req "kind" (constant "message_with_header"))
(req "message" Gs_interface.message_encoding)
(req "topic" Gs_interface.topic_encoding)
(req "message_id" Gs_interface.message_id_encoding))
(function
| Message_with_header {message; topic; message_id} ->
Some ((), message, topic, message_id)
| _ -> None)
(fun ((), message, topic, message_id) ->
Message_with_header {message; topic; message_id});
]
let distributed_db_versions = [Distributed_db_version.zero]
let message_config ~network_name : p2p_message P2p_params.message_config =
let chain_name = Distributed_db_version.Name.of_string network_name in
{encoding; chain_name; distributed_db_versions}
end
include P2p_message_V1
type peer_metadata = unit
let peer_meta_config : peer_metadata P2p_params.peer_meta_config =
let empty () = () in
let encoding = Data_encoding.unit in
let score (_ : peer_metadata) = 1.0 in
{peer_meta_encoding = encoding; peer_meta_initial = empty; score}
type connection_metadata = unit
let conn_meta_config : connection_metadata P2p_params.conn_meta_config =
{
conn_meta_encoding = Data_encoding.unit;
private_node = (fun () -> false);
conn_meta_value = (fun () -> ());
}