whisperv6

package
v0.0.0-...-b78b3a4 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion    = uint64(6) //
	ProtocolVersionStr = "6.0"     //
	ProtocolName       = "shh"     //

	NumberOfMessageCodes = 128

	SizeMask = byte(3) //

	TopicLength = 4 //

	BloomFilterSize = 64 //

	EnvelopeHeaderLength = 20

	MaxMessageSize        = uint32(10 * 1024 * 1024) //
	DefaultMaxMessageSize = uint32(1024 * 1024)
	DefaultMinimumPoW     = 0.2

	DefaultTTL           = 50 //
	DefaultSyncAllowance = 10 //
)

Variables

View Source
var (
	ErrSymAsym              = errors.New("specify either a symmetric or an asymmetric key")
	ErrInvalidSymmetricKey  = errors.New("invalid symmetric key")
	ErrInvalidPublicKey     = errors.New("invalid public key")
	ErrInvalidSigningPubKey = errors.New("invalid signing public key")
	ErrTooLowPoW            = errors.New("message rejected, PoW too low")
	ErrNoTopics             = errors.New("missing topic(s)")
)
View Source
var DefaultConfig = Config{
	MaxMessageSize:     DefaultMaxMessageSize,
	MinimumAcceptedPOW: DefaultMinimumPoW,
}

Functions

func BloomFilterMatch

func BloomFilterMatch(filter, sample []byte) bool

func BytesToUintBigEndian

func BytesToUintBigEndian(b []byte) (res uint64)

func GenerateRandomID

func GenerateRandomID() (id string, err error)

func IsPubKeyEqual

func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool

func MakeFullNodeBloom

func MakeFullNodeBloom() []byte

func NewSentMessage

func NewSentMessage(params *MessageParams) (*sentMessage, error)

func TopicToBloom

func TopicToBloom(topic TopicType) []byte

func ValidatePublicKey

func ValidatePublicKey(k *ecdsa.PublicKey) bool

Types

type Config

type Config struct {
	MaxMessageSize     uint32  `toml:",omitempty"`
	MinimumAcceptedPOW float64 `toml:",omitempty"`
}

type Criteria

type Criteria struct {
	SymKeyID     string      `json:"symKeyID"`
	PrivateKeyID string      `json:"privateKeyID"`
	Sig          []byte      `json:"sig"`
	MinPow       float64     `json:"minPow"`
	Topics       []TopicType `json:"topics"`
	AllowP2P     bool        `json:"allowP2P"`
}

func (Criteria) MarshalJSON

func (c Criteria) MarshalJSON() ([]byte, error)

func (*Criteria) UnmarshalJSON

func (c *Criteria) UnmarshalJSON(input []byte) error

type Envelope

type Envelope struct {
	Expiry uint32
	TTL    uint32
	Topic  TopicType
	Data   []byte
	Nonce  uint64
	// contains filtered or unexported fields
}

func NewEnvelope

func NewEnvelope(ttl uint32, topic TopicType, msg *sentMessage) *Envelope

func (*Envelope) Bloom

func (e *Envelope) Bloom() []byte

func (*Envelope) DecodeRLP

func (e *Envelope) DecodeRLP(s *rlp.Stream) error

func (*Envelope) Hash

func (e *Envelope) Hash() common.Hash

func (*Envelope) Open

func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage)

func (*Envelope) OpenAsymmetric

func (e *Envelope) OpenAsymmetric(key *ecdsa.PrivateKey) (*ReceivedMessage, error)

func (*Envelope) OpenSymmetric

func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error)

func (*Envelope) PoW

func (e *Envelope) PoW() float64

func (*Envelope) Seal

func (e *Envelope) Seal(options *MessageParams) error

type Filter

type Filter struct {
	Src        *ecdsa.PublicKey  //
	KeyAsym    *ecdsa.PrivateKey //
	KeySym     []byte            //
	Topics     [][]byte          //
	PoW        float64           //
	AllowP2P   bool              //
	SymKeyHash common.Hash       //

	Messages map[common.Hash]*ReceivedMessage
	// contains filtered or unexported fields
}

func (*Filter) MatchEnvelope

func (f *Filter) MatchEnvelope(envelope *Envelope) bool

func (*Filter) MatchMessage

func (f *Filter) MatchMessage(msg *ReceivedMessage) bool

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 NewFilters(w *Whisper) *Filters

func (*Filters) Get

func (fs *Filters) Get(id string) *Filter

func (*Filters) Install

func (fs *Filters) Install(watcher *Filter) (string, error)

func (*Filters) NotifyWatchers

func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool)

func (*Filters) Uninstall

func (fs *Filters) Uninstall(id string) bool

type Info

type Info struct {
	Memory         int     `json:"memory"`         //
	Messages       int     `json:"messages"`       //
	MinPow         float64 `json:"minPow"`         //
	MaxMessageSize uint32  `json:"maxMessageSize"` //
}

type MailServer

type MailServer interface {
	Archive(env *Envelope)
	DeliverMail(whisperPeer *Peer, request *Envelope)
}

type Message

