pss

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package pss exposes functionalities needed to communicate with other peers on the network. Pss uses pushsync and pullsync for message delivery and mailboxing. All messages are disguised as content-addressed chunks. Sending and receiving of messages is exposed over the HTTP API, with websocket subscriptions for incoming messages.

Index

Constants

View Source
const (
	// MaxPayloadSize is the maximum allowed payload size for the Message type, in bytes
	MaxPayloadSize = swarm.ChunkSize - 3*swarm.HashSize
)

Variables

View Source
var (
	// ErrPayloadTooBig is returned when a given payload for a Message type is longer than the maximum amount allowed
	ErrPayloadTooBig = fmt.Errorf("message payload size cannot be greater than %d bytes", MaxPayloadSize)

	// ErrEmptyTargets is returned when the given target list for a trojan chunk is empty
	ErrEmptyTargets = errors.New("target list cannot be empty")

	// ErrVarLenTargets is returned when the given target list for a trojan chunk has addresses of different lengths
	ErrVarLenTargets = errors.New("target list cannot have targets of different length")
)
View Source
var (
	ErrNoHandler = errors.New("no handler found")
)

Functions

func ParseRecipient

func ParseRecipient(recipientHexString string) (*ecdsa.PublicKey, error)

ParseRecipient extract ephemeral public key from the hexadecimal string to use with el-Gamal.

func Wrap

func Wrap(ctx context.Context, topic Topic, msg []byte, recipient *ecdsa.PublicKey, targets Targets) (swarm.Chunk, error)

Wrap creates a new serialised message with the given topic, payload and recipient public key used for encryption - span as topic hint (H(key|topic)[0:8]) to match topic chunk payload: - nonce is chosen so that the chunk address will have one of the targets as its prefix and thus will be forwarded to the neighbourhood of the recipient overlay address the target is derived from trojan payload: - ephemeral public key for el-Gamal encryption ciphertext - plaintext: - plaintext length encoding - integrity protection message:

Types

type Handler

type Handler func(context.Context, []byte)

Handler defines code to be executed upon reception of a trojan message.

type Interface

type Interface interface {
	Sender
	// Register a Handler for a given Topic.
	Register(Topic, Handler) func()
	// TryUnwrap tries to unwrap a wrapped trojan message.
	TryUnwrap(swarm.Chunk)

	SetPushSyncer(pushSyncer pushsync.PushSyncer)
	io.Closer
}

func New

func New(key *ecdsa.PrivateKey, logger logging.Logger) Interface

New returns a new pss service.

type Sender

type Sender interface {
	// Send arbitrary byte slice with the given topic to Targets.
	Send(context.Context, Topic, []byte, postage.Stamper, *ecdsa.PublicKey, Targets) error
}

type Target

type Target []byte

Target is an alias for a partial address (overlay prefix) serving as potential destination

type Targets

type Targets []Target

Targets is an alias for a collection of targets

type Topic

type Topic [32]byte

Topic is the type that classifies messages, allows client applications to subscribe to

func NewTopic

func NewTopic(text string) Topic

NewTopic creates a new Topic from an input string by taking its hash

func Unwrap

func Unwrap(ctx context.Context, key *ecdsa.PrivateKey, chunk swarm.Chunk, topics []Topic) (topic Topic, msg []byte, err error)

Unwrap takes a chunk, a topic and a private key, and tries to decrypt the payload using the private key, the prepended ephemeral public key for el-Gamal using the topic as salt

Jump to

Keyboard shortcuts

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