uniproto

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HandshakeMinVersion = 1
	HandshakeMaxVersion = HeaderByteSizeMin - 1

	HandshakeMaxPhase = 0
)
View Source
const (
	HeaderByteSizeMin = 16
	HeaderByteSizeMax = HeaderByteSizeMin + 4
)
View Source
const (
	PacketTypeCount = 1 << packetTypeBitSize
	PacketTypeMax   = PacketTypeCount - 1

	ProtocolTypeCount = 1 << protocolTypeBitSize
	ProtocolTypeMax   = ProtocolTypeCount - 1

	MinLengthBits         = 5
	SmallLengthBits       = payloadLengthBits
	ExcessiveLengthBits   = SmallLengthBits + 32
	MaxLengthBits         = ExcessiveLengthBits
	MaxNonExcessiveLength = 1<<payloadLengthBits - 1
)
View Source
const (
	PacketByteSizeMin                       = HeaderByteSizeMin + pulse.NumberSize
	LargePacketBaselineWithoutSignatureSize = HeaderByteSizeMax + pulse.NumberSize // + PacketSignatureSize
)
View Source
const AllowAll = ^ConnectionMode(0)
View Source
const HandshakeMagic = "INS"
View Source
const ProtocolTypeInterprocess = ProtocolTypePulsar

Variables

View Source
var DefaultByteOrder = binary.BigEndian
View Source
var ErrPossibleHTTPRequest = errors.New("possible HTTP request")

ErrPossibleHTTPRequest is returned when a protected HTTP header is detected

Functions

func CalcExcessivePayloadLength

func CalcExcessivePayloadLength(baseLength uint16, excessive uint32) uint64

func DeserializePulseNumber

func DeserializePulseNumber(r io.Reader) (pulse.Number, error)

func DeserializePulseNumberFromBytes

func DeserializePulseNumberFromBytes(b []byte) (pulse.Number, error)

func SerializePulseNumber

func SerializePulseNumber(pn pulse.Number, w io.Writer) error

func SerializePulseNumberToBytes

func SerializePulseNumberToBytes(pn pulse.Number, b []byte)

Types

type ConnectionMode

type ConnectionMode uint32
const (
	AllowUnknownPeer ConnectionMode = 1 << iota
)

func NewConnectionMode

func NewConnectionMode(m ConnectionMode, pts ...ProtocolType) ConnectionMode

func (ConnectionMode) AllowedSet

func (v ConnectionMode) AllowedSet() ProtocolSet

func (ConnectionMode) IsProtocolAllowed

func (v ConnectionMode) IsProtocolAllowed(pt ProtocolType) bool

func (ConnectionMode) IsUnknownPeerAllowed

func (v ConnectionMode) IsUnknownPeerAllowed() bool

func (ConnectionMode) SetAllowedSet

func (v ConnectionMode) SetAllowedSet(s ProtocolSet) ConnectionMode

type Controller

type Controller interface {
	// Start is called when protocol(s) should be activated. Individual protocols can be started or stopped multiple times.
	Start(PeerManager)
	// NextPulse is called when a next pulse is committed. Must be fast, can trigger housekeeping etc.
	// Also NextPulse has to be called immediately after Start with the latest pulse.Range when applicable.
	NextPulse(pulse.Range)
	// Start is called when protocol(s) should be deactivated. Individual protocols can be started or stopped multiple times.
	Stop()
}

Controller is an interface for life-cycle of a protocol or a set of protocols.

type Descriptor

type Descriptor struct {

	// Supporter is optional
	Supporter Supporter
	// SupportedPackets is a list of packet types supported by the protocol.
	// There are some restrictions on protocol type / packet type combinations. See ProtocolType.
	SupportedPackets PacketDescriptors
}

Descriptor provides information about a protocol. Each protocol has to define at least packet type #0.

func (Descriptor) IsSupported

func (d Descriptor) IsSupported() bool

type Descriptors

type Descriptors [ProtocolTypeCount]Descriptor

