mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-13 10:21:10 +01:00
Remove unnecessary endpoint map
This commit is contained in:
parent
2cffe6526a
commit
d0ad53b247
@ -22,8 +22,6 @@ type ICEBind struct {
|
||||
udpMux *UniversalUDPMuxDefault
|
||||
iceHostMux *UDPMuxDefault
|
||||
|
||||
endpointMap map[string]net.PacketConn
|
||||
|
||||
mu sync.Mutex // protects following fields
|
||||
}
|
||||
|
||||
@ -55,8 +53,6 @@ func (b *ICEBind) Open(uport uint16) ([]conn.ReceiveFunc, uint16, error) {
|
||||
return nil, 0, conn.ErrBindAlreadyOpen
|
||||
}
|
||||
|
||||
b.endpointMap = make(map[string]net.PacketConn)
|
||||
|
||||
port := int(uport)
|
||||
ipv4Conn, port, err := listenNet("udp4", port)
|
||||
if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) {
|
||||
@ -131,13 +127,6 @@ func (b *ICEBind) makeReceiveIPv4(c net.PacketConn) conn.ReceiveFunc {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
b.mu.Lock()
|
||||
if _, ok := b.endpointMap[e.String()]; !ok {
|
||||
b.endpointMap[e.String()] = c
|
||||
log.Infof("added endpoint %s", e.String())
|
||||
}
|
||||
b.mu.Unlock()
|
||||
|
||||
err = b.udpMux.HandleSTUNMessage(msg, endpoint)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
@ -186,21 +175,7 @@ func (b *ICEBind) Send(buff []byte, endpoint conn.Endpoint) error {
|
||||
if !ok {
|
||||
return conn.ErrWrongEndpointType
|
||||
}
|
||||
|
||||
b.mu.Lock()
|
||||
co := b.endpointMap[(*net.UDPAddr)(nend).String()]
|
||||
|
||||
if co == nil {
|
||||
// todo proper handling
|
||||
// todo without it relayed connections didn't work. investigate
|
||||
log.Warnf("conn not found for endpoint %s", (*net.UDPAddr)(nend).String())
|
||||
co = b.sharedConn
|
||||
b.endpointMap[(*net.UDPAddr)(nend).String()] = b.sharedConn
|
||||
//return conn.ErrWrongEndpointType
|
||||
}
|
||||
b.mu.Unlock()
|
||||
|
||||
_, err := co.WriteTo(buff, (*net.UDPAddr)(nend))
|
||||
_, err := b.sharedConn.WriteTo(buff, (*net.UDPAddr)(nend))
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user