Documentation ¶
Index ¶
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
MarshalBinary serializes a message struct
func (*Message) UnmarshalBinary ¶
UnmarshalBinary deserializes a message struct
func (*Message) Wrap ¶
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