whisperv5

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: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvelopeVersion    = uint64(0)
	ProtocolVersion    = uint64(5)
	ProtocolVersionStr = "5.0"
	ProtocolName       = "shh"

	NumberOfMessageCodes = 64

	TopicLength = 4

	AESNonceLength = 12

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

	DefaultTTL     = 50 //
	SynchAllowance = 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 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 NewSentMessage

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

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 {
	Version  []byte
	Expiry   uint32
	TTL      uint32
	Topic    TopicType
	AESNonce []byte
	Data     []byte
	EnvNonce uint64
	// contains filtered or unexported fields
}

func NewEnvelope

func NewEnvelope(ttl uint32, topic TopicType, aesNonce []byte, msg *sentMessage) *Envelope

func (*Envelope) DecodeRLP

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

func (*Envelope) Hash

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

func (*Envelope) IsSymmetric

func (e *Envelope) IsSymmetric() bool

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

func (*Envelope) Ver

func (e *Envelope) Ver() uint64

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

func (f *Filter) MatchTopic(topic TopicType) 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) 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) 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) (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

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

	SymKeyHash      common.Hash //
	EnvelopeHash    common.Hash //
	EnvelopeVersion uint64
}

func (*ReceivedMessage) SigToPubKey

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

func (*ReceivedMessage) Validate

func (msg *ReceivedMessage) Validate() 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 (w *Whisper) APIs() []rpc.API

func (*Whisper) AddKeyPair

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

func (*Whisper) AddSymKeyDirect

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

func (*Whisper) AddSymKeyFromPassword

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

func (*Whisper) AllowP2PMessagesFromPeer

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

func (*Whisper) DeleteKeyPair

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

func (*Whisper) DeleteSymKey

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

func (*Whisper) Envelopes

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

func (*Whisper) GenerateSymKey

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

func (*Whisper) GetFilter

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

func (*Whisper) GetPrivateKey

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

func (*Whisper) GetSymKey

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

func (*Whisper) HandlePeer

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

func (*Whisper) HasKeyPair

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

func (*Whisper) HasSymKey

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

func (*Whisper) MaxMessageSize

func (w *Whisper) MaxMessageSize() uint32

func (*Whisper) Messages

func (w *Whisper) Messages(id string) []*ReceivedMessage

func (*Whisper) MinPow

func (w *Whisper) MinPow() float64

func (*Whisper) NewKeyPair

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

func (*Whisper) Overflow

func (w *Whisper) Overflow() bool

func (*Whisper) Protocols

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

func (*Whisper) RegisterServer

func (w *Whisper) RegisterServer(server MailServer)

func (*Whisper) RequestHistoricMessages

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

func (*Whisper) Send

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

func (*Whisper) SendP2PDirect

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

func (*Whisper) SendP2PMessage

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

func (*Whisper) SetMaxMessageSize

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

func (*Whisper) SetMinimumPoW

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

func (*Whisper) Start

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

func (*Whisper) Stats

func (w *Whisper) Stats() Statistics

func (*Whisper) Stop

func (w *Whisper) Stop() error

func (*Whisper) Subscribe

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

func (*Whisper) Unsubscribe

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

func (*Whisper) Version

func (w *Whisper) Version() uint

Jump to

Keyboard shortcuts

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