github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/whisper/whisperv6/doc.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 /* 13 Package whisper implements the Whisper protocol (version 6). 14 15 Whisper combines aspects of both DHTs and datagram messaging systems (e.g. UDP). 16 As such it may be likened and compared to both, not dissimilar to the 17 matter/energy duality (apologies to physicists for the blatant abuse of a 18 fundamental and beautiful natural principle). 19 20 Whisper is a pure identity-based messaging system. Whisper provides a low-level 21 (non-application-specific) but easily-accessible API without being based upon 22 or prejudiced by the low-level hardware attributes and characteristics, 23 particularly the notion of singular endpoints. 24 */ 25 26 // Contains the Whisper protocol constant definitions 27 28 package whisperv6 29 30 import ( 31 "fmt" 32 "time" 33 ) 34 35 // Whisper protocol parameters 36 const ( 37 ProtocolVersion = uint64(6) // Protocol version number 38 ProtocolVersionStr = "6.0" // The same, as a string 39 ProtocolName = "shh" // Nickname of the protocol in geth 40 41 // whisper protocol message codes, according to EIP-627 42 statusCode = 0 // used by whisper protocol 43 messagesCode = 1 // normal whisper message 44 powRequirementCode = 2 // PoW requirement 45 bloomFilterExCode = 3 // bloom filter exchange 46 p2pRequestCode = 126 // peer-to-peer message, used by Dapp protocol 47 p2pMessageCode = 127 // peer-to-peer message (to be consumed by the peer, but not forwarded any further) 48 NumberOfMessageCodes = 128 49 50 SizeMask = byte(3) // mask used to extract the size of payload size field from the flags 51 signatureFlag = byte(4) 52 53 TopicLength = 4 // in bytes 54 signatureLength = 65 // in bytes 55 aesKeyLength = 32 // in bytes 56 aesNonceLength = 12 // in bytes; for more info please see cipher.gcmStandardNonceSize & aesgcm.NonceSize() 57 keyIDSize = 32 // in bytes 58 bloomFilterSize = 64 // in bytes 59 flagsLength = 1 60 61 EnvelopeHeaderLength = 20 62 63 MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message. 64 DefaultMaxMessageSize = uint32(1024 * 1024) 65 DefaultMinimumPoW = 0.2 66 67 padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol 68 messageQueueLimit = 1024 69 70 expirationCycle = time.Second 71 transmissionCycle = 300 * time.Millisecond 72 73 DefaultTTL = 50 // seconds 74 DefaultSyncAllowance = 10 // seconds 75 ) 76 77 type unknownVersionError uint64 78 79 func (e unknownVersionError) Error() string { 80 return fmt.Sprintf("invalid envelope version %d", uint64(e)) 81 } 82 83 // MailServer represents a mail server, capable of 84 // archiving the old messages for subsequent delivery 85 // to the peers. Any implementation must ensure that both 86 // functions are thread-safe. Also, they must return ASAP. 87 // DeliverMail should use directMessagesCode for delivery, 88 // in order to bypass the expiry checks. 89 type MailServer interface { 90 Archive(env *Envelope) 91 DeliverMail(whisperPeer *Peer, request *Envelope) 92 }