type Dispatcher

type Dispatcher interface {
	Controller

	// GetMode returns information about allowed protocols and flags.
	GetMode() ConnectionMode
	// GetReceiver returns a Receiver for the given protocol. Will return nil when the protocol is not know / not supported.
	GetReceiver(pt ProtocolType) Receiver
	// Seal should return a list of protocol's descriptors known to this Dispatcher. No changes are allowed after this call.
	Seal() Descriptors
}

Dispatcher provides life-cycle management for a set of protocols. Dispatcher can only be started (and stopped) once.

type FlagIndex

type FlagIndex uint8

type Flags

type Flags uint8

Flags is flags of a packet type of a protocol.

const (
	// DatagramOnly allows receiving of this packet type ONLY over a sessionless connection.
	DatagramOnly Flags = 1 << iota
	// DatagramOnly allows receiving of this packet type over a sessionless connection.
	DatagramAllowed
	// DisableRelay disallows packet relays. Only packets delivered directly will be accepted.
	DisableRelay
	// OmitSignatureOverTLS omits packet signature(s) for direct packets when TLS connection is in use.
	// Use of this flag will deny TLS connections with unrecognized certificates.
	OmitSignatureOverTLS
	// SourcePK indicates presence of source's PK in the packet header. And PK can be used to verify packet.
	SourcePK
	// OptionalTarget allows non-specified target for this packet type. E.g. to send to an unknown or to multiple peers.
	OptionalTarget
	// NoSourceID requires source id to be 0 (unspecified). Applied for requests from external / unknown nodes.
	NoSourceID
)

type HandshakeFlags

type HandshakeFlags uint8
const (
	HandshakeLarge HandshakeFlags
)

type HandshakeHeader

type HandshakeHeader struct {
	// Magic   [3]uint8 = "INS"
	Phase uint8
	// _    uint8          `insolar-transport:"[:]=0"`
	Flags   HandshakeFlags `insolar-transport:"[0]=1;[1]=0;[2]=IsLarge"`
	Version uint8          `insolar-transport:"[0:15]=1..15"` // value MUST be less than HeaderByteSizeMin
	// _    uint8
	Random uint64
}
ByteSize=16

HandshakeHeader is compatible with Header, but uses length = 0, which is invalid for a normal header. It is used for off-protocol operations, like handshake or heartbeat.

func (*HandshakeHeader) Deserialize

func (p *HandshakeHeader) Deserialize(b []byte) int

func (*HandshakeHeader) Serialize

func (p *HandshakeHeader) Serialize(b []byte) int
type Header struct {
	ReceiverID uint32 // NB! For hash/signature calculation MUST be considered as 0, actual value can be different

	ProtocolAndPacketType  uint8  `insolar-transport:"[0:3]=header:Packet;[4:7]=header:Protocol"` // [00-03]PacketType [04-07]ProtocolType
	PacketFlags            uint8  `insolar-transport:"[0]=IsRelayRestricted;[1]=IsBodyEncrypted;[2:]=flags:PacketFlags"`
	HeaderAndPayloadLength uint16 `insolar-transport:"[14]=reserved;[15]=IsExcessiveLength"`
	SourceID               uint32 // may differ from actual sender when relay is in use
	TargetID               uint32 // indicates final destination, if IsRelayRestricted then there is no relay allowed by sender and receiver MUST decline a packet if actual sender != source

	ExcessiveLength uint32 `insolar-transport:"optional=IsExcessiveLength"`
}
ByteSize=16-20

Header represents a header of uniproto packet. It is non-encrypted part of a packet with minimal set of identities, flags and packet size.

func (*Header) ByteSize

func (h *Header) ByteSize() uint

func (*Header) DeserializeFrom

func (h *Header) DeserializeFrom(reader io.Reader) error

func (*Header) DeserializeFromBytes

func (h *Header) DeserializeFromBytes(b []byte) (uint, error)

func (*Header) DeserializeMinFromBytes

