trojan

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

Documentation

Index

Constants

View Source
const (
	// MaxPayloadSize is the maximum allowed payload size for the Message type, in bytes
	// MaxPayloadSize + Topic + Length + Nonce = Default ChunkSize
	//    (4030)      +  (32) +   (2)  +  (32) = 4096 Bytes
	MaxPayloadSize = swarm.ChunkSize - NonceSize - LengthSize - TopicSize
	// NonceSize is a hash bit sequence
	NonceSize = 32
	// LengthSize is the byte length to represent message
	LengthSize = 2
	// TopicSize is a hash bit sequence
	TopicSize = 32
)

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

	// ErrUnmarshal is returned when a trojan message could not be de-serialized
	ErrUnmarshal = errors.New("trojan message unmarshall error")
)

Functions

func IsPotential

func IsPotential(c swarm.Chunk) bool

IsPotential returns true if the given chunk is a potential trojan

Types

type Message

type Message struct {
	Topic   Topic
	Payload []byte // contains the chunk address to be repaired
	// contains filtered or unexported fields
}

Message represents a trojan message, which is a message that will be hidden within a chunk payload as part of its data

func NewMessage

func NewMessage(topic Topic, payload []byte) (Message, error)

NewMessage creates a new Message variable with the given topic and payload it finds a length and nonce for the message according to the given input and maximum payload size

func Unwrap

func Unwrap(c swarm.Chunk) (*Message, error)

Unwrap creates a new trojan message from the given chunk payload this function assumes the chunk has been validated as a content-addressed chunk it will return the resulting message if the unwrapping is successful, and an error otherwise

func (*Message) MarshalBinary

func (m *Message) MarshalBinary() (data []byte, err error)

MarshalBinary serializes a message struct

func (*Message) UnmarshalBinary

func (m *Message) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary deserializes a message struct

func (*Message) Wrap

func (m *Message) Wrap(ctx context.Context, targets Targets) (swarm.Chunk, error)

Wrap creates a new trojan chunk for the given targets and Message a trojan chunk is a content-addressed chunk made up of span, a nonce, and a payload which contains the Message 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 this is done by iteratively enumerating different nonces until the BMT hash of the serialization of the trojan chunk fields results in a chunk address that has one of the targets as its prefix

type Target

type Target []byte

Target is an alias for an address which can be mined to construct a trojan message. Target is like partial address which helps to send message to a particular PO.

type Targets

type Targets []Target

Targets is an alias for a collection of targets

type Topic

type Topic [32]byte

Topic is an alias for a 32 byte fixed-size array which contains an encoding of a message topic

func NewTopic

func NewTopic(topic string) Topic

NewTopic creates a new Topic variable with the given input string the input string is taken as a byte slice and hashed

Jump to

Keyboard shortcuts

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