summaryrefslogtreecommitdiff
path: root/protocol/tags.go
blob: e9804546748e0636223daecc426989c60ec8d0f9 (plain)
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
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

package protocol

// Tag represents a message type identifier.  Messages have a Tag field. Handlers can register to a given Tag.
// e.g., the agreement service can register to handle agreements with the Agreement tag.
type Tag string

// TagLength specifies the length of protocol tags.
const TagLength = 2

// Tags, in lexicographic sort order of tag values to avoid duplicates.
// These tags must not contain a comma character because lists of tags
// are encoded using a comma separator (see network/msgOfInterest.go).
// The tags must be 2 bytes long.
const (
	AgreementVoteTag     Tag = "AV"
	MsgOfInterestTag     Tag = "MI"
	MsgDigestSkipTag     Tag = "MS"
	NetPrioResponseTag   Tag = "NP"
	NetIDVerificationTag Tag = "NI"
	PingTag              Tag = "pi"
	PingReplyTag         Tag = "pj"
	ProposalPayloadTag   Tag = "PP"
	StateProofSigTag     Tag = "SP"
	TopicMsgRespTag      Tag = "TS"
	TxnTag               Tag = "TX"
	//UniCatchupReqTag   Tag = "UC" was replaced by UniEnsBlockReqTag
	UniEnsBlockReqTag Tag = "UE"
	//UniEnsBlockResTag  Tag = "US" was used for wsfetcherservice
	//UniCatchupResTag   Tag = "UT" was used for wsfetcherservice
	VoteBundleTag Tag = "VB"
)

// The following constants are overestimates in some cases but are reasonable upper bounds
// for the purposes of limiting the number of bytes read from the network.
// The calculations to obtain them are defined in node/TestMaxSizesCorrect()

// AgreementVoteTagMaxSize is the maximum size of an AgreementVoteTag message
const AgreementVoteTagMaxSize = 1228

// MsgOfInterestTagMaxSize is the maximum size of a MsgOfInterestTag message
const MsgOfInterestTagMaxSize = 45

// MsgDigestSkipTagMaxSize is the maximum size of a MsgDigestSkipTag message
const MsgDigestSkipTagMaxSize = 69

// NetPrioResponseTagMaxSize is the maximum size of a NetPrioResponseTag message
const NetPrioResponseTagMaxSize = 850

// NetIDVerificationTagMaxSize is the maximum size of a NetIDVerificationTag message
const NetIDVerificationTagMaxSize = 215

// PingTagMaxSize is the maximum size of a PingTag message
const PingTagMaxSize = 8

// PingReplyTagMaxSize is the maximum size of a PingReplyTag message
const PingReplyTagMaxSize = 8

// ProposalPayloadTagMaxSize is the maximum size of a ProposalPayloadTag message
// This value is dominated by the MaxTxnBytesPerBlock
const ProposalPayloadTagMaxSize = 5247980

// StateProofSigTagMaxSize is the maximum size of a StateProofSigTag message
const StateProofSigTagMaxSize = 6378

// TopicMsgRespTagMaxSize is the maximum size of a TopicMsgRespTag message
// This is a response to a topic message request (either UE or MI) and the largest possible
// response is the largest possible block.
// Matches  current network.MaxMessageLength
const TopicMsgRespTagMaxSize = 6 * 1024 * 1024

// TxnTagMaxSize is the maximum size of a TxnTag message. This is equal to SignedTxnMaxSize()
// which is size of just a single message containing maximum Stateproof. Since Stateproof
// transactions can't be batched we don't need to multiply by MaxTxnBatchSize.
const TxnTagMaxSize = 4620031

// UniEnsBlockReqTagMaxSize is the maximum size of a UniEnsBlockReqTag message
const UniEnsBlockReqTagMaxSize = 67

// VoteBundleTagMaxSize is the maximum size of a VoteBundleTag message
// Matches current network.MaxMessageLength
const VoteBundleTagMaxSize = 6 * 1024 * 1024

// MaxMessageSize returns the maximum size of a message for a given tag
func (tag Tag) MaxMessageSize() uint64 {
	switch tag {
	case AgreementVoteTag:
		return AgreementVoteTagMaxSize
	case MsgOfInterestTag:
		return MsgOfInterestTagMaxSize
	case MsgDigestSkipTag:
		return MsgDigestSkipTagMaxSize
	case NetPrioResponseTag:
		return NetPrioResponseTagMaxSize
	case NetIDVerificationTag:
		return NetIDVerificationTagMaxSize
	case PingTag:
		return PingTagMaxSize
	case PingReplyTag:
		return PingReplyTagMaxSize
	case ProposalPayloadTag:
		return ProposalPayloadTagMaxSize
	case StateProofSigTag:
		return StateProofSigTagMaxSize
	case TopicMsgRespTag:
		return TopicMsgRespTagMaxSize
	case TxnTag:
		return TxnTagMaxSize
	case UniEnsBlockReqTag:
		return UniEnsBlockReqTagMaxSize
	case VoteBundleTag:
		return VoteBundleTagMaxSize
	default:
		return 0 // Unknown tag
	}
}

// TagList is a list of all currently used protocol tags.
var TagList = []Tag{
	AgreementVoteTag,
	MsgOfInterestTag,
	MsgDigestSkipTag,
	NetIDVerificationTag,
	NetPrioResponseTag,
	PingTag,
	PingReplyTag,
	ProposalPayloadTag,
	StateProofSigTag,
	TopicMsgRespTag,
	TxnTag,
	UniEnsBlockReqTag,
	VoteBundleTag,
}

// TagMap is a map of all currently used protocol tags.
var TagMap map[Tag]struct{}

func init() {
	TagMap = make(map[Tag]struct{})
	for _, tag := range TagList {
		TagMap[tag] = struct{}{}
	}
}