github.com/annchain/OG@v0.0.9/og/message_type.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package og 15 16 import "fmt" 17 18 ////go:generate msgp 19 20 const ( 21 OG01 = 01 22 OG02 = 02 23 ) 24 25 // ProtocolName is the official short name of the protocol used during capability negotiation. 26 var ProtocolName = "og" 27 28 // ProtocolVersions are the supported versions of the og protocol (first is primary). 29 var ProtocolVersions = []uint32{OG02, OG01} 30 31 // ProtocolLengths are the number of implemented Message corresponding to different protocol versions. 32 //var ProtocolLengths = []message.typesType{message.MessageTypeOg02Length, message.MessageTypeOg01Length} 33 34 const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol Message 35 36 37 type ErrCode int 38 39 const ( 40 ErrMsgTooLarge = iota 41 ErrDecode 42 ErrInvalidMsgCode 43 ErrProtocolVersionMismatch 44 ErrNetworkIdMismatch 45 ErrGenesisBlockMismatch 46 ErrNoStatusMsg 47 ErrExtraStatusMsg 48 ErrSuspendedPeer 49 ) 50 51 func (e ErrCode) String() string { 52 return errorToString[int(e)] 53 } 54 55 func ErrResp(code ErrCode, format string, v ...interface{}) error { 56 return fmt.Errorf("%v - %v", code, fmt.Sprintf(format, v...)) 57 } 58 59 // XXX change once legacy code is out 60 var errorToString = map[int]string{ 61 ErrMsgTooLarge: "Message too long", 62 ErrDecode: "Invalid message", 63 ErrInvalidMsgCode: "Invalid message code", 64 ErrProtocolVersionMismatch: "Protocol version mismatch", 65 ErrNetworkIdMismatch: "NetworkId mismatch", 66 ErrGenesisBlockMismatch: "Genesis block mismatch", 67 ErrNoStatusMsg: "No status message", 68 ErrExtraStatusMsg: "Extra status message", 69 ErrSuspendedPeer: "Suspended peer", 70 }