github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/message/init.go (about) 1 package message 2 3 import ( 4 "fmt" 5 ) 6 7 var ( 8 // validationExclusionList list of messages that are allowed to have more than 1 configured allowed protocol. 9 validationExclusionList = []string{TestMessage} 10 ) 11 12 // init is called first time this package is imported. 13 // It creates and initializes AuthorizationConfigs for each message type. 14 func init() { 15 initializeMessageAuthConfigsMap() 16 validateMessageAuthConfigsMap(validationExclusionList) 17 } 18 19 // validateMessageAuthConfigsMap ensures that each message authorization config has exactly one configured AllowedProtocol either pubsub or unicast. 20 // This is due to the fact that currently there are no messages that are used with both protocols aside from TestMessage. 21 func validateMessageAuthConfigsMap(excludeList []string) { 22 for _, msgAuthConf := range authorizationConfigs { 23 if excludeConfig(msgAuthConf.Name, excludeList) { 24 continue 25 } 26 27 for _, config := range msgAuthConf.Config { 28 if len(config.AllowedProtocols) != 1 { 29 panic(fmt.Errorf("error: message authorization config for message type %s should have a single allowed protocol found %d: %s", msgAuthConf.Name, len(config.AllowedProtocols), config.AllowedProtocols)) 30 } 31 } 32 } 33 } 34 35 func excludeConfig(name string, excludeList []string) bool { 36 for _, s := range excludeList { 37 if s == name { 38 return true 39 } 40 } 41 42 return false 43 } 44 45 // string constants for all message types sent on the network 46 const ( 47 BlockProposal = "BlockProposal" 48 BlockVote = "BlockVote" 49 TimeoutObject = "Timeout" 50 SyncRequest = "SyncRequest" 51 SyncResponse = "SyncResponse" 52 RangeRequest = "RangeRequest" 53 BatchRequest = "BatchRequest" 54 BlockResponse = "BlockResponse" 55 ClusterBlockProposal = "ClusterBlockProposal" 56 ClusterBlockVote = "ClusterBlockVote" 57 ClusterTimeoutObject = "ClusterTimeout" 58 ClusterBlockResponse = "ClusterBlockResponse" 59 CollectionGuarantee = "CollectionGuarantee" 60 TransactionBody = "TransactionBody" 61 ExecutionReceipt = "ExecutionReceipt" 62 ResultApproval = "ResultApproval" 63 ChunkDataRequest = "ChunkDataRequest" 64 ChunkDataResponse = "ChunkDataResponse" 65 ApprovalRequest = "ApprovalRequest" 66 ApprovalResponse = "ApprovalResponse" 67 EntityRequest = "EntityRequest" 68 EntityResponse = "EntityResponse" 69 TestMessage = "TestMessage" 70 DKGMessage = "DKGMessage" 71 )