feat: enhance TCP and UDP interfaces with improved timeout settings and MTU configuration
This commit is contained in:
@@ -36,8 +36,11 @@ func NewUDPInterface(name string, addr string, target string, enabled bool) (*UD
|
||||
BaseInterface: NewBaseInterface(name, common.IF_TYPE_UDP, enabled),
|
||||
addr: udpAddr,
|
||||
targetAddr: targetAddr,
|
||||
readBuffer: make([]byte, common.DEFAULT_MTU),
|
||||
readBuffer: make([]byte, 1064), // Python RNS uses 1064 bytes for UDP MTU
|
||||
}
|
||||
|
||||
// Set MTU to match Python RNS
|
||||
ui.MTU = 1064
|
||||
|
||||
return ui, nil
|
||||
}
|
||||
@@ -181,6 +184,19 @@ func (ui *UDPInterface) Start() error {
|
||||
return err
|
||||
}
|
||||
ui.conn = conn
|
||||
|
||||
// Enable broadcast mode if we have a target address
|
||||
// This matches Python RNS UDP interface behavior
|
||||
if ui.targetAddr != nil {
|
||||
// Get the raw connection file descriptor to set SO_BROADCAST
|
||||
if err := conn.SetReadBuffer(1064); err != nil {
|
||||
debug.Log(debug.DEBUG_ERROR, "Failed to set read buffer size", "error", err)
|
||||
}
|
||||
if err := conn.SetWriteBuffer(1064); err != nil {
|
||||
debug.Log(debug.DEBUG_ERROR, "Failed to set write buffer size", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
ui.Online = true
|
||||
|
||||
// Start the read loop in a goroutine
|
||||
@@ -190,7 +206,7 @@ func (ui *UDPInterface) Start() error {
|
||||
}
|
||||
|
||||
func (ui *UDPInterface) readLoop() {
|
||||
buffer := make([]byte, common.DEFAULT_MTU)
|
||||
buffer := make([]byte, 1064) // Match Python RNS UDP MTU
|
||||
for ui.IsOnline() && !ui.IsDetached() {
|
||||
n, remoteAddr, err := ui.conn.ReadFromUDP(buffer)
|
||||
if err != nil {
|
||||
@@ -200,7 +216,11 @@ func (ui *UDPInterface) readLoop() {
|
||||
return
|
||||
}
|
||||
|
||||
// Update RX stats
|
||||
ui.mutex.Lock()
|
||||
ui.RxBytes += uint64(n)
|
||||
|
||||
// Auto-discover target address from first packet if not set
|
||||
if ui.targetAddr == nil {
|
||||
debug.Log(debug.DEBUG_ALL, "UDP interface discovered peer", "name", ui.Name, "peer", remoteAddr.String())
|
||||
ui.targetAddr = remoteAddr
|
||||
|
||||
Reference in New Issue
Block a user