shhext

package
v0.23.0-beta.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2019 License: MPL-2.0 Imports: 30 Imported by: 0

README

Whisper API Extension

API

shhext_getNewFilterMessages

Accepts the same input as shh_getFilterMessages.

Returns

Returns a list of whisper messages matching the specified filter. Filters out the messages already confirmed received by shhext_confirmMessagesProcessed

Deduplication is made using the whisper envelope content and topic only, so the same content received in different whisper envelopes will be deduplicated.

shhext_confirmMessagesProcessed

Confirms whisper messages received and processed on the client side. These messages won't appear anymore when shhext_getNewFilterMessages is called.

Parameters

Gets a list of whisper envelopes.

shhext_post

Accepts same input as shh_post.

Returns

DATA, 32 Bytes - the envelope hash

shhext_requestMessages

Sends a request for historic messages to a mail server.

Parameters
  1. Object - The message request object:
  • mailServerPeer:URL - Mail servers' enode addess
  • from:QUANTITY - (optional) Lower bound of time range as unix timestamp, default is 24 hours back from now
  • to:QUANTITY- (optional) Upper bound of time range as unix timestamp, default is now
  • topic:DATA, 4 Bytes - Regular whisper topic
  • symKeyID:DATA- ID of a symmetric key to authenticate to mail server, derived from mail server password
Returns

Boolean - returns true if the request was send, otherwise false.

Signals

Sends sent signal once per envelope.

{
  "type": "envelope.sent",
  "event": {
    "hash": "0xea0b93079ed32588628f1cabbbb5ed9e4d50b7571064c2962c3853972db67790"
  }
}

Sends expired signal if envelope dropped from whisper local queue before it was sent to any peer on the network.

{
  "type": "envelope.expired",
  "event": {
    "hash": "0x754f4c12dccb14886f791abfeb77ffb86330d03d5a4ba6f37a8c21281988b69e"
  }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMailServerPeer is returned when it fails to parse enode from params.
	ErrInvalidMailServerPeer = errors.New("invalid mailServerPeer value")
	// ErrInvalidSymKeyID is returned when it fails to get a symmetric key.
	ErrInvalidSymKeyID = errors.New("invalid symKeyID value")
	// ErrInvalidPublicKey is returned when public key can't be extracted
	// from MailServer's nodeID.
	ErrInvalidPublicKey = errors.New("can't extract public key")
	// ErrPFSNotEnabled is returned when an endpoint PFS only is called but
	// PFS is disabled
	ErrPFSNotEnabled = errors.New("pfs not enabled")
)

Functions

This section is empty.

Types

type DebugAPI

type DebugAPI struct {
	// contains filtered or unexported fields
}

DebugAPI represents a set of APIs from the `web3.debug` namespace.

func NewDebugAPI

func NewDebugAPI(s *Service) *DebugAPI

NewDebugAPI creates an instance of the debug API.

func (*DebugAPI) PostSync

func (api *DebugAPI) PostSync(ctx context.Context, req whisper.NewMessage) (hash hexutil.Bytes, err error)

PostSync sends an envelope through shhext_post and waits until it's sent.

type EnvelopeEventsHandler

type EnvelopeEventsHandler interface {
	EnvelopeSent(common.Hash)
	EnvelopeExpired(common.Hash)
	MailServerRequestCompleted(common.Hash, common.Hash, []byte, error)
	MailServerRequestExpired(common.Hash)
}

EnvelopeEventsHandler used for two different event types.

type EnvelopeSignalHandler

type EnvelopeSignalHandler struct{}

EnvelopeSignalHandler sends signals when envelope is sent or expired.

func (EnvelopeSignalHandler) BundleAdded added in v0.16.4

func (h EnvelopeSignalHandler) BundleAdded(identity string, installationID string)

func (EnvelopeSignalHandler) DecryptMessageFailed added in v0.15.1

