transport_layer

package
v0.0.0-...-8e980cd Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ACKPacket

type ACKPacket struct {
	LatestSeqID   SequenceID
	MissingSeqIDs []SequenceID
}

func DecodeACKPacket

func DecodeACKPacket(buf []byte) (*ACKPacket, error)

func NewACKPacket

func NewACKPacket(latestSeqID SequenceID, missingSeqIDs []SequenceID) *ACKPacket

func (*ACKPacket) EncodePacket

func (d *ACKPacket) EncodePacket() []byte

func (*ACKPacket) PacketType

func (d *ACKPacket) PacketType() PacketType

type DATAPacket

type DATAPacket struct {
	SeqID SequenceID
	Data  []byte
}

func DecodeDataPacket

func DecodeDataPacket(buf []byte) (*DATAPacket, error)

func NewDATAPacket

func NewDATAPacket(seqID SequenceID, data []byte) *DATAPacket

func (*DATAPacket) EncodePacket

func (d *DATAPacket) EncodePacket() []byte

func (*DATAPacket) PacketType

func (d *DATAPacket) PacketType() PacketType

type Packet

type Packet interface {
	EncodePacket() []byte
	PacketType() PacketType
}

type PacketType

type PacketType int64
const (
	DATA PacketType = 0x01
	ACK  PacketType = 0x02
)

type ReceiverState

type ReceiverState struct {
	// contains filtered or unexported fields
}

type SenderState

type SenderState struct {
	// contains filtered or unexported fields
}

type SequenceID

type SequenceID uint32

func DecodeSequenceID

func DecodeSequenceID(buf []byte) SequenceID

func (SequenceID) Encode

func (s SequenceID) Encode(buf []byte) []byte

type SessionState

type SessionState struct {
	// contains filtered or unexported fields
}

func NewSessionState

func NewSessionState(sessionID device.SessionID) *SessionState

func (*SessionState) DeliverMessage

func (state *SessionState) DeliverMessage(transport *TransportLayer, message outboxMessage) SequenceID

DeliverMessage registers a message as awaiting an ack, it returns the sequence ID for the new packet to be delivered.

func (*SessionState) ReceiveACK

func (state *SessionState) ReceiveACK(transport *TransportLayer, packet *ACKPacket) []*DATAPacket

func (*SessionState) ReceiveDATA

func (state *SessionState) ReceiveDATA(transport *TransportLayer, packet *DATAPacket) []*DATAPacket

Updates the local state with the incoming packet. Returns a list of packets (in ascending sorted order by their sequence ID) that can now be delivered.

type TransportEvents

type TransportEvents interface {
	SessionEstablished(session device.SessionID, contact device.ContactID, address device.DeviceAddress, payload []byte, isInitiator bool)
	SessionBroken(session device.SessionID)
	ReplyPayload(session device.SessionID, contact device.ContactID) []byte
	MessageDelivered(messageID device.MessageID)
}

type TransportLayer

type TransportLayer struct {
	// contains filtered or unexported fields
}

func NewTransportLayer

func NewTransportLayer(dev device.Device, events TransportEvents, options device.ProtocolOptions) *TransportLayer

func (*TransportLayer) AllSessions

func (transport *TransportLayer) AllSessions(contact device.ContactID) []device.SessionID

func (*TransportLayer) BroadcastRouteRequest

func (transport *TransportLayer) BroadcastRouteRequest()

func (*TransportLayer) DeleteContact

func (transport *TransportLayer) DeleteContact(contact device.ContactID)

func (*TransportLayer) OnConnection

func (transport *TransportLayer) OnConnection(address device.DeviceAddress)

func (*TransportLayer) OnDisconnection

func (transport *TransportLayer) OnDisconnection(address device.DeviceAddress)

func (*TransportLayer) ReceivePacket

func (transport *TransportLayer) ReceivePacket(address device.DeviceAddress, packet []byte) []TransportMessage

func (*TransportLayer) SendMessage

func (transport *TransportLayer) SendMessage(sessionID device.SessionID, message []byte) (device.MessageID, error)

func (*TransportLayer) SessionContact

func (transport *TransportLayer) SessionContact(sessionID device.SessionID) (*device.ContactID, bool)

func (*TransportLayer) SessionState

func (transport *TransportLayer) SessionState(sessionID device.SessionID) *SessionState

func (*TransportLayer) TimeoutSession

func (transport *TransportLayer) TimeoutSession(sessionID device.SessionID)

type TransportMessage

type TransportMessage struct {
	Contact device.ContactID
	Session device.SessionID
	Data    []byte
}

Jump to

Keyboard shortcuts

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