whisper

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMailservers returned if there is no configured mailservers that can be used.
	ErrNoMailservers = errors.New("no configured mailservers")
)

Functions

func ContactCodeTopic

func ContactCodeTopic(publicKey *ecdsa.PublicKey) string

func DefaultWhisperMessage

func DefaultWhisperMessage() types.NewMessage

func ToTopic

func ToTopic(s string) []byte

ToTopic converts a string to a whisper topic.

Types

type EnvelopeEventsHandler

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

EnvelopeEventsHandler used for two different event types.

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
)

type EnvelopesMonitor

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

EnvelopesMonitor is responsible for monitoring whisper envelopes state.

func NewEnvelopesMonitor

func NewEnvelopesMonitor(w types.Whisper, config EnvelopesMonitorConfig) *EnvelopesMonitor

NewEnvelopesMonitor returns a pointer to an instance of the EnvelopesMonitor.

func (*EnvelopesMonitor) Add

func (m *EnvelopesMonitor) Add(identifiers [][]byte, envelopeHash types.Hash, message types.NewMessage)

Add hash to a tracker.

func (*EnvelopesMonitor) GetState

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

func (*EnvelopesMonitor) Start

func (m *EnvelopesMonitor) Start()

Start processing events.

func (*EnvelopesMonitor) Stop

func (m *EnvelopesMonitor) Stop()

Stop process events.

type EnvelopesMonitorConfig

type EnvelopesMonitorConfig struct {
	EnvelopeEventsHandler          EnvelopeEventsHandler
	MaxAttempts                    int
	MailserverConfirmationsEnabled bool
	IsMailserver                   func(types.EnodeID) bool
	Logger                         *zap.Logger
}

type Filter

type Filter struct {
	// ChatID is the identifier of the chat
	ChatID string `json:"chatId"`
	// FilterID the whisper filter id generated
	FilterID string `json:"filterId"`
	// SymKeyID is the symmetric key id used for symmetric filters
	SymKeyID string `json:"symKeyId"`
	// OneToOne tells us if we need to use asymmetric encryption for this chat
	OneToOne bool `json:"oneToOne"`
	// Identity is the public key of the other recipient for non-public filters.
	// It's encoded using encoding/hex.
	Identity string `json:"identity"`
	// Topic is the whisper topic
	Topic types.TopicType `json:"topic"`
	// Discovery is whether this is a discovery topic
	Discovery bool `json:"discovery"`
	// Negotiated tells us whether is a negotiated topic
	Negotiated bool `json:"negotiated"`
	// Listen is whether we are actually listening for messages on this chat, or the filter is only created in order to be able to post on the topic
	Listen bool `json:"listen"`
}

TODO: revise fields encoding/decoding. Some are encoded using hexutil and some using encoding/hex.

func (*Filter) IsPublic

func (c *Filter) IsPublic() bool

type Message

type Message struct {
	Message *types.Message
	Public  bool
}

type Option

type Option func(*WhisperServiceTransport) error

type RequestOptions

type RequestOptions struct {
	Topics   []types.TopicType
	Password string
	Limit    int
	From     int64 // in seconds
	To       int64 // in seconds
}

type WhisperServiceTransport

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

WhisperServiceTransport is a transport based on Whisper service.

func NewWhisperServiceTransport

func NewWhisperServiceTransport(
	shh types.Whisper,
	privateKey *ecdsa.PrivateKey,
	db *sql.DB,
	mailservers []string,
	envelopesMonitorConfig *EnvelopesMonitorConfig,
	logger *zap.Logger,
	opts ...Option,
) (*WhisperServiceTransport, error)

NewWhisperServiceTransport returns a new WhisperServiceTransport. TODO: leaving a chat should verify that for a given public key

there are no other chats. It may happen that we leave a private chat
but still have a public chat for a given public key.

func (*WhisperServiceTransport) Filters

func (a *WhisperServiceTransport) Filters() []*Filter

func (*WhisperServiceTransport) InitFilters

func (a *WhisperServiceTransport) InitFilters(chatIDs []string, publicKeys []*ecdsa.PublicKey) ([]*Filter, error)

func (*WhisperServiceTransport) JoinGroup

func (a *WhisperServiceTransport) JoinGroup(publicKeys []*ecdsa.PublicKey) error

func (*WhisperServiceTransport) JoinPrivate

func (a *WhisperServiceTransport) JoinPrivate(publicKey *ecdsa.PublicKey) error

func (*WhisperServiceTransport) JoinPublic

func (a *WhisperServiceTransport) JoinPublic(chatID string) error

func (*WhisperServiceTransport) LeaveGroup

func (a *WhisperServiceTransport) LeaveGroup(publicKeys []*ecdsa.PublicKey) error

func (*WhisperServiceTransport) LeavePrivate

func (a *WhisperServiceTransport) LeavePrivate(publicKey *ecdsa.PublicKey) error

func (*WhisperServiceTransport) LeavePublic

func (a *WhisperServiceTransport) LeavePublic(chatID string) error

func (*WhisperServiceTransport) LoadFilters

func (a *WhisperServiceTransport) LoadFilters(filters []*Filter) ([]*Filter, error)

DEPRECATED

func (*WhisperServiceTransport) ProcessNegotiatedSecret

func (a *WhisperServiceTransport) ProcessNegotiatedSecret(secret types.NegotiatedSecret) (*Filter, error)

func (*WhisperServiceTransport) RemoveFilters

func (a *WhisperServiceTransport) RemoveFilters(filters []*Filter) error

DEPRECATED

func (*WhisperServiceTransport) Reset

func (a *WhisperServiceTransport) Reset() error

func (*WhisperServiceTransport) RetrieveAllMessages

func (a *WhisperServiceTransport) RetrieveAllMessages() ([]Message, error)

func (*WhisperServiceTransport) RetrievePrivateMessages

func (a *WhisperServiceTransport) RetrievePrivateMessages(publicKey *ecdsa.PublicKey) ([]*types.Message, error)

func (*WhisperServiceTransport) RetrievePublicMessages

func (a *WhisperServiceTransport) RetrievePublicMessages(chatID string) ([]*types.Message, error)

func (*WhisperServiceTransport) RetrieveRawAll

func (a *WhisperServiceTransport) RetrieveRawAll() (map[Filter][]*types.Message, error)

func (*WhisperServiceTransport) SendMessagesRequest

func (a *WhisperServiceTransport) SendMessagesRequest(
	ctx context.Context,
	peerID []byte,
	from, to uint32,
	previousCursor []byte,
) (cursor []byte, err error)

RequestHistoricMessages requests historic messages for all registered filters.

func (*WhisperServiceTransport) SendPrivateOnDiscovery

func (a *WhisperServiceTransport) SendPrivateOnDiscovery(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error)

func (*WhisperServiceTransport) SendPrivateWithPartitioned

func (a *WhisperServiceTransport) SendPrivateWithPartitioned(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error)

func (*WhisperServiceTransport) SendPrivateWithSharedSecret

func (a *WhisperServiceTransport) SendPrivateWithSharedSecret(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey, secret []byte) ([]byte, error)

func (*WhisperServiceTransport) SendPublic

func (a *WhisperServiceTransport) SendPublic(ctx context.Context, newMessage *types.NewMessage, chatName string) ([]byte, error)

SendPublic sends a new message using the Whisper service. For public filters, chat name is used as an ID as well as a topic.

func (*WhisperServiceTransport) Stop

func (a *WhisperServiceTransport) Stop() error

func (*WhisperServiceTransport) Track

func (a *WhisperServiceTransport) Track(identifiers [][]byte, hash []byte, newMessage *types.NewMessage)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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