func (h EnvelopeSignalHandler) DecryptMessageFailed(pubKey string)

func (EnvelopeSignalHandler) EnvelopeExpired

func (h EnvelopeSignalHandler) EnvelopeExpired(hash common.Hash)

EnvelopeExpired triggered when envelope is expired but wasn't delivered to any peer.

func (EnvelopeSignalHandler) EnvelopeSent

func (h EnvelopeSignalHandler) EnvelopeSent(hash common.Hash)

EnvelopeSent triggered when envelope delivered atleast to 1 peer.

func (EnvelopeSignalHandler) MailServerRequestCompleted

func (h EnvelopeSignalHandler) MailServerRequestCompleted(requestID common.Hash, lastEnvelopeHash common.Hash, cursor []byte, err error)

MailServerRequestCompleted triggered when the mailserver sends a message to notify that the request has been completed

func (EnvelopeSignalHandler) MailServerRequestExpired

func (h EnvelopeSignalHandler) MailServerRequestExpired(hash common.Hash)

MailServerRequestExpired triggered when the mailserver request expires

type EnvelopeState

type EnvelopeState int

EnvelopeState in local tracker

const (
	// NotRegistered returned if asked hash wasn't registered in the tracker.
	NotRegistered EnvelopeState = -1
	// EnvelopePosted is set when envelope was added to a local whisper queue.
	EnvelopePosted EnvelopeState = iota
	// EnvelopeSent is set when envelope is sent to atleast one peer.
	EnvelopeSent
	// MailServerRequestSent is set when p2p request is sent to the mailserver
	MailServerRequestSent
)

type EnvelopesMonitor

type EnvelopesMonitor struct {
	// contains filtered or unexported fields
}

EnvelopesMonitor is responsible for monitoring whisper envelopes state.

func (*EnvelopesMonitor) Add

func (m *EnvelopesMonitor) Add(hash common.Hash)

Add hash to a tracker.

func (*EnvelopesMonitor) GetState

func (m *EnvelopesMonitor) GetState(hash common.Hash) EnvelopeState

func (*EnvelopesMonitor) Start

func (m *EnvelopesMonitor) Start()

Start processing events.

func (*EnvelopesMonitor) Stop

func (m *EnvelopesMonitor) Stop()

Stop process events.

type MailRequestMonitor added in v0.35.0

type MailRequestMonitor struct {
	// contains filtered or unexported fields
}

MailRequestMonitor is responsible for monitoring history request to mailservers.

func (*MailRequestMonitor) GetState added in v0.35.0

func (m *MailRequestMonitor) GetState(hash common.Hash) EnvelopeState

func (*MailRequestMonitor) Start added in v0.35.0

func (m *MailRequestMonitor) Start()

Start processing events.

func (*MailRequestMonitor) Stop added in v0.35.0

func (m *MailRequestMonitor) Stop()

Stop process events.

type MessagesRequest

type MessagesRequest struct {
	// MailServerPeer is MailServer's enode address.
	MailServerPeer string `json:"mailServerPeer"`

	// From is a lower bound of time range (optional).
	// Default is 24 hours back from now.
	From uint32 `json:"from"`

	// To is a upper bound of time range (optional).
	// Default is now.
	To uint32 `json:"to"`

	// Limit determines the number of messages sent by the mail server
	// for the current paginated request
	Limit uint32 `json:"limit"`

	// Cursor is used as starting point for paginated requests
	Cursor string `json:"cursor"`

	// Topic is a regular Whisper topic.
	// DEPRECATED
	Topic whisper.TopicType `json:"topic"`

	// Topics is a list of Whisper topics.
	Topics []whisper.TopicType `json:"topics"`

	// SymKeyID is an ID of a symmetric key to authenticate to MailServer.
	// It's derived from MailServer password.
	SymKeyID string `json:"symKeyID"`

	// Timeout is the time to live of the request specified in seconds.
	// Default is 10 seconds
	Timeout time.Duration `json:"timeout"`

	// Force ensures that requests will bypass enforced delay.
	Force bool `json:"force"`
}

