network_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: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeSessionID

func DecodeSessionID(buf []byte) device.SessionID

func EncodeRREPHeader

func EncodeRREPHeader(reqID RequestID, sessID device.SessionID, ephemeralKey ecdh.PublicKey) []byte

func EncodeSessionID

func EncodeSessionID(session device.SessionID, buf []byte) []byte

func SessionSecret

func SessionSecret(container device.ContactsContainer, contact device.ContactID, ephemeral []byte, remoteEphemeral []byte) (device.SharedSecret, error)

Types

type NetworkLayer

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

func NewNetworkLayer

func NewNetworkLayer(dev device.Device, events NetworkLayerEvents, options device.ProtocolOptions) *NetworkLayer

func (*NetworkLayer) AllSessions

func (network *NetworkLayer) AllSessions(contact device.ContactID) []device.SessionID

func (*NetworkLayer) BroadcastPacket

func (network *NetworkLayer) BroadcastPacket(packet Packet)

func (*NetworkLayer) BroadcastPacketExcept

func (network *NetworkLayer) BroadcastPacketExcept(packet Packet, except device.DeviceAddress)

func (*NetworkLayer) BroadcastRouteRequest

func (network *NetworkLayer) BroadcastRouteRequest()

func (*NetworkLayer) DeleteContact

func (network *NetworkLayer) DeleteContact(contact device.ContactID)

func (*NetworkLayer) GetSession

func (network *NetworkLayer) GetSession(sessionID device.SessionID) (*SessionTableEntry, bool)

func (*NetworkLayer) NewRREP

func (network *NetworkLayer) NewRREP(reqID RequestID, sessID device.SessionID, sessionSecret []byte, ownEphemeralPublicKey ecdh.PublicKey, payload []byte) (*RREPPacket, error)

func (*NetworkLayer) NewSESSPacket

func (network *NetworkLayer) NewSESSPacket(sessionID device.SessionID, data []byte) (*SESSPacket, error)

func (*NetworkLayer) OnConnection

func (network *NetworkLayer) OnConnection(address device.DeviceAddress)

func (*NetworkLayer) OnDisconnection

func (network *NetworkLayer) OnDisconnection(address device.DeviceAddress)

func (*NetworkLayer) ReceivePacket

func (network *NetworkLayer) ReceivePacket(sender device.DeviceAddress, packet []byte) []SessionMessage

func (*NetworkLayer) SendData

func (network *NetworkLayer) SendData(session device.SessionID, data []byte) error

func (*NetworkLayer) SendRouteRequest

func (network *NetworkLayer) SendRouteRequest(address device.DeviceAddress, ttl TTL)

func (*NetworkLayer) SessionBroken

func (network *NetworkLayer) SessionBroken(sessID device.SessionID, address *device.DeviceAddress)

func (*NetworkLayer) SessionEstablished

func (network *NetworkLayer) SessionEstablished(contact device.ContactID, session device.SessionID, address device.DeviceAddress, payload []byte, isInitiator bool)

type NetworkLayerEvents

type NetworkLayerEvents 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
}

type Packet

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

func DecodeRoutingPacket

func DecodeRoutingPacket(data []byte) (Packet, error)

type PacketType

type PacketType int64
const (
	RREQ PacketType = 0x01
	RREP PacketType = 0x02
	SESS PacketType = 0x03
	RERR PacketType = 0x04
)

type PublicKey

type PublicKey int64

type RERRPacket

type RERRPacket struct {
	SessionID device.SessionID
}

func DecodeRERR

func DecodeRERR(buf []byte) (*RERRPacket, error)

func NewRERR

func NewRERR(sessionID device.SessionID) *RERRPacket

func (*RERRPacket) EncodePacket

func (p *RERRPacket) EncodePacket() []byte

func (*RERRPacket) PacketType

func (p *RERRPacket) PacketType() PacketType

type RREPPacket

type RREPPacket struct {
	RequestID    RequestID
	SessionID    device.SessionID
	EphemeralKey ecdh.PublicKey
	Nonce        []byte
	// Cipher contains the authentication tag as well as some optional payload
	Cipher []byte
}

func DecodeRREP

func DecodeRREP(buf []byte) (*RREPPacket, error)

func (*RREPPacket) EncodePacket

func (p *RREPPacket) EncodePacket() []byte

func (*RREPPacket) PacketType

func (p *RREPPacket) PacketType() PacketType

type RREQPacket

type RREQPacket struct {
	RequestID    RequestID
	TTL          TTL
	EphemeralKey ecdh.PublicKey
	ContactMask  contact_bitmap.ContactBitmap
}

func DecodeRREQ

func DecodeRREQ(buf []byte) (*RREQPacket, error)

func NewRREQPacket

func NewRREQPacket(reqID RequestID, ttl TTL, ephemeralKey ecdh.PublicKey, contactMap contact_bitmap.ContactBitmap) *RREQPacket

func (*RREQPacket) EncodePacket

func (packet *RREQPacket) EncodePacket() []byte

func (*RREQPacket) PacketType

func (*RREQPacket) PacketType() PacketType

type RequestID

type RequestID uint64

func DecodeRequestID

func DecodeRequestID(buf []byte) RequestID

func (RequestID) Encode

func (r RequestID) Encode(buf []byte) []byte

type RequestTable

type RequestTable map[RequestID]*RequestTableEntry

type RequestTableEntry

type RequestTableEntry struct {
	RequestID           RequestID
	SourceNeighbour     *device.DeviceAddress
	EphemeralPrivateKey *ecdh.PrivateKey
}

func NewRequestTableEntry

func NewRequestTableEntry(reqID RequestID, source *device.DeviceAddress, ephemeral *ecdh.PrivateKey) RequestTableEntry

type SESSPacket

type SESSPacket struct {
	SessionID device.SessionID
	Nonce     []byte
	Cipher    []byte
}

func DecodeSESS

func DecodeSESS(buf []byte) (*SESSPacket, error)

func (*SESSPacket) EncodePacket

func (packet *SESSPacket) EncodePacket() []byte

func (*SESSPacket) PacketType

func (*SESSPacket) PacketType() PacketType

type SessionMessage

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

func (*SessionMessage) Data

func (d *SessionMessage) Data() []byte

func (*SessionMessage) SessionID

func (d *SessionMessage) SessionID() device.SessionID

type SessionTable

type SessionTable map[device.SessionID]*SessionTableEntry

type SessionTableEntry

type SessionTableEntry struct {
	RequestID       RequestID
	SessionID       device.SessionID
	Contact         *device.ContactID
	SourceNeighbour *device.DeviceAddress
	TargetNeighbour *device.DeviceAddress
	SessionSecret   []byte
}

func SessionEntryFromRREP

func SessionEntryFromRREP(random *rand.Rand, contact *device.ContactID, reqEntry RequestTableEntry, rrep RREPPacket, sender *device.DeviceAddress, sessionSecret []byte) SessionTableEntry

func SessionEntryFromRREQ

func SessionEntryFromRREQ(random *rand.Rand, contact *device.ContactID, reqEntry RequestTableEntry, sender *device.DeviceAddress, sessionSecret []byte) SessionTableEntry

func (*SessionTableEntry) EndpointSession

func (s *SessionTableEntry) EndpointSession() bool

type TTL

type TTL uint16

func DecodeTTL

func DecodeTTL(buf []byte) TTL

func (TTL) Encode

func (ttl TTL) Encode(buf []byte) []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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