refactoring a bit

This commit is contained in:
JackDoan
2025-12-18 13:27:28 -06:00
parent f5c46c43ce
commit 41c9a3b2eb
19 changed files with 229 additions and 387 deletions

View File

@@ -10,7 +10,7 @@ import (
const MTU = 9001
type EncReader func(
[]*packet.Packet,
[]*packet.UDPPacket,
)
type Conn interface {
@@ -19,8 +19,8 @@ type Conn interface {
ListenOut(r EncReader)
WriteTo(b []byte, addr netip.AddrPort) error
ReloadConfig(c *config.C)
Prep(pkt *packet.Packet, addr netip.AddrPort) error
WriteBatch(pkt []*packet.Packet) (int, error)
Prep(pkt *packet.UDPPacket, addr netip.AddrPort) error
WriteBatch(pkt []*packet.UDPPacket) (int, error)
SupportsMultipleReaders() bool
Close() error
}

View File

@@ -215,7 +215,7 @@ func (u *StdConn) WriteToBatch(b []byte, ip netip.AddrPort) error {
return u.writeTo6(b, ip)
}
func (u *StdConn) Prep(pkt *packet.Packet, addr netip.AddrPort) error {
func (u *StdConn) Prep(pkt *packet.UDPPacket, addr netip.AddrPort) error {
//todo move this into pkt
nl, err := u.encodeSockaddr(pkt.Name, addr)
if err != nil {
@@ -226,7 +226,7 @@ func (u *StdConn) Prep(pkt *packet.Packet, addr netip.AddrPort) error {
return nil
}
func (u *StdConn) WriteBatch(pkts []*packet.Packet) (int, error) {
func (u *StdConn) WriteBatch(pkts []*packet.UDPPacket) (int, error) {
if len(pkts) == 0 {
return 0, nil
}
@@ -235,7 +235,7 @@ func (u *StdConn) WriteBatch(pkts []*packet.Packet) (int, error) {
//u.iovs = u.iovs[:0]
sent := 0
var mostRecentPkt *packet.Packet
var mostRecentPkt *packet.UDPPacket
mostRecentPktSize := 0
//segmenting := false
idx := 0

View File

@@ -52,9 +52,9 @@ func setCmsgLen(h *unix.Cmsghdr, l int) {
h.Len = uint64(l)
}
func (u *StdConn) PrepareRawMessages(n int, isV4 bool) ([]rawMessage, []*packet.Packet) {
func (u *StdConn) PrepareRawMessages(n int, isV4 bool) ([]rawMessage, []*packet.UDPPacket) {
msgs := make([]rawMessage, n)
packets := make([]*packet.Packet, n)
packets := make([]*packet.UDPPacket, n)
for i := range msgs {
packets[i] = packet.New(isV4)

View File

@@ -41,7 +41,7 @@ type TesterConn struct {
l *logrus.Logger
}
func (u *TesterConn) Prep(pkt *packet.Packet, addr netip.AddrPort) error {
func (u *TesterConn) Prep(pkt *packet.UDPPacket, addr netip.AddrPort) error {
pkt.ReadyToSend = true
return pkt.SetAddrPort(addr)
}
@@ -96,7 +96,7 @@ func (u *TesterConn) Get(block bool) *Packet {
// Below this is boilerplate implementation to make nebula actually work
//********************************************************************************************************************//
func (u *TesterConn) WriteBatch(pkts []*packet.Packet) (int, error) {
func (u *TesterConn) WriteBatch(pkts []*packet.UDPPacket) (int, error) {
for _, pkt := range pkts {
if !pkt.ReadyToSend {
continue
@@ -141,7 +141,7 @@ func (u *TesterConn) ListenOut(r EncReader) {
if err != nil {
panic(err)
}
y := []*packet.Packet{x}
y := []*packet.UDPPacket{x}
r(y)
}
}