github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/whisper/whisperv5/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 5). 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 package whisperv5 26 27 import ( 28 "fmt" 29 "time" 30 ) 31 32 const ( 33 EnvelopeVersion = uint64(0) 34 ProtocolVersion = uint64(5) 35 ProtocolVersionStr = "5.0" 36 ProtocolName = "shh" 37 38 statusCode = 0 // used by whisper protocol 39 messagesCode = 1 // normal whisper message 40 p2pCode = 2 // peer-to-peer message (to be consumed by the peer, but not forwarded any further) 41 p2pRequestCode = 3 // peer-to-peer message, used by Dapp protocol 42 NumberOfMessageCodes = 64 43 44 paddingMask = byte(3) 45 signatureFlag = byte(4) 46 47 TopicLength = 4 48 signatureLength = 65 49 aesKeyLength = 32 50 AESNonceLength = 12 51 keyIdSize = 32 52 53 MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message. 54 DefaultMaxMessageSize = uint32(1024 * 1024) 55 DefaultMinimumPoW = 0.2 56 57 padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol (must not exceed 2^24) 58 messageQueueLimit = 1024 59 60 expirationCycle = time.Second 61 transmissionCycle = 300 * time.Millisecond 62 63 DefaultTTL = 50 // seconds 64 SynchAllowance = 10 // seconds 65 ) 66 67 type unknownVersionError uint64 68 69 func (e unknownVersionError) Error() string { 70 return fmt.Sprintf("invalid envelope version %d", uint64(e)) 71 } 72 73 // MailServer represents a mail server, capable of 74 // archiving the old messages for subsequent delivery 75 // to the peers. Any implementation must ensure that both 76 // functions are thread-safe. Also, they must return ASAP. 77 // DeliverMail should use directMessagesCode for delivery, 78 // in order to bypass the expiry checks. 79 type MailServer interface { 80 Archive(env *Envelope) 81 DeliverMail(whisperPeer *Peer, request *Envelope) 82 }