MessagesRequest is a RequestMessages() request payload.

type PublicAPI

type PublicAPI struct {
	// contains filtered or unexported fields
}

PublicAPI extends whisper public API.

func NewPublicAPI

func NewPublicAPI(s *Service) *PublicAPI

NewPublicAPI returns instance of the public API.

func (*PublicAPI) ConfirmMessagesProcessed

func (api *PublicAPI) ConfirmMessagesProcessed(messages []*whisper.Message) error

ConfirmMessagesProcessed is a method to confirm that messages was consumed by the client side.

func (*PublicAPI) ConfirmMessagesProcessedByID added in v0.35.0

func (api *PublicAPI) ConfirmMessagesProcessedByID(messageIDs [][]byte) error

ConfirmMessagesProcessedByID is a method to confirm that messages was consumed by the client side.

func (*PublicAPI) GetNewFilterMessages

func (api *PublicAPI) GetNewFilterMessages(filterID string) ([]dedup.DeduplicateMessage, error)

GetNewFilterMessages is a prototype method with deduplication

func (*PublicAPI) Post

func (api *PublicAPI) Post(ctx context.Context, req whisper.NewMessage) (hash hexutil.Bytes, err error)

Post shamelessly copied from whisper codebase with slight modifications.

func (*PublicAPI) RequestMessages

func (api *PublicAPI) RequestMessages(_ context.Context, r MessagesRequest) (hexutil.Bytes, error)

RequestMessages sends a request for historic messages to a MailServer.

func (*PublicAPI) RequestMessagesSync added in v0.35.0

func (api *PublicAPI) RequestMessagesSync(conf RetryConfig, r MessagesRequest) error

RequestMessagesSync repeats MessagesRequest using configuration in retry conf.

func (*PublicAPI) SendDirectMessage added in v0.15.1

func (api *PublicAPI) SendDirectMessage(ctx context.Context, msg chat.SendDirectMessageRPC) (hexutil.Bytes, error)

SendDirectMessage sends a 1:1 chat message to the underlying transport

func (*PublicAPI) SendPairingMessage added in v0.16.4

func (api *PublicAPI) SendPairingMessage(ctx context.Context, msg chat.SendDirectMessageRPC) ([]hexutil.Bytes, error)

DEPRECATED: use SendDirectMessage with DH flag SendPairingMessage sends a 1:1 chat message to our own devices to initiate a pairing session

func (*PublicAPI) SendPublicMessage added in v0.15.1

func (api *PublicAPI) SendPublicMessage(ctx context.Context, msg chat.SendPublicMessageRPC) (hexutil.Bytes, error)

SendPublicMessage sends a public chat message to the underlying transport

func (*PublicAPI) SyncMessages added in v0.35.0

SyncMessages sends a request to a given MailServerPeer to sync historic messages. MailServerPeers needs to be added as a trusted peer first.

type RequestsRegistry added in v0.35.0

type RequestsRegistry struct {
	// contains filtered or unexported fields
}

RequestsRegistry keeps map for all requests with timestamp when they were made.

func NewRequestsRegistry added in v0.35.0

func NewRequestsRegistry(delay time.Duration) *RequestsRegistry

NewRequestsRegistry creates instance of the RequestsRegistry and returns pointer to it.

func (*RequestsRegistry) Clear added in v0.35.0

func (r *RequestsRegistry) Clear()

Clear recreates all structures used for caching requests.

func (*RequestsRegistry) Register added in v0.35.0

func (r *RequestsRegistry) Register(uid common.Hash, topics []whisper.TopicType) error

Register request with given topics. If request with same topics was made in less then configured delay then error will be returned.

func (*RequestsRegistry) Unregister added in v0.35.0

