@@ -15,8 +15,8 @@ import (
1515type Op byte
1616
1717// Types of messages that may be sent between nodes
18- // Note: If you add a new parseable Op below, you must also add it to ops
19- // (declared below)
18+ // Note: If you add a new parseable Op below, you must add it to either
19+ // [UnrequestedOps] or [FailedToResponseOps].
2020const (
2121 // Handshake:
2222 PingOp Op = iota
@@ -62,102 +62,23 @@ const (
6262)
6363
6464var (
65- HandshakeOps = []Op {
66- PingOp ,
67- PongOp ,
68- HandshakeOp ,
69- GetPeerListOp ,
70- PeerListOp ,
71- }
72-
73- // List of all consensus request message types
74- ConsensusRequestOps = []Op {
75- GetStateSummaryFrontierOp ,
76- GetAcceptedStateSummaryOp ,
65+ // UnrequestedOps are operations that are expected to be seen without having
66+ // requested them. For example, a peer may receive a Get request for a block
67+ // without having sent a message previously.
68+ UnrequestedOps = set .Of (
7769 GetAcceptedFrontierOp ,
7870 GetAcceptedOp ,
7971 GetAncestorsOp ,
8072 GetOp ,
8173 PushQueryOp ,
8274 PullQueryOp ,
8375 AppRequestOp ,
84- }
85- ConsensusResponseOps = []Op {
86- StateSummaryFrontierOp ,
87- AcceptedStateSummaryOp ,
88- AcceptedFrontierOp ,
89- AcceptedOp ,
90- AncestorsOp ,
91- PutOp ,
92- ChitsOp ,
93- AppResponseOp ,
94- AppErrorOp ,
95- }
96- // AppGossip is the only message that is sent unrequested without the
97- // expectation of a response
98- ConsensusExternalOps = append (
99- ConsensusRequestOps ,
100- append (
101- ConsensusResponseOps ,
102- AppGossipOp ,
103- )... ,
104- )
105- ConsensusInternalOps = []Op {
106- GetStateSummaryFrontierFailedOp ,
107- GetAcceptedStateSummaryFailedOp ,
108- GetAcceptedFrontierFailedOp ,
109- GetAcceptedFailedOp ,
110- GetAncestorsFailedOp ,
111- GetFailedOp ,
112- QueryFailedOp ,
113- ConnectedOp ,
114- DisconnectedOp ,
115- NotifyOp ,
116- GossipRequestOp ,
117- }
118- ConsensusOps = append (ConsensusExternalOps , ConsensusInternalOps ... )
119-
120- ExternalOps = append (ConsensusExternalOps , HandshakeOps ... )
121-
122- SynchronousOps = []Op {
123- // State sync
76+ AppGossipOp ,
12477 GetStateSummaryFrontierOp ,
125- GetStateSummaryFrontierFailedOp ,
126- StateSummaryFrontierOp ,
12778 GetAcceptedStateSummaryOp ,
128- GetAcceptedStateSummaryFailedOp ,
129- AcceptedStateSummaryOp ,
130- // Bootstrapping
131- GetAcceptedFrontierOp ,
132- GetAcceptedFrontierFailedOp ,
133- AcceptedFrontierOp ,
134- GetAcceptedOp ,
135- GetAcceptedFailedOp ,
136- AcceptedOp ,
137- GetAncestorsOp ,
138- GetAncestorsFailedOp ,
139- AncestorsOp ,
140- // Consensus
141- GetOp ,
142- GetFailedOp ,
143- PutOp ,
144- PushQueryOp ,
145- PullQueryOp ,
146- QueryFailedOp ,
147- ChitsOp ,
148- // Internal
149- ConnectedOp ,
150- DisconnectedOp ,
151- }
152-
153- AsynchronousOps = []Op {
154- // Application
155- AppRequestOp ,
156- AppErrorOp ,
157- AppGossipOp ,
158- AppResponseOp ,
159- }
160-
79+ )
80+ // FailedToResponseOps maps response failure messages to their successful
81+ // counterparts.
16182 FailedToResponseOps = map [Op ]Op {
16283 GetStateSummaryFrontierFailedOp : StateSummaryFrontierOp ,
16384 GetAcceptedStateSummaryFailedOp : AcceptedStateSummaryOp ,
@@ -168,18 +89,6 @@ var (
16889 QueryFailedOp : ChitsOp ,
16990 AppErrorOp : AppResponseOp ,
17091 }
171- UnrequestedOps = set .Of (
172- GetAcceptedFrontierOp ,
173- GetAcceptedOp ,
174- GetAncestorsOp ,
175- GetOp ,
176- PushQueryOp ,
177- PullQueryOp ,
178- AppRequestOp ,
179- AppGossipOp ,
180- GetStateSummaryFrontierOp ,
181- GetAcceptedStateSummaryOp ,
182- )
18392
18493 errUnknownMessageType = errors .New ("unknown message type" )
18594)
0 commit comments