func (h *Header) DeserializeMinFromBytes(b []byte) error

func (*Header) DeserializeRestFromBytes

func (h *Header) DeserializeRestFromBytes(b []byte) (int, error)

func (*Header) GetFlagRangeInt

func (h *Header) GetFlagRangeInt(from, to uint8) uint8

func (*Header) GetFullLength

func (h *Header) GetFullLength() (uint64, error)

func (Header) GetHashingZeroPrefix

func (Header) GetHashingZeroPrefix() int

func (*Header) GetPacketSize

func (h *Header) GetPacketSize(dataSize uint, sigSize uint) uint

func (*Header) GetPacketType

func (h *Header) GetPacketType() uint8

func (*Header) GetPayloadLength

func (h *Header) GetPayloadLength() (uint64, error)

func (*Header) GetProtocolType

func (h *Header) GetProtocolType() ProtocolType

func (*Header) HasFlag

func (h *Header) HasFlag(f FlagIndex) bool

func (*Header) IsBodyEncrypted

func (h *Header) IsBodyEncrypted() bool

func (*Header) IsExcessiveLength

func (h *Header) IsExcessiveLength() bool

func (*Header) IsForRelay

func (h *Header) IsForRelay() bool

func (*Header) IsRelayRestricted

func (h *Header) IsRelayRestricted() bool

func (*Header) IsTargeted

func (h *Header) IsTargeted() bool

func (*Header) IsValid

func (h *Header) IsValid() bool

func (*Header) IsZero

func (h *Header) IsZero() bool

func (*Header) SerializeToBytes

func (h *Header) SerializeToBytes(b []byte) uint

func (*Header) SetBodyEncrypted

func (h *Header) SetBodyEncrypted(encrypted bool)

func (*Header) SetFlag

func (h *Header) SetFlag(f FlagIndex, v bool)

func (*Header) SetPacketType

func (h *Header) SetPacketType(packetType uint8)

func (*Header) SetPayloadLength

func (h *Header) SetPayloadLength(payloadLength uint64) uint64

func (*Header) SetProtocolType

func (h *Header) SetProtocolType(protocolType ProtocolType)

func (*Header) SetRelayRestricted

func (h *Header) SetRelayRestricted(isRestricted bool)

type OutFunc

type OutFunc func(l1.BasicOutTransport) (canRetry bool, err error)

OutFunc receives a specific transport and should use its methods to send data. WARNING! When Sessionless transport is allowed then this func MUST ONLY send a single chunk of data. Otherwise delivery will be broken. NB! Should use l1.BasicOutTransport.Send when source of data is file or another network connection. Function should return (canRetry) when retry is possible for this transfer.

type OutTransport

type OutTransport interface {
	// UseSessionless applies OutFunc on a sessionless transport. This function is non-blocking when a connection is established.
	// WARNING! OutFunc MUST ONLY send a single chunk of data. Otherwise delivery will be broken.
	UseSessionless(OutFunc) error
	// UseSessionful applies OutFunc on a sessionful transport, either for small or for large packets.
	// This function is blocking. Both small and large transports have individual mutexes.
	UseSessionful(size int64, applyFn OutFunc) error
	// CanUseSessionless returns true when Sessionless server is listening (otherwise replies will be lost) and size is supported by sessionless transport.
	CanUseSessionless(size int64) bool
	// EnsureConnect forces connection of sessionful transport for small packet. Is used to check availability of a peer.
	// This function is non-blocking when a connection is established.
	EnsureConnect() error
}

type OutType

type OutType uint8

OutType defines a type of transport allowed for a send operation.

