Documentation ¶
Overview ¶
Package whisper implements the Whisper protocol (version 5).
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.
Index ¶
- Constants
- func BytesToIntBigEndian(b []byte) (res uint64)
- func DeriveOneTimeKey(key []byte, salt []byte, version uint64) ([]byte, error)
- func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool
- func ValidatePublicKey(k *ecdsa.PublicKey) bool
- type Envelope
- func (e *Envelope) DecodeRLP(s *rlp.Stream) error
- func (e *Envelope) Hash() common.Hash
- func (e *Envelope) IsSymmetric() bool
- func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage)
- func (e *Envelope) OpenAsymmetric(key *ecdsa.PrivateKey) (*ReceivedMessage, error)
- func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error)
- func (e *Envelope) PoW() float64
- func (e *Envelope) Seal(options *MessageParams) error
- func (e *Envelope) Ver() uint64
- type Filter
- type Filters
- type MailServer
- type MessageParams
- type Peer
- type ReceivedMessage
- type SentMessage
- type TopicType
- type Whisper
- func (w *Whisper) AddSymKey(name string, key []byte) error
- func (w *Whisper) DeleteIdentity(key string)
- func (w *Whisper) DeleteSymKey(name string)
- func (w *Whisper) Envelopes() []*Envelope
- func (w *Whisper) GenerateSymKey(name string) error
- func (w *Whisper) GetFilter(id uint32) *Filter
- func (w *Whisper) GetIdentity(pubKey string) *ecdsa.PrivateKey
- func (w *Whisper) GetSymKey(name string) []byte
- func (wh *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error
- func (w *Whisper) HasIdentity(pubKey string) bool
- func (w *Whisper) HasSymKey(name string) bool
- func (w *Whisper) MarkPeerTrusted(peerID []byte) error
- func (w *Whisper) Messages(id uint32) []*ReceivedMessage
- func (w *Whisper) NewIdentity() *ecdsa.PrivateKey
- func (w *Whisper) Protocols() []p2p.Protocol
- func (w *Whisper) RequestHistoricMessages(peerID []byte, envelope *Envelope) error
- func (w *Whisper) Send(envelope *Envelope) error
- func (w *Whisper) SendP2PDirect(peer *Peer, envelope *Envelope) error
- func (w *Whisper) SendP2PMessage(peerID []byte, envelope *Envelope) error
- func (w *Whisper) Start(*p2p.Server) error
- func (w *Whisper) Stop() error
- func (w *Whisper) Unwatch(id uint32)
- func (w *Whisper) Version() uint
- func (w *Whisper) Watch(f *Filter) uint32
Constants ¶
const ( EnvelopeVersion = uint64(0) ProtocolVersion = uint64(5) ProtocolVersionStr = "5.0" ProtocolName = "shh" NumberOfMessageCodes = 64 TopicLength = 4 AESNonceMaxLength = 12 MaxMessageLength = 0xFFFF // todo: remove this restriction after testing. this should be regulated by PoW. MinimumPoW = 1.0 // todo: review after testing. DefaultTTL = 50 // seconds SynchAllowance = 10 // seconds )
Variables ¶
This section is empty.
Functions ¶
func BytesToIntBigEndian ¶
func DeriveOneTimeKey ¶
func IsPubKeyEqual ¶
func ValidatePublicKey ¶
Types ¶
type Envelope ¶
type Envelope struct { Version []byte Expiry uint32 TTL uint32 Topic TopicType Salt []byte AESNonce []byte Data []byte EnvNonce uint64 // contains filtered or unexported fields }
Envelope represents a clear-text data packet to transmit through the Whisper network. Its contents may or may not be encrypted and signed.
func NewEnvelope ¶
func NewEnvelope(ttl uint32, topic TopicType, salt []byte, aesNonce []byte, msg *SentMessage) *Envelope
NewEnvelope wraps a Whisper message with expiration and destination data included into an envelope for network forwarding.
func (*Envelope) IsSymmetric ¶
func (*Envelope) Open ¶
func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage)
Open tries to decrypt an envelope, and populates the message fields in case of success.
func (*Envelope) OpenAsymmetric ¶
func (e *Envelope) OpenAsymmetric(key *ecdsa.PrivateKey) (*ReceivedMessage, error)
OpenAsymmetric tries to decrypt an envelope, potentially encrypted with a particular key.
func (*Envelope) OpenSymmetric ¶
func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error)
OpenSymmetric tries to decrypt an envelope, potentially encrypted with a particular key.
func (*Envelope) Seal ¶
func (e *Envelope) Seal(options *MessageParams) error
Seal closes the envelope by spending the requested amount of time as a proof of work on hashing the data.
type Filter ¶
type Filter struct { Src *ecdsa.PublicKey // Sender of the message KeyAsym *ecdsa.PrivateKey // Private Key of recipient KeySym []byte // Key associated with the Topic Topics []TopicType // Topics to filter messages with PoW float64 // Proof of work as described in the Whisper spec AcceptP2P bool // Indicates whether this filter is interested in direct peer-to-peer messages SymKeyHash common.Hash // The Keccak256Hash of the symmetric key, needed for optimization Messages map[common.Hash]*ReceivedMessage // contains filtered or unexported fields }
func (*Filter) MatchEnvelope ¶
func (*Filter) MatchMessage ¶
func (f *Filter) MatchMessage(msg *ReceivedMessage) bool
func (*Filter) MatchTopic ¶
func (*Filter) Retrieve ¶
func (f *Filter) Retrieve() (all []*ReceivedMessage)
func (*Filter) Trigger ¶
func (f *Filter) Trigger(msg *ReceivedMessage)
type Filters ¶
type Filters struct {
// contains filtered or unexported fields
}
func NewFilters ¶
func (*Filters) NotifyWatchers ¶
type MailServer ¶
type MailServer interface { Archive(env *Envelope) DeliverMail(whisperPeer *Peer, request *Envelope) }
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 MessageParams ¶
type MessageParams struct { TTL uint32 Src *ecdsa.PrivateKey Dst *ecdsa.PublicKey KeySym []byte Topic TopicType WorkTime uint32 PoW float64 Payload []byte Padding []byte }
Options specifies the exact way a message should be wrapped into an Envelope.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
peer represents a whisper protocol peer connection.
type ReceivedMessage ¶
type ReceivedMessage struct { Raw []byte Payload []byte Padding []byte Signature []byte PoW float64 // Proof of work as described in the Whisper spec Sent uint32 // Time when the message was posted into the network TTL uint32 // Maximum time to live allowed for the message Src *ecdsa.PublicKey // Message recipient (identity used to decode the message) Dst *ecdsa.PublicKey // Message recipient (identity used to decode the message) Topic TopicType SymKeyHash common.Hash // The Keccak256Hash of the key, associated with the Topic EnvelopeHash common.Hash // Message envelope hash to act as a unique id EnvelopeVersion uint64 }
ReceivedMessage represents a data packet to be received through the Whisper protocol.
func (*ReceivedMessage) SigToPubKey ¶
func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey
Recover retrieves the public key of the message signer.
func (*ReceivedMessage) Validate ¶
func (msg *ReceivedMessage) Validate() bool
Validate checks the validity and extracts the fields in case of success
type SentMessage ¶
type SentMessage struct {
Raw []byte
}
SentMessage represents an end-user data packet to transmit through the Whisper protocol. These are wrapped into Envelopes that need not be understood by intermediate nodes, just forwarded.
func NewSentMessage ¶
func NewSentMessage(params *MessageParams) *SentMessage
NewMessage creates and initializes a non-signed, non-encrypted Whisper message.
func (*SentMessage) Wrap ¶
func (msg *SentMessage) Wrap(options *MessageParams) (envelope *Envelope, err error)
Wrap bundles the message into an Envelope to transmit over the network.
pow (Proof Of Work) controls how much time to spend on hashing the message, inherently controlling its priority through the network (smaller hash, bigger priority).
The user can control the amount of identity, privacy and encryption through the options parameter as follows:
- options.From == nil && options.To == nil: anonymous broadcast
- options.From != nil && options.To == nil: signed broadcast (known sender)
- options.From == nil && options.To != nil: encrypted anonymous message
- options.From != nil && options.To != nil: encrypted signed message
type TopicType ¶
type TopicType [TopicLength]byte
Topic represents a cryptographically secure, probabilistic partial classifications of a message, determined as the first (left) 4 bytes of the SHA3 hash of some arbitrary data given by the original author of the message.
func BytesToTopic ¶
func (*TopicType) UnmarshalJSON ¶
UnmarshalJSON parses a hex representation to a topic.
type Whisper ¶
type Whisper struct {
// contains filtered or unexported fields
}
Whisper represents a dark communication interface through the Ethereum network, using its very own P2P communication layer.
func NewWhisper ¶
func NewWhisper(server MailServer) *Whisper
New creates a Whisper client ready to communicate through the Ethereum P2P network. Param s should be passed if you want to implement mail server, otherwise nil.
func (*Whisper) DeleteIdentity ¶
DeleteIdentity deletes the specified key if it exists.
func (*Whisper) DeleteSymKey ¶
func (*Whisper) GenerateSymKey ¶
func (*Whisper) GetIdentity ¶
func (w *Whisper) GetIdentity(pubKey string) *ecdsa.PrivateKey
GetIdentity retrieves the private key of the specified public identity.
func (*Whisper) HandlePeer ¶
handlePeer is called by the underlying P2P layer when the whisper sub-protocol connection is negotiated.
func (*Whisper) HasIdentity ¶
HasIdentity checks if the the whisper node is configured with the private key of the specified public pair.
func (*Whisper) MarkPeerTrusted ¶
MarkPeerTrusted marks specific peer trusted, which will allow it to send historic (expired) messages.
func (*Whisper) Messages ¶
func (w *Whisper) Messages(id uint32) []*ReceivedMessage
Messages retrieves all the decrypted messages matching a filter id.
func (*Whisper) NewIdentity ¶
func (w *Whisper) NewIdentity() *ecdsa.PrivateKey
NewIdentity generates a new cryptographic identity for the client, and injects it into the known identities for message decryption.
func (*Whisper) Protocols ¶
Protocols returns the whisper sub-protocols ran by this particular client.
func (*Whisper) RequestHistoricMessages ¶
func (*Whisper) Send ¶
Send injects a message into the whisper send queue, to be distributed in the network in the coming cycles.
func (*Whisper) SendP2PDirect ¶ added in v1.5.11
func (*Whisper) SendP2PMessage ¶
func (*Whisper) Start ¶
Start implements node.Service, starting the background data propagation thread of the Whisper protocol.
func (*Whisper) Stop ¶
Stop implements node.Service, stopping the background data propagation thread of the Whisper protocol.