transport

package
v0.167.6 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MPL-2.0, MPL-2.0 Imports: 21 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 DiscoveryTopic

func DiscoveryTopic() string

func GetPubsubTopic added in v0.166.1

func GetPubsubTopic(communityID []byte) string

func NegotiatedTopic

func NegotiatedTopic(publicKey *ecdsa.PublicKey) string

func PartitionedTopic

func PartitionedTopic(publicKey *ecdsa.PublicKey) string

PartitionedTopic returns the associated partitioned topic string with the given public key.

func PersonalDiscoveryTopic

func PersonalDiscoveryTopic(publicKey *ecdsa.PublicKey) string

func PubkeyToHex added in v0.72.0

func PubkeyToHex(key *ecdsa.PublicKey) string

func PublicKeyToStr

func PublicKeyToStr(publicKey *ecdsa.PublicKey) string

func StrToPublicKey

func StrToPublicKey(str string) (*ecdsa.PublicKey, error)

func ToTopic

func ToTopic(s string) []byte

ToTopic converts a string to a whisper topic.

Types

type CommunityFilterToInitialize added in v0.166.1

type CommunityFilterToInitialize struct {
	CommunityID []byte
	PrivKey     *ecdsa.PrivateKey
}

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 added in v0.76.6

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 waku queue.
	EnvelopePosted EnvelopeState = iota + 1
	// EnvelopeSent is set when envelope is sent to at least one peer.
	EnvelopeSent
)

type EnvelopesMonitor added in v0.76.6

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

EnvelopesMonitor is responsible for monitoring waku envelopes state.

func NewEnvelopesMonitor added in v0.76.6

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

NewEnvelopesMonitor returns a pointer to an instance of the EnvelopesMonitor.

func (*EnvelopesMonitor) Add added in v0.76.6

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

Add hash to a tracker.

func (*EnvelopesMonitor) GetState added in v0.76.6

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

func (*EnvelopesMonitor) Start added in v0.76.6

func (m *EnvelopesMonitor) Start()

Start processing events.

func (*EnvelopesMonitor) Stop added in v0.76.6

func (m *EnvelopesMonitor) Stop()

Stop process events.

type EnvelopesMonitorConfig

type EnvelopesMonitorConfig struct {
	EnvelopeEventsHandler            EnvelopeEventsHandler
	MaxAttempts                      int
	AwaitOnlyMailServerConfirmations 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"`
	// PubsubTopic is the waku2 pubsub topic
	PubsubTopic string `json:"pubsubTopic"`
	// ContentTopic is the waku topic
	ContentTopic 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"`
	// Ephemeral indicates that this is an ephemeral filter
	Ephemeral bool `json:"ephemeral"`
	// Priority
	Priority uint64
}

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

func (*Filter) IsPublic

func (c *Filter) IsPublic() bool

type FiltersManager

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

func NewFiltersManager

func NewFiltersManager(persistence KeysPersistence, service FiltersService, privateKey *ecdsa.PrivateKey, logger *zap.Logger) (*FiltersManager, error)

NewFiltersManager returns a new filtersManager.

func (*FiltersManager) Filter

func (f *FiltersManager) Filter(chatID string) *Filter

func (*FiltersManager) FilterByChatID added in v0.76.3

func (f *FiltersManager) FilterByChatID(chatID string) *Filter

FilterByChatID returns a Filter for given chat id

func (*FiltersManager) FilterByFilterID

func (f *FiltersManager) FilterByFilterID(filterID string) *Filter

FilterByFilterID returns a Filter with a given Whisper filter ID.

func (*FiltersManager) FilterByTopic added in v0.100.0

func (f *FiltersManager) FilterByTopic(topic []byte) *Filter

func (*FiltersManager) Filters

func (f *FiltersManager) Filters() (result []*Filter)

func (*FiltersManager) FiltersByIdentities added in v0.79.0

func (f *FiltersManager) FiltersByIdentities(identities []string) []*Filter

FiltersByIdentities returns an array of filters for given list of public keys

func (*FiltersManager) GetNegotiated

func (f *FiltersManager) GetNegotiated(identity *ecdsa.PublicKey) *Filter

GetNegotiated returns a negotiated chat given an identity

func (*FiltersManager) Init

func (f *FiltersManager) Init(
	filtersToInit []FiltersToInitialize,
	publicKeys []*ecdsa.PublicKey,
) ([]*Filter, error)