const (
	// Any enables use of any transport based on packet size. Sessionless will be preferred over SessionfulSmall.
	Any OutType = iota
	// SessionfulAny allows use of either SessionfulSmall or SessionfulLarge based on packet size.
	SessionfulAny
	// SessionfulLarge allows ONLY use of sessionful large-packet transport, irrelevant of packet size.
	SessionfulLarge
	// SessionfulLarge allows ONLY use of sessionful small-packet transport, irrelevant of packet size.
	// Packets larger than uniproto.MaxNonExcessiveLength will be rejected locally with an error.
	SessionfulSmall
	// SmallAny allows use of either Sessionless or SessionfulSmall. Sessionless is preferred when size allows.
	// Packets larger than uniproto.MaxNonExcessiveLength will be rejected locally with an error.
	SmallAny
	// Sessionless allows ONLY use of sessionless transport.
	// Packets larger than transport's size limit will be rejected locally with an error.
	Sessionless
	// SessionlessNoQuota allows ONLY use of sessionless transport. Quota limits will be ignored.
	// Packets larger than transport's size limit will be rejected locally with an error.
	// NB! Only for use by consensus / low latency packets.
	SessionlessNoQuota
)

type Packet

type Packet struct {
	Header      Header
	PulseNumber pulse.Number `insolar-transport:"[30-31]=0"`
}

Packet represents a logical packet of a protocol

func (*Packet) DeserializeMinFrom

func (p *Packet) DeserializeMinFrom(reader io.Reader) error

func (*Packet) DeserializeMinFromBytes

func (p *Packet) DeserializeMinFromBytes(b []byte) (int, error)

func (*Packet) DeserializePayload

func (p *Packet) DeserializePayload(ctx nwapi.DeserializationContext, r io.Reader, readLimit int64, decrypter cryptkit.Decrypter, fn PayloadDeserializeFunc) error

func (*Packet) GetPacketSize

func (p *Packet) GetPacketSize(dataSize, sigSize uint) uint

func (*Packet) GetPayloadOffset

func (p *Packet) GetPayloadOffset() uint

func (*Packet) SerializeMinToBytes

func (p *Packet) SerializeMinToBytes(b []byte) uint

func (*Packet) SerializePayload

func (p *Packet) SerializePayload(ctx nwapi.SerializationContext, writer *iokit.LimitedWriter, dataSize uint, encrypter cryptkit.Encrypter, fn PayloadSerializerFunc) error

func (*Packet) VerifyExcessivePayload

func (p *Packet) VerifyExcessivePayload(sv PacketVerifier, preload *[]byte, r io.Reader) error

func (*Packet) VerifyNonExcessivePayload

func (p *Packet) VerifyNonExcessivePayload(sv PacketVerifier, b []byte) error

type PacketDataSigner

type PacketDataSigner struct {
	Signer cryptkit.DataSigner
}

func (PacketDataSigner) GetSignatureSize

func (v PacketDataSigner) GetSignatureSize() uint

func (PacketDataSigner) NewHasher

func (v PacketDataSigner) NewHasher(h *Header) (int, cryptkit.DigestHasher)

func (PacketDataSigner) NewHasherWith

func (v PacketDataSigner) NewHasherWith(h *Header, b []byte) cryptkit.DigestHasher

func (PacketDataSigner) SumToSignatureBytes

func (v PacketDataSigner) SumToSignatureBytes(hasher cryptkit.DigestHasher, b []byte)

type PacketDescriptor

type PacketDescriptor struct {
	Flags Flags
	// LengthBits is a number of bits used to represent maximum size of a packet.
	// When LengthBits is [0..4], less than MinLengthBits, then the packet is considered as disabled.
	// When LengthBits is over ExcessiveLengthBits then this packet can't be supported yet.
	LengthBits uint8
}

PacketDescriptor defines flags and packet size limit for a given packet type of a protocol.

func (PacketDescriptor) IsAllowedLength

func (d PacketDescriptor) IsAllowedLength(fullLen uint64) bool

func (PacketDescriptor) IsSupported

func (d PacketDescriptor) IsSupported() bool

type PacketDescriptors

type PacketDescriptors [PacketTypeCount]PacketDescriptor

type PacketPreparer

