network

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: AGPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (

	// EmptyUDPSize is the size of an empty UDP packet
	EmptyUDPSize = 28
)

Variables

This section is empty.

Functions

func ApplyBPF

func ApplyBPF(rawConn *ipv4.RawConn, server *Server, client *PeerNet)

ApplyBPF constructs a BPF program and applies it to the RawConn

func GetClientIP

func GetClientIP(dstIP net.IP) net.IP

GetClientIP gets source ip address that will be used when sending data to dstIP

func HostToAddr

func HostToAddr(hostStr string) *net.IPAddr

HostToAddr resolves a hostname, whether DNS or IP to a valid net.IPAddr

func MakePacket

func MakePacket(payload []byte, server *Server, client *PeerNet) []byte

MakePacket constructs a request packet to send to the server

func ParseResponse

func ParseResponse(response []byte) (net.IP, uint16)

ParseResponse takes a response packet and parses it into an IP and port

func RecvDataPacket

func RecvDataPacket(conn *ipv4.RawConn, server *Server, client *PeerNet) ([]byte, error)

RecvDataPacket receives and unmarshals a JSON packet from server

func RecvPacket

func RecvPacket(conn *ipv4.RawConn, server *Server, client *PeerNet) ([]byte, int, error)

RecvPacket receives a UDP packet from server

func SendDataPacket

func SendDataPacket(data interface{}, conn *ipv4.RawConn, server *Server, client *PeerNet) error

SendDataPacket sends a JSON payload to the Server

func SendPacket

func SendPacket(packet []byte, conn *ipv4.RawConn, server *Server, client *PeerNet) error

SendPacket sends packet to the Server

func SetupRawConn

func SetupRawConn(server *Server, client *PeerNet) *ipv4.RawConn

SetupRawConn creates an ipv4 and udp only RawConn and applies packet filtering

Types

type PeerNet

type PeerNet struct {
	Resolved bool
	IP       net.IP
	Port     uint16
	NewtID   string
}

PeerNet stores data about a peer's endpoint

type Server

type Server struct {
	Hostname string
	Addr     *net.IPAddr
	Port     uint16
}

Server stores data relating to the server

Jump to

Keyboard shortcuts

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