func (*FiltersManager) InitCommunityFilters added in v0.72.0

func (f *FiltersManager) InitCommunityFilters(communityFiltersToInitialize []CommunityFilterToInitialize) ([]*Filter, error)

func (*FiltersManager) InitPublicFilters added in v0.67.0

func (f *FiltersManager) InitPublicFilters(publicFiltersToInit []FiltersToInitialize) ([]*Filter, error)

func (*FiltersManager) InitWithFilters

func (f *FiltersManager) InitWithFilters(filters []*Filter) ([]*Filter, error)

DEPRECATED

func (*FiltersManager) LoadContactCode

func (f *FiltersManager) LoadContactCode(pubKey *ecdsa.PublicKey) (*Filter, error)

LoadContactCode creates a filter for the advertise topic for a given public key.

func (*FiltersManager) LoadDiscovery

func (f *FiltersManager) LoadDiscovery() ([]*Filter, error)

LoadDiscovery adds 1 discovery filter for the personal discovery topic.

func (*FiltersManager) LoadEphemeral added in v0.69.0

func (f *FiltersManager) LoadEphemeral(publicKey *ecdsa.PublicKey, identity *ecdsa.PrivateKey, listen bool) (*Filter, error)

LoadEphemeral creates a filter for a partitioned/personal topic.

func (*FiltersManager) LoadNegotiated

func (f *FiltersManager) LoadNegotiated(secret types.NegotiatedSecret) (*Filter, error)

LoadNegotiated loads a negotiated secret as a filter.

func (*FiltersManager) LoadPartitioned

func (f *FiltersManager) LoadPartitioned(publicKey *ecdsa.PublicKey, identity *ecdsa.PrivateKey, listen bool) (*Filter, error)

LoadPartitioned creates a filter for a partitioned topic.

func (*FiltersManager) LoadPersonal added in v0.69.0

func (f *FiltersManager) LoadPersonal(publicKey *ecdsa.PublicKey, identity *ecdsa.PrivateKey, listen bool) (*Filter, error)

LoadPersonal creates a filter for a personal topic.

func (*FiltersManager) LoadPublic

func (f *FiltersManager) LoadPublic(chatID string, pubsubTopic string) (*Filter, error)

LoadPublic adds a filter for a public chat.

func (*FiltersManager) PersonalTopicFilter added in v0.90.0

func (f *FiltersManager) PersonalTopicFilter() *Filter

func (*FiltersManager) Remove

func (f *FiltersManager) Remove(ctx context.Context, filters ...*Filter) error

Remove remove all the filters associated with a chat/identity

func (*FiltersManager) RemoveFilterByChatID added in v0.67.0

func (f *FiltersManager) RemoveFilterByChatID(chatID string) (*Filter, error)

Remove remove all the filters associated with a chat/identity

func (*FiltersManager) RemoveNoListenFilters added in v0.69.0

func (f *FiltersManager) RemoveNoListenFilters() error

Remove remove all the filters associated with a chat/identity

func (*FiltersManager) Reset

func (f *FiltersManager) Reset(ctx context.Context) error

type FiltersService

type FiltersService interface {
	AddKeyPair(key *ecdsa.PrivateKey) (string, error)
	DeleteKeyPair(keyID string) bool

	AddSymKeyDirect(key []byte) (string, error)
	AddSymKeyFromPassword(password string) (string, error)
	GetSymKey(id string) ([]byte, error)
	DeleteSymKey(id string) bool

	Subscribe(opts *types.SubscriptionOptions) (string, error)
	Unsubscribe(ctx context.Context, id string) error
	UnsubscribeMany(ids []string) error
}

type FiltersToInitialize added in v0.166.1

type FiltersToInitialize struct {
	ChatID      string
	PubsubTopic string
}

type KeysPersistence

type KeysPersistence interface {
	All() (map[string][]byte, error)
	Add(chatID string, key []byte) error
}

type Option added in v0.76.6

type Option func(*Transport) error

type ProcessedMessageIDsCache added in v0.68.6

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

func NewProcessedMessageIDsCache added in v0.68.6

func NewProcessedMessageIDsCache(db *sql.DB) *ProcessedMessageIDsCache

func (*ProcessedMessageIDsCache) Add added in v0.68.6