type PacketPreparer interface {
	// PreparePacket returns pre-populated header, size of data to be included into the packet (excludes all packet fields),
	// and a data serialization function.
	PreparePacket() (template PacketTemplate, dataSize uint, dataFn PayloadSerializerFunc)
}

PacketPreparer is a factory to provide a to-be-sent packet and necessary information.

type PacketSerializerFunc

type PacketSerializerFunc func() (template PacketTemplate, dataSize uint, dataFn PayloadSerializerFunc)

type PacketSet

type PacketSet uint16
const AllPackets PacketSet = ^PacketSet(0)

func (PacketSet) Has

func (v PacketSet) Has(pt uint8) bool

func (PacketSet) Set

func (v PacketSet) Set(pt uint8, val bool) PacketSet

type PacketTemplate

type PacketTemplate struct {
	Packet
}

type PacketVerifier

type PacketVerifier struct {
	Verifier cryptkit.DataSignatureVerifier
}

func (PacketVerifier) GetSignatureSize

func (v PacketVerifier) GetSignatureSize() int

func (PacketVerifier) NewHasher

func (v PacketVerifier) NewHasher(h *Header) (int, cryptkit.DigestHasher)

func (PacketVerifier) VerifySignature

func (v PacketVerifier) VerifySignature(digest cryptkit.Digest, signatureBytes []byte) error

func (PacketVerifier) VerifyWhole

func (v PacketVerifier) VerifyWhole(h *Header, b []byte) error

type Parser

type Parser struct {
	Protocols   Descriptors
	SigSizeHint int // a pre-allocation hint, MUST be >= actual size from cryptkit.DataSignatureVerifier
	Dispatcher  Dispatcher
}

Parser is a helper structure to receive and check packet

func (Parser) GetMode

func (p Parser) GetMode() ConnectionMode

func (Parser) ReceiveDatagram

func (p Parser) ReceiveDatagram(packet *ReceivedPacket, headerFn VerifyHeaderFunc, b []byte) (int, error)

func (Parser) ReceivePacket

func (p Parser) ReceivePacket(packet *ReceivedPacket, headerFn VerifyHeaderFunc, r io.Reader, allowExcessive bool,
) (preRead []byte, more int64, err error)

type PayloadDeserializeFunc

type PayloadDeserializeFunc func(nwapi.DeserializationContext, *Packet, *iokit.LimitedReader) error

PayloadDeserializeFunc should read packet and its content. Param (iokit.LimitedReader) contains data past the packet's default header.

type Peer

type Peer interface {
	// GetPrimary returns a peer's primary identity
	GetPrimary() nwapi.Address
	// GetLocalUID returns a locally unique peer's address.
	// This address can only be used locally and it will change after each disconnection of the peer.
	GetLocalUID() nwapi.Address
	// GetNodeID returns ShortNodeID of the peer. Result can be zero. ShortNodeID is related to consensus operations.
	GetNodeID() nwapi.ShortNodeID

	// GetSignatureKey returns peer's signature key. Key can be zero.
	GetSignatureKey() cryptkit.SigningKey

	// SetProtoInfo sets/updated per-protocol peer's projection (info). It will be closed when the peer is unregistered.
	SetProtoInfo(pt ProtocolType, info io.Closer)
	// GetOrCreateProtoInfo performs "atomic" get or create of peer's projection for the given protocol.
	GetProtoInfo(pt ProtocolType) io.Closer
	// GetOrCreateProtoInfo performs "atomic" get or create of peer's projection for the given protocol.
	GetOrCreateProtoInfo(pt ProtocolType, factoryFn func(Peer) io.Closer) io.Closer

	// Transport returns a multiplexed transport over available peer's transports.
	// This transport does internal connection management (retry, reconnect, etc).
	Transport() OutTransport
	// SendPacket is a convenience handler to send a packet provided by uniproto.PacketPreparer.
	// See SendPreparedPacket for details.
	SendPacket(tp OutType, packet PacketPreparer) error
	// SendPreparedPacket prepares uniproto packet and checks its eligibility for the given (uniproto.OutType).
	// Can also choose a specific out type by properties of packet and value of (uniproto.OutType).
	// See SendingPacket.NewTransportFunc for details about serialization.
	SendPreparedPacket(tp OutType, packet *Packet, dataSize uint, fn PayloadSerializerFunc, checkFn func() bool) error
}

