2017-11-03 20:29:49 +00:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/*
|
|
|
|
Package whisper implements the Whisper protocol (version 6).
|
|
|
|
|
|
|
|
Whisper combines aspects of both DHTs and datagram messaging systems (e.g. UDP).
|
|
|
|
As such it may be likened and compared to both, not dissimilar to the
|
|
|
|
matter/energy duality (apologies to physicists for the blatant abuse of a
|
|
|
|
fundamental and beautiful natural principle).
|
|
|
|
|
|
|
|
Whisper is a pure identity-based messaging system. Whisper provides a low-level
|
|
|
|
(non-application-specific) but easily-accessible API without being based upon
|
|
|
|
or prejudiced by the low-level hardware attributes and characteristics,
|
|
|
|
particularly the notion of singular endpoints.
|
|
|
|
*/
|
2018-01-26 11:45:10 +00:00
|
|
|
|
|
|
|
// Contains the Whisper protocol constant definitions
|
|
|
|
|
2017-11-03 20:29:49 +00:00
|
|
|
package whisperv6
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-01-26 11:45:10 +00:00
|
|
|
// Whisper protocol parameters
|
2017-11-03 20:29:49 +00:00
|
|
|
const (
|
2018-01-26 11:45:10 +00:00
|
|
|
ProtocolVersion = uint64(6) // Protocol version number
|
|
|
|
ProtocolVersionStr = "6.0" // The same, as a string
|
|
|
|
ProtocolName = "shh" // Nickname of the protocol in geth
|
2017-11-03 20:29:49 +00:00
|
|
|
|
2017-12-21 14:17:27 +00:00
|
|
|
// whisper protocol message codes, according to EIP-627
|
|
|
|
statusCode = 0 // used by whisper protocol
|
|
|
|
messagesCode = 1 // normal whisper message
|
|
|
|
powRequirementCode = 2 // PoW requirement
|
|
|
|
bloomFilterExCode = 3 // bloom filter exchange
|
|
|
|
p2pRequestCode = 126 // peer-to-peer message, used by Dapp protocol
|
|
|
|
p2pMessageCode = 127 // peer-to-peer message (to be consumed by the peer, but not forwarded any further)
|
2017-12-08 10:40:59 +00:00
|
|
|
NumberOfMessageCodes = 128
|
2017-11-03 20:29:49 +00:00
|
|
|
|
2018-01-30 08:55:08 +00:00
|
|
|
SizeMask = byte(3) // mask used to extract the size of payload size field from the flags
|
2017-11-03 20:29:49 +00:00
|
|
|
signatureFlag = byte(4)
|
|
|
|
|
2018-01-12 11:11:22 +00:00
|
|
|
TopicLength = 4 // in bytes
|
|
|
|
signatureLength = 65 // in bytes
|
|
|
|
aesKeyLength = 32 // in bytes
|
2018-01-30 08:55:08 +00:00
|
|
|
aesNonceLength = 12 // in bytes; for more info please see cipher.gcmStandardNonceSize & aesgcm.NonceSize()
|
2018-01-26 11:45:10 +00:00
|
|
|
keyIDSize = 32 // in bytes
|
2018-03-01 15:04:09 +00:00
|
|
|
BloomFilterSize = 64 // in bytes
|
2018-01-30 08:55:08 +00:00
|
|
|
flagsLength = 1
|
2018-01-12 11:11:22 +00:00
|
|
|
|
|
|
|
EnvelopeHeaderLength = 20
|
2017-11-03 20:29:49 +00:00
|
|
|
|
|
|
|
MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message.
|
|
|
|
DefaultMaxMessageSize = uint32(1024 * 1024)
|
|
|
|
DefaultMinimumPoW = 0.2
|
|
|
|
|
2018-01-30 08:55:08 +00:00
|
|
|
padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol
|
2017-11-03 20:29:49 +00:00
|
|
|
messageQueueLimit = 1024
|
|
|
|
|
|
|
|
expirationCycle = time.Second
|
|
|
|
transmissionCycle = 300 * time.Millisecond
|
|
|
|
|
2018-01-12 11:11:22 +00:00
|
|
|
DefaultTTL = 50 // seconds
|
|
|
|
DefaultSyncAllowance = 10 // seconds
|
2017-11-03 20:29:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MailServer represents a mail server, capable of
|
|
|
|
// archiving the old messages for subsequent delivery
|
|
|
|
// to the peers. Any implementation must ensure that both
|
|
|
|
// functions are thread-safe. Also, they must return ASAP.
|
|
|
|
// DeliverMail should use directMessagesCode for delivery,
|
|
|
|
// in order to bypass the expiry checks.
|
|
|
|
type MailServer interface {
|
|
|
|
Archive(env *Envelope)
|
|
|
|
DeliverMail(whisperPeer *Peer, request *Envelope)
|
|
|
|
}
|