func (c *ProcessedMessageIDsCache) Add(ids []string, timestamp uint64) (err error)

func (*ProcessedMessageIDsCache) Clean added in v0.68.6

func (c *ProcessedMessageIDsCache) Clean(timestamp uint64) error

func (*ProcessedMessageIDsCache) Clear added in v0.79.0

func (c *ProcessedMessageIDsCache) Clear() error

func (*ProcessedMessageIDsCache) Hits added in v0.68.6

func (c *ProcessedMessageIDsCache) Hits(ids []string) (map[string]bool, error)

type RawFilter

type RawFilter struct {
	FilterID string
	Topic    types.TopicType
	SymKeyID string
}

type SqlitePersistence added in v0.80.2

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

func (*SqlitePersistence) Add added in v0.80.2

func (s *SqlitePersistence) Add(chatID string, key []byte) error

func (*SqlitePersistence) All added in v0.80.2

func (s *SqlitePersistence) All() (map[string][]byte, error)

type Transport

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

Transport is a transport based on Whisper service.

func NewTransport added in v0.76.6

func NewTransport(
	waku types.Waku,
	privateKey *ecdsa.PrivateKey,
	db *sql.DB,
	sqlitePersistenceTableName string,
	mailservers []string,
	envelopesMonitorConfig *EnvelopesMonitorConfig,
	logger *zap.Logger,
	opts ...Option,
) (*Transport, error)

NewTransport returns a new Transport. 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 (*Transport) AddRelayPeer added in v0.88.4

func (t *Transport) AddRelayPeer(address string) (peer.ID, error)

func (*Transport) AddStorePeer added in v0.88.4

func (t *Transport) AddStorePeer(address string) (peer.ID, error)

func (*Transport) BloomFilter added in v0.85.0

func (t *Transport) BloomFilter() []byte

func (*Transport) CleanMessagesProcessed added in v0.68.6

func (t *Transport) CleanMessagesProcessed(timestamp uint64) error

CleanMessagesProcessed clears the messages that are older than timestamp

func (*Transport) ClearProcessedMessageIDsCache added in v0.79.0

func (t *Transport) ClearProcessedMessageIDsCache() error

func (*Transport) ConfirmMessagesProcessed added in v0.68.6

func (t *Transport) ConfirmMessagesProcessed(ids []string, timestamp uint64) error

ConfirmMessagesProcessed marks the messages as processed in the cache so they won't be passed to the next layer anymore

func (*Transport) ConnectionChanged added in v0.117.1

func (t *Transport) ConnectionChanged(state connection.State)

func (*Transport) DialPeer added in v0.88.4

func (t *Transport) DialPeer(address string) error

func (*Transport) DialPeerByID added in v0.88.4

func (t *Transport) DialPeerByID(peerID string) error

func (*Transport) DropPeer added in v0.88.4

func (t *Transport) DropPeer(peerID string) error

func (*Transport) FilterByChatID added in v0.76.3

func (t *Transport) FilterByChatID(chatID string) *Filter

func (*Transport) FilterByTopic added in v0.100.0

func (t *Transport) FilterByTopic(topic []byte) *Filter

func (*Transport) Filters

func (t *Transport) Filters() []*Filter

func (*Transport) FiltersByIdentities added in v0.79.0

func (t *Transport) FiltersByIdentities(identities []string) []*Filter

func (*Transport) GetCurrentTime

func (t *Transport) GetCurrentTime() uint64

GetCurrentTime returns the current unix timestamp in milliseconds

func (*Transport) GetStats added in v0.83.8

func (t *Transport) GetStats() types.StatsSummary

func (*Transport) InitCommunityFilters added in v0.72.0

func (t *Transport) InitCommunityFilters(communityFiltersToInitialize []CommunityFilterToInitialize) ([]*Filter, error)

func (*Transport) InitFilters

func (t *Transport) InitFilters(chatIDs []FiltersToInitialize, publicKeys []*ecdsa.PublicKey) ([]*Filter, error)

func (*Transport) InitPublicFilters added in v0.67.0

func (t *Transport) InitPublicFilters(filtersToInit []FiltersToInitialize) ([]*Filter, error)

func (*Transport) JoinGroup

func (t *Transport) JoinGroup(publicKeys []*ecdsa.PublicKey) ([]*Filter, error)

func (*Transport) JoinPrivate