type PeerManager

type PeerManager interface {
	// ConnectPeer either returns a known peer for the given address. Or attempts to connect the given address with EnsureConnect().
	// A new Peer will not be added if an error occur. For local peer will return (nil, nil).
	ConnectPeer(nwapi.Address) (Peer, error)
	// ConnectedPeer returns an already known peer for the given address.
	// Returns error when peer is unknown. For local peer will return (nil, nil).
	ConnectedPeer(nwapi.Address) (Peer, error)

	// MaxSessionlessPayloadSize returns a max size of a packet allowed for sessionless delivery.
	MaxSessionlessPayloadSize() uint
	// MaxSessionlessPayloadSize returns a max size of a packet allowed for small session-based delivery.
	MaxSmallPayloadSize() uint
	// LocalPeer returns a peer representing the local host.
	LocalPeer() Peer
}

PeerManager provides access to a set of peers.

type ProtocolPacket

type ProtocolPacket interface {
	PacketPreparer
	SerializePayload(nwapi.SerializationContext, *Packet, *iokit.LimitedWriter) error
	DeserializePayload(nwapi.DeserializationContext, *Packet, *iokit.LimitedReader) error
}

type ProtocolSet

type ProtocolSet uint16
const AllProtocols ProtocolSet = ^ProtocolSet(0)

func NewPacketSet

func NewPacketSet(pts ...ProtocolType) ProtocolSet

func NewProtocolSet

func NewProtocolSet(pts ...ProtocolType) ProtocolSet

func (ProtocolSet) ForEach

func (v ProtocolSet) ForEach(fn func(pt ProtocolType) bool) bool

func (ProtocolSet) Has

func (v ProtocolSet) Has(pt ProtocolType) bool

func (ProtocolSet) Set

func (v ProtocolSet) Set(pt ProtocolType, val bool) ProtocolSet

type ProtocolType

type ProtocolType uint8

ProtocolType defines a type of a protocol for a packet. Can be [0, 15]. ATTENTION! To provide compatibility with HTTP GET, PUT and POST following restrictions apply 1) "POST /", "HEAD /" - Protocol=2, Packet=0 must have PacketFlags[5:] = 0 2) "GET /", "PUT /" Protocol=2, Packet=0x0F is forbidden 3) "OPTION" - Protocol=4, Packet=0xF must have PacketFlags[6:] = 0

const (
	ProtocolTypePulsar ProtocolType = iota
	ProtocolTypeGlobulaConsensus
	ProtocolTypeJoinCandidate
	ProtocolTypeMessageDelivery
)

type ReceivedPacket

type ReceivedPacket struct {
	// Packet is a standard part of a packet.
	Packet
	// From is a transport-specific address of a remote endpoint.
	From nwapi.Address
	// Peer represents a peer for the given remote endpoint.
	Peer Peer

	// Decrypter is provided when packet's content is encrypted.
	Decrypter cryptkit.Decrypter
	// contains filtered or unexported fields
}

ReceivedPacket represents a received packet with additional information, Also ReceivedPacket provides a few convenience functions to unify deserialization of different packet types.

func (ReceivedPacket) DownstreamError

func (ReceivedPacket) DownstreamError(err error) error

DownstreamError filters errors from downstream (from transport) as they will be handled there. DO NOT attempt to remediate transport errors.

func (*ReceivedPacket) GetContext

GetContext is a helper to create nwapi.DeserializationContext with necessary dependencies.

func (*ReceivedPacket) GetSignatureSize

func (p *ReceivedPacket) GetSignatureSize() int

GetSignatureSize returns size of a signature applicable fot this packet.

func (*ReceivedPacket) NewLargePayloadDeserializer

