github.com/mandrigin/go-ethereum@v1.7.4-0.20180116162341-02aeb3d76652/whisper/whisperv6/doc.go (about)

     1  // Copyright 2016 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  /*
    18  Package whisper implements the Whisper protocol (version 6).
    19  
    20  Whisper combines aspects of both DHTs and datagram messaging systems (e.g. UDP).
    21  As such it may be likened and compared to both, not dissimilar to the
    22  matter/energy duality (apologies to physicists for the blatant abuse of a
    23  fundamental and beautiful natural principle).
    24  
    25  Whisper is a pure identity-based messaging system. Whisper provides a low-level
    26  (non-application-specific) but easily-accessible API without being based upon
    27  or prejudiced by the low-level hardware attributes and characteristics,
    28  particularly the notion of singular endpoints.
    29  */
    30  package whisperv6
    31  
    32  import (
    33  	"fmt"
    34  	"time"
    35  )
    36  
    37  const (
    38  	ProtocolVersion    = uint64(6)
    39  	ProtocolVersionStr = "6.0"
    40  	ProtocolName       = "shh"
    41  
    42  	// whisper protocol message codes, according to EIP-627
    43  	statusCode           = 0   // used by whisper protocol
    44  	messagesCode         = 1   // normal whisper message
    45  	powRequirementCode   = 2   // PoW requirement
    46  	bloomFilterExCode    = 3   // bloom filter exchange
    47  	p2pRequestCode       = 126 // peer-to-peer message, used by Dapp protocol
    48  	p2pMessageCode       = 127 // peer-to-peer message (to be consumed by the peer, but not forwarded any further)
    49  	NumberOfMessageCodes = 128
    50  
    51  	paddingMask   = byte(3)
    52  	signatureFlag = byte(4)
    53  
    54  	TopicLength     = 4  // in bytes
    55  	signatureLength = 65 // in bytes
    56  	aesKeyLength    = 32 // in bytes
    57  	AESNonceLength  = 12 // in bytes
    58  	keyIdSize       = 32 // in bytes
    59  	bloomFilterSize = 64 // in bytes
    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 (must not exceed 2^24)
    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  }