shhext

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: MPL-2.0 Imports: 24 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)
	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) 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)

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 (
	// 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 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.
	Topic whisper.TopicType `json:"topic"`

	// SymKeyID is an ID of a symmetric key to authenticate to MailServer.
	// It's derived from MailServer password.
	//
	// It's also possible to authenticate request with MailServerPeer
	// public key.
	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"`
}

MessagesRequest is a payload send to a MailServer to get messages.

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) GetNewFilterMessages

func (api *PublicAPI) GetNewFilterMessages(filterID string) ([]*whisper.Message, 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) 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) SendGroupMessage added in v0.15.1

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

SendGroupMessage sends a group messag chat message to the underlying transport

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

type Service

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

Service is a service that provides some additional Whisper API.

func New

func New(w *whisper.Whisper, handler EnvelopeEventsHandler, db *leveldb.DB, config *ServiceConfig) *Service

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) GetBundle added in v0.15.1

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

func (*Service) InitProtocol added in v0.15.1

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

InitProtocol create an instance of ProtocolService given an address and password

func (*Service) ProcessPublicBundle added in v0.15.1

func (s *Service) ProcessPublicBundle(myIdentityKey *ecdsa.PrivateKey, bundle *chat.Bundle) 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.

type ServiceConfig added in v0.15.1

type ServiceConfig struct {
	DataDir        string
	InstallationID string
	Debug          bool
	PFSEnabled     bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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