func (p *ReceivedPacket) NewLargePayloadDeserializer(preRead []byte, r io.LimitedReader) PacketDeserializerFunc

NewLargePayloadDeserializer returns a unified PacketDeserializerFunc to a large (partially-read) packet. Param (preRead) is a pre-read portion of the packet, and it MUST correlate with p.Packet. Param (r) is unread portion of the packet from the transport. WARNING! Transfer of other large packets of all protocols is BLOCKED until content of (r) will be read.

func (*ReceivedPacket) NewSmallPayloadDeserializer

func (p *ReceivedPacket) NewSmallPayloadDeserializer(b []byte) PacketDeserializerFunc

NewSmallPayloadDeserializer returns a unified PacketDeserializerFunc to read a small (fully-read) packet. Param (b) is a fully read packet, and it MUST correlate with p.Packet.

type Receiver

type Receiver interface {
	// ReceiveSmallPacket is called on small (non-excessive length) packets, (b) is exactly whole packet
	ReceiveSmallPacket(rp *ReceivedPacket, b []byte)
	// ReceiveLargePacket is called on large (excessive length) packets, (preRead) is a pre-read portion, that can be larger than a header, and (r) is configured for the remaining length.
	ReceiveLargePacket(rp *ReceivedPacket, preRead []byte, r io.LimitedReader) error
}

type RegisterControllerFunc

type RegisterControllerFunc func(ProtocolType, Descriptor, Controller, Receiver)

RegisterControllerFunc is provided to register a protocol. For each protocol there should be provided ProtocolType, a Descriptor with protocol's packets and feature, a Controller and Receiver.

type RegisterProtocolFunc

type RegisterProtocolFunc func(RegisterControllerFunc)

type SendingPacket

type SendingPacket struct {
	// Packet is a standard part of a packet.
	Packet
	// Peer represents a peer for this packet. Not in use.
	Peer Peer
	// contains filtered or unexported fields
}

ReceivedPacket represents a to-be-sent packet. Also ReceivedPacket provides a few convenience functions to unify serialization of different packet types.

func NewSendingPacket

func NewSendingPacket(signer cryptkit.DataSigner, encrypter cryptkit.Encrypter) *SendingPacket

NewSendingPacket creates a to-be-sent packet. Param (encrypter) is only required when encryption is needed.

func (*SendingPacket) GetContext

func (p *SendingPacket) GetContext() nwapi.SerializationContext

func (*SendingPacket) GetSignatureSize

func (p *SendingPacket) GetSignatureSize() uint

GetSignatureSize returns size of a signature applicable fot this packet.

func (*SendingPacket) NewTransportFunc

func (p *SendingPacket) NewTransportFunc(dataSize uint, fn PayloadSerializerFunc, checkFn func() bool) (uint, OutFunc)

NewTransportFunc provides ready-to-use arguments for OutTransport methods. for the given payload data and PayloadSerializerFunc. When option (checkFn) is provided, it will be invoked before each send attempt and it can return false to prevent from (re)sending.

func (*SendingPacket) SerializeToBytes

func (p *SendingPacket) SerializeToBytes(dataSize uint, fn PayloadSerializerFunc) ([]byte, error)

SerializeToBytes assists with serialization of a packet into memory from the given payload data size and PayloadSerializerFunc

type Supporter

type Supporter interface {
	VerifyHeader(*Header, pulse.Number, cryptkit.DataSignatureVerifier) (cryptkit.DataSignatureVerifier, error)
	FromPacketToHostID(id uint32) nwapi.HostID
	FromLocalToPacket(nwapi.ShortNodeID) uint32
}

type VerifyHeaderFunc

type VerifyHeaderFunc func(h *Header, flags Flags, s Supporter) (cryptkit.DataSignatureVerifier, error)

VerifyHeaderFunc can provide DataSignatureVerifier for the given packet.

Directories

Path Synopsis
l2

Jump to

Keyboard shortcuts

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