type Message struct {
	Sig       []byte    `json:"sig,omitempty"`
	TTL       uint32    `json:"ttl"`
	Timestamp uint32    `json:"timestamp"`
	Topic     TopicType `json:"topic"`
	Payload   []byte    `json:"payload"`
	Padding   []byte    `json:"padding"`
	PoW       float64   `json:"pow"`
	Hash      []byte    `json:"hash"`
	Dst       []byte    `json:"recipientPublicKey,omitempty"`
}

func ToWhisperMessage

func ToWhisperMessage(message *ReceivedMessage) *Message

func (Message) MarshalJSON

func (m Message) MarshalJSON() ([]byte, error)

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(input []byte) error

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
}

type NewMessage

type NewMessage struct {
	SymKeyID   string    `json:"symKeyID"`
	PublicKey  []byte    `json:"pubKey"`
	Sig        string    `json:"sig"`
	TTL        uint32    `json:"ttl"`
	Topic      TopicType `json:"topic"`
	Payload    []byte    `json:"payload"`
	Padding    []byte    `json:"padding"`
	PowTime    uint32    `json:"powTime"`
	PowTarget  float64   `json:"powTarget"`
	TargetPeer string    `json:"targetPeer"`
}

func (NewMessage) MarshalJSON

func (n NewMessage) MarshalJSON() ([]byte, error)

func (*NewMessage) UnmarshalJSON

func (n *NewMessage) UnmarshalJSON(input []byte) error

type Peer

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

func (*Peer) ID

func (peer *Peer) ID() []byte

type PublicWhisperAPI

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

func NewPublicWhisperAPI

func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI

func (*PublicWhisperAPI) AddPrivateKey

func (api *PublicWhisperAPI) AddPrivateKey(ctx context.Context, privateKey hexutil.Bytes) (string, error)

func (*PublicWhisperAPI) AddSymKey

func (api *PublicWhisperAPI) AddSymKey(ctx context.Context, key hexutil.Bytes) (string, error)

func (*PublicWhisperAPI) CancelLightClient

func (api *PublicWhisperAPI) CancelLightClient(ctx context.Context) bool

func (*PublicWhisperAPI) DeleteKeyPair

func (api *PublicWhisperAPI) DeleteKeyPair(ctx context.Context, key string) (bool, error)

func (*PublicWhisperAPI) DeleteMessageFilter

func (api *PublicWhisperAPI) DeleteMessageFilter(id string) (bool, error)

func (*PublicWhisperAPI) DeleteSymKey

func (api *PublicWhisperAPI) DeleteSymKey(ctx context.Context, id string) bool

func (*PublicWhisperAPI) GenerateSymKeyFromPassword

func (api *PublicWhisperAPI) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error)

func (*PublicWhisperAPI) GetFilterMessages

func (api *PublicWhisperAPI) GetFilterMessages(id string) ([]*Message, error)

func (*PublicWhisperAPI) GetPrivateKey

func (api *PublicWhisperAPI) GetPrivateKey(ctx context.Context, id string) (hexutil.Bytes, error)

func (*PublicWhisperAPI) GetPublicKey

func (api *PublicWhisperAPI) GetPublicKey(ctx context.Context, id string) (hexutil.Bytes, error)

func (*PublicWhisperAPI) GetSymKey

func (api *PublicWhisperAPI) GetSymKey(ctx context.Context, id string) (hexutil.Bytes, error)

func (*PublicWhisperAPI) HasKeyPair

func (api *PublicWhisperAPI) HasKeyPair(ctx context.Context, id string) bool

func (*PublicWhisperAPI) HasSymKey

func (api *PublicWhisperAPI) HasSymKey(ctx context.Context, id string) bool

func (*PublicWhisperAPI) Info

func (api *PublicWhisperAPI) Info(ctx context.Context) Info

func (*PublicWhisperAPI) MakeLightClient

func (api *PublicWhisperAPI) MakeLightClient(ctx context.Context) bool

func (*PublicWhisperAPI) MarkTrustedPeer

func (api *PublicWhisperAPI) MarkTrustedPeer(ctx context.Context, enode string) (bool, error)

func (*PublicWhisperAPI) Messages

func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.Subscription, error)

func (*PublicWhisperAPI) NewKeyPair

func (api *PublicWhisperAPI) NewKeyPair(ctx context.Context) (string, error)

func (*PublicWhisperAPI) NewMessageFilter

func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error)

func (*PublicWhisperAPI) NewSymKey

func (api *PublicWhisperAPI) NewSymKey(ctx context.Context) (string, error)

func (*PublicWhisperAPI) Post

func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error)

func (*PublicWhisperAPI) SetBloomFilter

func (api *PublicWhisperAPI) SetBloomFilter(ctx context.Context, bloom hexutil.Bytes) (bool, error)

func (*PublicWhisperAPI) SetMaxMessageSize

func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32) (bool, error)

func (*PublicWhisperAPI) SetMinPoW

func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error)

func (*PublicWhisperAPI) Version

func (api *PublicWhisperAPI) Version(ctx context.Context) string

type ReceivedMessage