func (t *Transport) JoinPrivate(publicKey *ecdsa.PublicKey) (*Filter, error)

func (*Transport) JoinPublic

func (t *Transport) JoinPublic(chatID string) (*Filter, error)

func (*Transport) LeavePublic

func (t *Transport) LeavePublic(chatID string) error

func (*Transport) ListenAddresses added in v0.115.4

func (t *Transport) ListenAddresses() ([]string, error)

func (*Transport) LoadFilters

func (t *Transport) LoadFilters(filters []*Filter) ([]*Filter, error)

func (*Transport) LoadKeyFilters added in v0.56.1

func (t *Transport) LoadKeyFilters(key *ecdsa.PrivateKey) (*Filter, error)

func (*Transport) MarkP2PMessageAsProcessed added in v0.91.12

func (t *Transport) MarkP2PMessageAsProcessed(hash common.Hash)

func (*Transport) MaxMessageSize added in v0.63.2

func (t *Transport) MaxMessageSize() uint32

func (*Transport) PeerCount added in v0.88.4

func (t *Transport) PeerCount() int

func (*Transport) Peers added in v0.88.4

func (t *Transport) Peers() map[string]types.WakuV2Peer

func (*Transport) PersonalTopicFilter added in v0.90.0

func (t *Transport) PersonalTopicFilter() *Filter

func (*Transport) ProcessNegotiatedSecret

func (t *Transport) ProcessNegotiatedSecret(secret types.NegotiatedSecret) (*Filter, error)

func (*Transport) ProcessingP2PMessages added in v0.91.12

func (t *Transport) ProcessingP2PMessages() bool

func (*Transport) RemoveFilterByChatID added in v0.67.0

func (t *Transport) RemoveFilterByChatID(chatID string) (*Filter, error)

func (*Transport) RemoveFilters

func (t *Transport) RemoveFilters(filters []*Filter) error

func (*Transport) ResetFilters

func (t *Transport) ResetFilters(ctx context.Context) error

func (*Transport) RetrieveRawAll

func (t *Transport) RetrieveRawAll() (map[Filter][]*types.Message, error)

func (*Transport) SendCommunityMessage added in v0.72.0

func (t *Transport) SendCommunityMessage(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error)

func (*Transport) SendMessagesRequestForTopics added in v0.79.0

func (t *Transport) SendMessagesRequestForTopics(
	ctx context.Context,
	peerID []byte,
	from, to uint32,
	previousCursor []byte,
	previousStoreCursor *types.StoreRequestCursor,
	pubsubTopic string,
	contentTopics []types.TopicType,
	waitForResponse bool,
) (cursor []byte, storeCursor *types.StoreRequestCursor, err error)

func (*Transport) SendPrivateOnPersonalTopic added in v0.69.0

func (t *Transport) SendPrivateOnPersonalTopic(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error)

func (*Transport) SendPrivateWithPartitioned

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

func (*Transport) SendPrivateWithSharedSecret

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

func (*Transport) SendPublic

func (t *Transport) 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 (*Transport) SetEnvelopeEventsHandler added in v0.64.7

func (t *Transport) SetEnvelopeEventsHandler(handler EnvelopeEventsHandler) error

func (*Transport) StartDiscV5 added in v0.91.8

func (t *Transport) StartDiscV5() error

func (*Transport) Stop

func (t *Transport) Stop() error

func (*Transport) StopDiscV5 added in v0.91.8

func (t *Transport) StopDiscV5() error

func (*Transport) StorePubsubTopicKey added in v0.166.1

func (t *Transport) StorePubsubTopicKey(topic string, privKey *ecdsa.PrivateKey) error

func (*Transport) SubscribeToConnStatusChanges added in v0.93.2

func (t *Transport) SubscribeToConnStatusChanges() (*types.ConnStatusSubscription, error)

func (*Transport) SubscribeToPubsubTopic added in v0.166.1

func (t *Transport) SubscribeToPubsubTopic(topic string, optPublicKey *ecdsa.PublicKey) error

Subscribe to a pubsub topic, passing an optional public key if the pubsub topic is protected

func (*Transport) Track

func (t *Transport) Track(identifiers [][]byte, hash []byte, newMessage *types.NewMessage)

func (*Transport) WakuVersion added in v0.83.2

func (t *Transport) WakuVersion() uint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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