mirror of
https://github.com/soypat/lneto.git
synced 2026-08-28 10:29:05 +00:00
chore: bump minimum Go version to 1.24 (#85)
Signed-off-by: Marvin Drees <marvin.drees@9elements.com>
This commit is contained in:
@@ -31,7 +31,7 @@ const (
|
||||
// family must be syscall.AF_INET. SOCK_STREAM is only one supported for now since is TCP.
|
||||
// network supported for now is "tcp" or "tcp4". A nil remote address and defined local address means net.Listener is returned.
|
||||
// if remote address defined then is active connection, returns a net.Conn.
|
||||
type gosocket = func(ctx context.Context, network string, family, sotype int, laddr, raddr net.Addr) (c interface{}, err error)
|
||||
type gosocket = func(ctx context.Context, network string, family, sotype int, laddr, raddr net.Addr) (c any, err error)
|
||||
|
||||
type socket[T any] struct {
|
||||
sockfd int
|
||||
@@ -84,7 +84,7 @@ func (s *StackBerkeley) Bind(sockfd int, ip netip.AddrPort) error {
|
||||
}
|
||||
|
||||
// SetSockOpt sets a socket option on sockfd. Currently unimplemented.
|
||||
func (s *StackBerkeley) SetSockOpt(sockfd int, level int, opt int, value interface{}) error {
|
||||
func (s *StackBerkeley) SetSockOpt(sockfd int, level int, opt int, value any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ func (s StackBlocking) DoDHCPv4(reqAddr [4]byte, timeout time.Duration) (*DHCPRe
|
||||
deadline := time.Now().Add(timeout)
|
||||
requested := false
|
||||
var lastState dhcpv4.ClientState
|
||||
for i := 0; i < maxIter; i++ {
|
||||
for range maxIter {
|
||||
s.async.mu.Lock()
|
||||
state := s.async.dhcp.State()
|
||||
s.async.mu.Unlock()
|
||||
@@ -80,7 +80,7 @@ func (s StackBlocking) DoPing(hostAddr netip.Addr, timeout time.Duration) (round
|
||||
}
|
||||
start := time.Now()
|
||||
var backoffs uint
|
||||
for i := 0; i < maxIter; i++ {
|
||||
for range maxIter {
|
||||
s.async.mu.Lock()
|
||||
completed, exists := s.async.icmp.PingPop(key)
|
||||
s.async.mu.Unlock()
|
||||
@@ -108,7 +108,7 @@ func (s StackBlocking) DoNTP(hostAddr netip.Addr, timeout time.Duration) (offset
|
||||
deadline := time.Now().Add(timeout)
|
||||
var done bool
|
||||
var backoffs uint
|
||||
for i := 0; i < maxIter; i++ {
|
||||
for range maxIter {
|
||||
offset, done = s.async.ResultNTPOffset()
|
||||
if done {
|
||||
return offset, nil
|
||||
@@ -128,7 +128,7 @@ func (s StackBlocking) DoResolveHardwareAddress6(addr netip.Addr, timeout time.D
|
||||
}
|
||||
var backoffs uint
|
||||
deadline := time.Now().Add(timeout)
|
||||
for i := 0; i < maxIter; i++ {
|
||||
for range maxIter {
|
||||
hw, err = s.async.ResultResolveHardwareAddress6(addr)
|
||||
if err == nil {
|
||||
break
|
||||
@@ -152,7 +152,7 @@ func (s StackBlocking) DoLookupIP(host string, timeout time.Duration) (addrs []n
|
||||
|
||||
deadline := time.Now().Add(timeout)
|
||||
var backoffs uint
|
||||
for i := 0; i < maxIter; i++ {
|
||||
for range maxIter {
|
||||
addrs, completed, err := s.async.ResultLookupIP(host)
|
||||
if completed {
|
||||
return addrs, err
|
||||
@@ -174,7 +174,7 @@ func (s StackBlocking) DoDialTCP(conn *tcp.Conn, localPort uint16, addrp netip.A
|
||||
}
|
||||
deadline := time.Now().Add(timeout)
|
||||
var backoffs uint
|
||||
for i := 0; i < maxIter; i++ {
|
||||
for range maxIter {
|
||||
state := conn.State()
|
||||
if state == tcp.StateEstablished {
|
||||
return nil
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ type StackGo struct {
|
||||
plcfg TCPPoolConfig
|
||||
}
|
||||
|
||||
func (s StackGo) Socket(ctx context.Context, network string, family, sotype int, laddr, raddr net.Addr) (c interface{}, err error) {
|
||||
func (s StackGo) Socket(ctx context.Context, network string, family, sotype int, laddr, raddr net.Addr) (c any, err error) {
|
||||
switch family {
|
||||
case syscall.AF_INET:
|
||||
default:
|
||||
@@ -60,7 +60,7 @@ func (s StackGo) Socket(ctx context.Context, network string, family, sotype int,
|
||||
return s.SocketNetip(ctx, network, family, sotype, local, remote)
|
||||
}
|
||||
|
||||
func (s StackGo) SocketNetip(ctx context.Context, network string, family, sotype int, laddr, raddr netip.AddrPort) (c interface{}, err error) {
|
||||
func (s StackGo) SocketNetip(ctx context.Context, network string, family, sotype int, laddr, raddr netip.AddrPort) (c any, err error) {
|
||||
switch family {
|
||||
case syscall.AF_INET:
|
||||
default:
|
||||
|
||||
@@ -25,7 +25,7 @@ type StackRetrying struct {
|
||||
|
||||
func (s StackRetrying) DoDHCPv4(reqAddr [4]byte, timeout time.Duration, retries int) (results *DHCPResults, err error) {
|
||||
expectEnd := time.Now().Add(timeout * time.Duration(retries))
|
||||
for i := 0; i < retries; i++ {
|
||||
for i := range retries {
|
||||
if i > 0 {
|
||||
println("Retrying DHCP")
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (s StackRetrying) DoDHCPv4(reqAddr [4]byte, timeout time.Duration, retries
|
||||
|
||||
func (s StackRetrying) DoNTP(ntpHost netip.Addr, timeout time.Duration, retries int) (offset time.Duration, err error) {
|
||||
expectEnd := time.Now().Add(timeout * time.Duration(retries))
|
||||
for i := 0; i < retries; i++ {
|
||||
for i := range retries {
|
||||
if i > 0 {
|
||||
println("Retrying NTP")
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (s StackRetrying) DoLookupIP(host string, timeout time.Duration, retries in
|
||||
return nil, errNoDNSServer
|
||||
}
|
||||
expectEnd := time.Now().Add(timeout * time.Duration(retries))
|
||||
for i := 0; i < retries; i++ {
|
||||
for range retries {
|
||||
addrs, err = s.block.DoLookupIP(host, timeout)
|
||||
if err == nil {
|
||||
return addrs, nil
|
||||
@@ -75,7 +75,7 @@ func (s StackRetrying) DoLookupIP(host string, timeout time.Duration, retries in
|
||||
|
||||
func (s StackRetrying) DoResolveHardwareAddress6(addr netip.Addr, timeout time.Duration, retries int) (hw [6]byte, err error) {
|
||||
expectEnd := time.Now().Add(timeout * time.Duration(retries))
|
||||
for i := 0; i < retries; i++ {
|
||||
for range retries {
|
||||
hw, err = s.block.DoResolveHardwareAddress6(addr, timeout)
|
||||
if err == nil {
|
||||
return hw, nil
|
||||
@@ -90,7 +90,7 @@ func (s StackRetrying) DoResolveHardwareAddress6(addr netip.Addr, timeout time.D
|
||||
func (s StackRetrying) DoDialTCP(conn *tcp.Conn, localPort uint16, addrp netip.AddrPort, timeout time.Duration, retries int) (err error) {
|
||||
expectEnd := time.Now().Add(timeout * time.Duration(retries))
|
||||
var firstErr error
|
||||
for i := 0; i < retries; i++ {
|
||||
for range retries {
|
||||
err = s.block.DoDialTCP(conn, localPort, addrp, timeout)
|
||||
if err == nil {
|
||||
return nil
|
||||
|
||||
@@ -259,7 +259,7 @@ func runClient(t *testing.T, id int, stack *StackAsync, conn *tcp.Conn,
|
||||
}
|
||||
|
||||
// Send test data.
|
||||
testData := []byte(fmt.Sprintf("hello from client %d", id))
|
||||
testData := fmt.Appendf(nil, "hello from client %d", id)
|
||||
_, err = conn.Write(testData)
|
||||
if err != nil {
|
||||
t.Errorf("client %d write failed: %v", id, err)
|
||||
|
||||
@@ -3,6 +3,7 @@ package xnet
|
||||
import (
|
||||
"errors"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
@@ -87,13 +88,7 @@ func TestDNS_QueryReceivesAnswer(t *testing.T) {
|
||||
t.Fatal("no addresses returned from DNS lookup")
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, addr := range addrs {
|
||||
if addr == wantAddr {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found := slices.Contains(addrs, wantAddr)
|
||||
if !found {
|
||||
t.Errorf("expected address %s not found in result %v", wantAddr, addrs)
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ func testStackSeeded(t *testing.T, seed1, seed2 int64) {
|
||||
// Hard ceiling prevents infinite send loops from passing silently.
|
||||
// Also send drained packet to other stack to also catch infinite feedback loops.
|
||||
const drainLimit = 8
|
||||
for d := 0; d < drainLimit; d++ {
|
||||
for d := range drainLimit {
|
||||
limit := d == drainLimit-1
|
||||
n, err := first.EgressEthernet(buf[:])
|
||||
if (err != nil || n > 0) && limit {
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ func TestStackAsyncTCP_multipacket(t *testing.T) {
|
||||
tst.TestTCPSetupAndEstablish(sv, client, svconn, clconn, svPort, 1337)
|
||||
testClose()
|
||||
var buf [MTU]byte
|
||||
for i := 0; i < 20; i++ {
|
||||
for range 20 {
|
||||
payloadSize := rng.Intn(maxPktLen) + 1
|
||||
tst.TestTCPSetupAndEstablish(sv, client, svconn, clconn, svPort, 1337)
|
||||
// npkt := rng.Intn(maxNPkt-1) + 2
|
||||
|
||||
Reference in New Issue
Block a user