func (r *RequestsRegistry) Unregister(uid common.Hash)

Unregister removes request with given UID from registry.

type RetryConfig added in v0.35.0

type RetryConfig struct {
	BaseTimeout time.Duration
	// StepTimeout defines duration increase per each retry.
	StepTimeout time.Duration
	MaxRetries  int
}

RetryConfig specifies configuration for retries with timeout and max amount of retries.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a service that provides some additional Whisper API.

func New

New returns a new Service. dataDir is a folder path to a network-independent location

func (*Service) APIs

func (s *Service) APIs() []rpc.API

APIs returns a list of new APIs.

func (*Service) DisableInstallation added in v0.35.0

func (s *Service) DisableInstallation(myIdentityKey *ecdsa.PublicKey, installationID string) error

DisableInstallation disables an installation for multi-device sync.

func (*Service) EnableInstallation added in v0.35.0

func (s *Service) EnableInstallation(myIdentityKey *ecdsa.PublicKey, installationID string) error

EnableInstallation enables an installation for multi-device sync.

func (*Service) GetBundle added in v0.15.1

func (s *Service) GetBundle(myIdentityKey *ecdsa.PrivateKey) (*chat.Bundle, error)

func (*Service) GetPublicBundle

func (s *Service) GetPublicBundle(identityKey *ecdsa.PublicKey) (*chat.Bundle, error)

func (*Service) InitProtocolWithEncyptionKey

func (s *Service) InitProtocolWithEncyptionKey(address string, encKey string) error

InitProtocolWithEncyptionKey creates an instance of ProtocolService given an address and encryption key.

func (*Service) InitProtocolWithPassword

func (s *Service) InitProtocolWithPassword(address string, password string) error

InitProtocolWithPassword creates an instance of ProtocolService given an address and password used to generate an encryption key.

func (*Service) ProcessPublicBundle added in v0.15.1

func (s *Service) ProcessPublicBundle(myIdentityKey *ecdsa.PrivateKey, bundle *chat.Bundle) ([]chat.IdentityAndIDPair, error)

func (*Service) Protocols

func (s *Service) Protocols() []p2p.Protocol

Protocols returns a new protocols list. In this case, there are none.

func (*Service) Start

func (s *Service) Start(server *p2p.Server) error

Start is run when a service is started. It does nothing in this case but is required by `node.Service` interface.

func (*Service) Stop

func (s *Service) Stop() error

Stop is run when a service is stopped. It does nothing in this case but is required by `node.Service` interface.

func (*Service) UpdateMailservers added in v0.35.0

func (s *Service) UpdateMailservers(nodes []*enode.Node) error

UpdateMailservers updates information about selected mail servers.

type SyncMessagesRequest added in v0.35.0

type SyncMessagesRequest struct {
	// MailServerPeer is MailServer's enode address.
	MailServerPeer string `json:"mailServerPeer"`

	// From is a lower bound of time range (optional).
	// Default is 24 hours back from now.
	From uint32 `json:"from"`

	// To is a upper bound of time range (optional).
	// Default is now.
	To uint32 `json:"to"`

	// Limit determines the number of messages sent by the mail server
	// for the current paginated request
	Limit uint32 `json:"limit"`

	// Cursor is used as starting point for paginated requests
	Cursor string `json:"cursor"`

	// Topics is a list of Whisper topics.
	// If empty, a full bloom filter will be used.
	Topics []whisper.TopicType `json:"topics"`
}

SyncMessagesRequest is a SyncMessages() request payload.

type SyncMessagesResponse added in v0.35.0

type SyncMessagesResponse struct {
	// Cursor from the response can be used to retrieve more messages
	// for the previous request.
	Cursor string `json:"cursor"`

	// Error indicates that something wrong happened when sending messages
	// to the requester.
	Error string `json:"error"`
}

SyncMessagesResponse is a response from the mail server to which SyncMessagesRequest was sent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL