mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
[relay] Replace net.Conn with context-aware Conn interface (#5770)
* [relay] Replace net.Conn with context-aware Conn interface for relay transports Introduce a listener.Conn interface with context-based Read/Write methods, replacing net.Conn throughout the relay server. This enables proper timeout propagation (e.g. handshake timeout) without goroutine-based workarounds and removes unused LocalAddr/SetDeadline methods from WS and QUIC conns. * [relay] Refactor Peer context management to ensure proper cleanup Integrate context creation (`context.WithCancel`) directly in `NewPeer` and remove redundant initialization in `Work`. Add `ctxCancel` calls to ensure context is properly canceled during `Close` operations.
This commit is contained in:
@@ -3,7 +3,6 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
@@ -31,7 +30,7 @@ type ListenerConfig struct {
|
||||
// In a new HTTP connection, the server will accept the connection and pass it to the Relay server via the Accept method.
|
||||
type Server struct {
|
||||
relay *Relay
|
||||
listeners []listener.Listener
|
||||
listeners []Listener
|
||||
listenerMux sync.Mutex
|
||||
}
|
||||
|
||||
@@ -56,7 +55,7 @@ func NewServer(config Config) (*Server, error) {
|
||||
}
|
||||
return &Server{
|
||||
relay: relay,
|
||||
listeners: make([]listener.Listener, 0, 2),
|
||||
listeners: make([]Listener, 0, 2),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ func (r *Server) Listen(cfg ListenerConfig) error {
|
||||
wg := sync.WaitGroup{}
|
||||
for _, l := range r.listeners {
|
||||
wg.Add(1)
|
||||
go func(listener listener.Listener) {
|
||||
go func(listener Listener) {
|
||||
defer wg.Done()
|
||||
errChan <- listener.Listen(r.relay.Accept)
|
||||
}(l)
|
||||
@@ -139,6 +138,6 @@ func (r *Server) InstanceURL() url.URL {
|
||||
// RelayAccept returns the relay's Accept function for handling incoming connections.
|
||||
// This allows external HTTP handlers to route connections to the relay without
|
||||
// starting the relay's own listeners.
|
||||
func (r *Server) RelayAccept() func(conn net.Conn) {
|
||||
func (r *Server) RelayAccept() func(conn listener.Conn) {
|
||||
return r.relay.Accept
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user