type ReceivedMessage struct {
	Raw []byte

	Payload   []byte
	Padding   []byte
	Signature []byte
	Salt      []byte

	PoW   float64          //
	Sent  uint32           //
	TTL   uint32           //
	Src   *ecdsa.PublicKey //
	Dst   *ecdsa.PublicKey //
	Topic TopicType

	SymKeyHash   common.Hash //
	EnvelopeHash common.Hash //
}

func (*ReceivedMessage) SigToPubKey

func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey

func (*ReceivedMessage) ValidateAndParse

func (msg *ReceivedMessage) ValidateAndParse() bool

type Statistics

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

type TopicType

type TopicType [TopicLength]byte

func BytesToTopic

func BytesToTopic(b []byte) (t TopicType)

func (TopicType) MarshalText

func (t TopicType) MarshalText() ([]byte, error)

func (*TopicType) String

func (t *TopicType) String() string

func (*TopicType) UnmarshalText

func (t *TopicType) UnmarshalText(input []byte) error

type Whisper

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

func New

func New(cfg *Config) *Whisper

func (*Whisper) APIs

func (whisper *Whisper) APIs() []rpc.API

func (*Whisper) AddKeyPair

func (whisper *Whisper) AddKeyPair(key *ecdsa.PrivateKey) (string, error)

func (*Whisper) AddSymKeyDirect

func (whisper *Whisper) AddSymKeyDirect(key []byte) (string, error)

func (*Whisper) AddSymKeyFromPassword

func (whisper *Whisper) AddSymKeyFromPassword(password string) (string, error)

func (*Whisper) AllowP2PMessagesFromPeer

func (whisper *Whisper) AllowP2PMessagesFromPeer(peerID []byte) error

func (*Whisper) BloomFilter

func (whisper *Whisper) BloomFilter() []byte

func (*Whisper) BloomFilterTolerance

func (whisper *Whisper) BloomFilterTolerance() []byte

func (*Whisper) DeleteKeyPair

func (whisper *Whisper) DeleteKeyPair(key string) bool

func (*Whisper) DeleteSymKey

func (whisper *Whisper) DeleteSymKey(id string) bool

func (*Whisper) Envelopes

func (whisper *Whisper) Envelopes() []*Envelope

func (*Whisper) GenerateSymKey

func (whisper *Whisper) GenerateSymKey() (string, error)

func (*Whisper) GetEnvelope

func (w *Whisper) GetEnvelope(hash common.Hash) *Envelope

func (*Whisper) GetFilter

func (whisper *Whisper) GetFilter(id string) *Filter

func (*Whisper) GetPrivateKey

func (whisper *Whisper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error)

func (*Whisper) GetSymKey

func (whisper *Whisper) GetSymKey(id string) ([]byte, error)

func (*Whisper) HandlePeer

func (whisper *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error

func (*Whisper) HasKeyPair

func (whisper *Whisper) HasKeyPair(id string) bool

func (*Whisper) HasSymKey

func (whisper *Whisper) HasSymKey(id string) bool

func (*Whisper) MaxMessageSize

func (whisper *Whisper) MaxMessageSize() uint32

func (*Whisper) MinPow

func (whisper *Whisper) MinPow() float64

func (*Whisper) MinPowTolerance

func (whisper *Whisper) MinPowTolerance() float64

func (*Whisper) NewKeyPair

func (whisper *Whisper) NewKeyPair() (string, error)

func (*Whisper) Overflow

func (whisper *Whisper) Overflow() bool

func (*Whisper) Protocols

func (whisper *Whisper) Protocols() []p2p.Protocol

func (*Whisper) RegisterServer

func (whisper *Whisper) RegisterServer(server MailServer)

func (*Whisper) RequestHistoricMessages

func (whisper *Whisper) RequestHistoricMessages(peerID []byte, envelope *Envelope) error

func (*Whisper) Send

func (whisper *Whisper) Send(envelope *Envelope) error

func (*Whisper) SendP2PDirect

func (whisper *Whisper) SendP2PDirect(peer *Peer, envelope *Envelope) error

func (*Whisper) SendP2PMessage

func (whisper *Whisper) SendP2PMessage(peerID []byte, envelope *Envelope) error

func (*Whisper) SetBloomFilter

func (whisper *Whisper) SetBloomFilter(bloom []byte) error

func (*Whisper) SetMaxMessageSize

func (whisper *Whisper) SetMaxMessageSize(size uint32) error

func (*Whisper) SetMinimumPoW

func (whisper *Whisper) SetMinimumPoW(val float64) error

func (*Whisper) SetMinimumPowTest

func (whisper *Whisper) SetMinimumPowTest(val float64)

func (*Whisper) Start

func (whisper *Whisper) Start(*p2p.Server) error

func (*Whisper) Stats

func (whisper *Whisper) Stats() Statistics

func (*Whisper) Stop

func (whisper *Whisper) Stop() error

func (*Whisper) Subscribe

func (whisper *Whisper) Subscribe(f *Filter) (string, error)

func (*Whisper) Unsubscribe

func (whisper *Whisper) Unsubscribe(id string) error

func (*Whisper) Version

func (whisper *Whisper) Version() uint

Jump to

Keyboard shortcuts

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