mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
Fix Codacy
This commit is contained in:
@@ -118,9 +118,6 @@ type Engine struct {
|
|||||||
routeManager routemanager.Manager
|
routeManager routemanager.Manager
|
||||||
|
|
||||||
dnsServer dns.Server
|
dnsServer dns.Server
|
||||||
|
|
||||||
// userspaceBind indicates whether a
|
|
||||||
userspaceBind bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peer is an instance of the Connection Peer
|
// Peer is an instance of the Connection Peer
|
||||||
|
|||||||
@@ -214,6 +214,9 @@ func TestEngine_UpdateNetworkMap(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
engine.wgInterface, err = iface.NewWGIFace("utun102", "100.64.0.1/24", iface.DefaultMTU, nil, newNet)
|
engine.wgInterface, err = iface.NewWGIFace("utun102", "100.64.0.1/24", iface.DefaultMTU, nil, newNet)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
engine.routeManager = routemanager.NewManager(ctx, key.PublicKey().String(), engine.wgInterface, engine.statusRecorder)
|
engine.routeManager = routemanager.NewManager(ctx, key.PublicKey().String(), engine.wgInterface, engine.statusRecorder)
|
||||||
engine.dnsServer = &dns.MockServer{
|
engine.dnsServer = &dns.MockServer{
|
||||||
UpdateDNSServerFunc: func(serial uint64, update nbdns.Config) error { return nil },
|
UpdateDNSServerFunc: func(serial uint64, update nbdns.Config) error { return nil },
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ func NewDirectNoProxy(config Config, remoteWgPort int) *DirectNoProxy {
|
|||||||
return &DirectNoProxy{config: config, RemoteWgListenPort: remoteWgPort}
|
return &DirectNoProxy{config: config, RemoteWgListenPort: remoteWgPort}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close removes peer from the WireGuard interface
|
||||||
func (p *DirectNoProxy) Close() error {
|
func (p *DirectNoProxy) Close() error {
|
||||||
err := p.config.WgInterface.RemovePeer(p.config.RemoteKey)
|
err := p.config.WgInterface.RemovePeer(p.config.RemoteKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -50,6 +51,7 @@ func (p *DirectNoProxy) Start(remoteConn net.Conn) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type returns the type of this proxy
|
||||||
func (p *DirectNoProxy) Type() Type {
|
func (p *DirectNoProxy) Type() Type {
|
||||||
return TypeDirectNoProxy
|
return TypeDirectNoProxy
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (n *Net) filterInterfaces(interfaces []*transport.Interface) []*transport.I
|
|||||||
// The interfaces are discovered by an external iFaceDiscover function or by a default discoverer if the external one
|
// The interfaces are discovered by an external iFaceDiscover function or by a default discoverer if the external one
|
||||||
// wasn't specified.
|
// wasn't specified.
|
||||||
func (n *Net) UpdateInterfaces(iFaceDiscover IFaceDiscover) error {
|
func (n *Net) UpdateInterfaces(iFaceDiscover IFaceDiscover) error {
|
||||||
discoveredInterfaces := []*transport.Interface{}
|
discoveredInterfaces := []*transport.Interface{} //nolint
|
||||||
var err error
|
var err error
|
||||||
if iFaceDiscover != nil {
|
if iFaceDiscover != nil {
|
||||||
interfacesString := ""
|
interfacesString := ""
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ICEBind is the userspace implementation of WireGuard's conn.Bind interface using ice.UDPMux of the pion/ice library
|
||||||
type ICEBind struct {
|
type ICEBind struct {
|
||||||
// below fields, initialized on open
|
// below fields, initialized on open
|
||||||
sharedConn net.PacketConn
|
sharedConn net.PacketConn
|
||||||
@@ -33,6 +34,7 @@ func NewICEBind(transportNet transport.Net) *ICEBind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetICEMux returns the ICE UDPMux that was created and used by ICEBind
|
||||||
func (b *ICEBind) GetICEMux() (*UniversalUDPMuxDefault, error) {
|
func (b *ICEBind) GetICEMux() (*UniversalUDPMuxDefault, error) {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
defer b.mu.Unlock()
|
||||||
@@ -43,6 +45,7 @@ func (b *ICEBind) GetICEMux() (*UniversalUDPMuxDefault, error) {
|
|||||||
return b.udpMux, nil
|
return b.udpMux, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open creates a WireGuard socket and an instance of UDPMux that is used to glue up ICE and WireGuard for hole punching
|
||||||
func (b *ICEBind) Open(uport uint16) ([]conn.ReceiveFunc, uint16, error) {
|
func (b *ICEBind) Open(uport uint16) ([]conn.ReceiveFunc, uint16, error) {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
defer b.mu.Unlock()
|
||||||
@@ -134,6 +137,7 @@ func (b *ICEBind) makeReceiveIPv4(c net.PacketConn) conn.ReceiveFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the WireGuard socket and UDPMux
|
||||||
func (b *ICEBind) Close() error {
|
func (b *ICEBind) Close() error {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
defer b.mu.Unlock()
|
||||||
|
|||||||
@@ -359,6 +359,7 @@ func (m *UDPMuxDefault) createMuxedConn(key string) *udpMuxedConn {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleSTUNMessage handles STUN packets and forwards them to underlying pion/ice library
|
||||||
func (m *UDPMuxDefault) HandleSTUNMessage(msg *stun.Message, addr net.Addr) error {
|
func (m *UDPMuxDefault) HandleSTUNMessage(msg *stun.Message, addr net.Addr) error {
|
||||||
|
|
||||||
remoteAddr, ok := addr.(*net.UDPAddr)
|
remoteAddr, ok := addr.(*net.UDPAddr)
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ type udpConn struct {
|
|||||||
logger logging.LeveledLogger
|
logger logging.LeveledLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetListenAddresses returns the listen addr of this UDPMux
|
||||||
func (m *UniversalUDPMuxDefault) GetListenAddresses() []net.Addr {
|
func (m *UniversalUDPMuxDefault) GetListenAddresses() []net.Addr {
|
||||||
return []net.Addr{m.LocalAddr()}
|
return []net.Addr{m.LocalAddr()}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user