github.com/koko1123/flow-go-1@v0.29.6/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 SyncRequest = "SyncRequest" 50 SyncResponse = "SyncResponse" 51 RangeRequest = "RangeRequest" 52 BatchRequest = "BatchRequest" 53 BlockResponse = "BlockResponse" 54 ClusterBlockProposal = "ClusterBlockProposal" 55 ClusterBlockVote = "ClusterBlockVote" 56 ClusterBlockResponse = "ClusterBlockResponse" 57 CollectionGuarantee = "CollectionGuarantee" 58 TransactionBody = "TransactionBody" 59 ExecutionReceipt = "ExecutionReceipt" 60 ResultApproval = "ResultApproval" 61 ChunkDataRequest = "ChunkDataRequest" 62 ChunkDataResponse = "ChunkDataResponse" 63 ApprovalRequest = "ApprovalRequest" 64 ApprovalResponse = "ApprovalResponse" 65 EntityRequest = "EntityRequest" 66 EntityResponse = "EntityResponse" 67 TestMessage = "TestMessage" 68 DKGMessage = "DKGMessage" 69 )