github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/whisper/whisperv6/doc.go (about)

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