dataplane

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Copyright (c) 2026 Veld Authors. SPDX-License-Identifier: MIT

Copyright (c) 2026 Veld Authors. SPDX-License-Identifier: MIT

Index

Constants

View Source
const (
	TypeData          uint32 = 0x01
	TypeHandshakeInit uint32 = 0x02
	TypeHandshakeResp uint32 = 0x03
	TypeKeepalive     uint32 = 0x04
	TypeNATProbe      uint32 = 0x05 // NAT hole-punch probe/reply
)
View Source
const HeaderSize = 16

Wire format for UDP packets:

[4B] packet_type
[4B] sender_index (reserved, 0 for now)
[8B] nonce
[NB] ChaCha20-Poly1305 ciphertext + 16B auth tag

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {

	// OnHandshakeRequired is called when a TUN packet is destined for a peer
	// that has no active session. The packet is already in the peer's hold queue.
	// The caller must eventually call entry.SetSession to drain the hold queue.
	// May be nil (hold queue fills and drops if no handler registered).
	OnHandshakeRequired func(entry *peer.Entry)

	// OnRekeyRequired is called when the current session hits the nonce threshold
	// (2^32 packets). The packet is already in the peer's hold queue. The caller
	// must clear the old session and initiate a fresh handshake — SetSession will
	// drain the hold queue once the new session is ready.
	// May be nil (packets queued until queue is full, then dropped).
	OnRekeyRequired func(entry *peer.Entry)

	// OnHandshakePacket is called for TypeHandshakeInit and TypeHandshakeResp packets.
	// pkt is the full wire packet (including 16-byte header); addr is the sender.
	OnHandshakePacket func(pkt []byte, addr net.Addr)

	// OnNATProbePacket is called for TypeNATProbe packets.
	// pkt is the full wire packet (including 16-byte header); addr is the sender.
	OnNATProbePacket func(pkt []byte, addr net.Addr)
	// contains filtered or unexported fields
}

Dispatcher routes encrypted packets between TUN and UDP.

func New

func New(t tun.TUN, conn net.PacketConn, peers *peer.Table) *Dispatcher

New creates a Dispatcher. Call Start to launch the I/O goroutines.

func (*Dispatcher) FlushHoldQueue

func (d *Dispatcher) FlushHoldQueue(entry *peer.Entry)

FlushHoldQueue drains the peer's hold queue and sends all held packets as encrypted data over UDP. Called by handshake.Manager.OnSessionEstablished.

func (*Dispatcher) Start

func (d *Dispatcher) Start()

Start launches the TUN→UDP and UDP→TUN goroutines.

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop closes the TUN and UDP conn, causing both loops to exit. Safe to call multiple times.

func (*Dispatcher) Wait

func (d *Dispatcher) Wait()

Wait blocks until both loops have exited.

Jump to

Keyboard shortcuts

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