mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Refactor variable names {r,s}addr to {r,s}Addr
As most variables are using camelCase.
This commit is contained in:
@@ -340,32 +340,32 @@ func (a *Agent) gatherCandidatesSrflxMapped(ctx context.Context, networkTypes []
|
||||
return
|
||||
}
|
||||
|
||||
laddr, ok := conn.LocalAddr().(*net.UDPAddr)
|
||||
lAddr, ok := conn.LocalAddr().(*net.UDPAddr)
|
||||
if !ok {
|
||||
closeConnAndLog(conn, a.log, "1:1 NAT mapping is enabled but LocalAddr is not a UDPAddr")
|
||||
return
|
||||
}
|
||||
|
||||
mappedIP, err := a.extIPMapper.findExternalIP(laddr.IP.String())
|
||||
mappedIP, err := a.extIPMapper.findExternalIP(lAddr.IP.String())
|
||||
if err != nil {
|
||||
closeConnAndLog(conn, a.log, fmt.Sprintf("1:1 NAT mapping is enabled but no external IP is found for %s", laddr.IP.String()))
|
||||
closeConnAndLog(conn, a.log, fmt.Sprintf("1:1 NAT mapping is enabled but no external IP is found for %s", lAddr.IP.String()))
|
||||
return
|
||||
}
|
||||
|
||||
srflxConfig := CandidateServerReflexiveConfig{
|
||||
Network: network,
|
||||
Address: mappedIP.String(),
|
||||
Port: laddr.Port,
|
||||
Port: lAddr.Port,
|
||||
Component: ComponentRTP,
|
||||
RelAddr: laddr.IP.String(),
|
||||
RelPort: laddr.Port,
|
||||
RelAddr: lAddr.IP.String(),
|
||||
RelPort: lAddr.Port,
|
||||
}
|
||||
c, err := NewCandidateServerReflexive(&srflxConfig)
|
||||
if err != nil {
|
||||
closeConnAndLog(conn, a.log, fmt.Sprintf("Failed to create server reflexive candidate: %s %s %d: %v",
|
||||
network,
|
||||
mappedIP.String(),
|
||||
laddr.Port,
|
||||
lAddr.Port,
|
||||
err))
|
||||
return
|
||||
}
|
||||
@@ -407,7 +407,7 @@ func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, ne
|
||||
return
|
||||
}
|
||||
|
||||
xoraddr, err := a.udpMuxSrflx.GetXORMappedAddr(serverAddr, stunGatherTimeout)
|
||||
xorAddr, err := a.udpMuxSrflx.GetXORMappedAddr(serverAddr, stunGatherTimeout)
|
||||
if err != nil {
|
||||
a.log.Warnf("could not get server reflexive address %s %s: %v", network, url, err)
|
||||
return
|
||||
@@ -419,8 +419,8 @@ func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, ne
|
||||
return
|
||||
}
|
||||
|
||||
ip := xoraddr.IP
|
||||
port := xoraddr.Port
|
||||
ip := xorAddr.IP
|
||||
port := xorAddr.Port
|
||||
|
||||
srflxConfig := CandidateServerReflexiveConfig{
|
||||
Network: network,
|
||||
@@ -487,23 +487,23 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT
|
||||
}
|
||||
}()
|
||||
|
||||
xoraddr, err := getXORMappedAddr(conn, serverAddr, stunGatherTimeout)
|
||||
xorAddr, err := getXORMappedAddr(conn, serverAddr, stunGatherTimeout)
|
||||
if err != nil {
|
||||
closeConnAndLog(conn, a.log, fmt.Sprintf("could not get server reflexive address %s %s: %v", network, url, err))
|
||||
return
|
||||
}
|
||||
|
||||
ip := xoraddr.IP
|
||||
port := xoraddr.Port
|
||||
ip := xorAddr.IP
|
||||
port := xorAddr.Port
|
||||
|
||||
laddr := conn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||
lAddr := conn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||
srflxConfig := CandidateServerReflexiveConfig{
|
||||
Network: network,
|
||||
Address: ip.String(),
|
||||
Port: port,
|
||||
Component: ComponentRTP,
|
||||
RelAddr: laddr.IP.String(),
|
||||
RelPort: laddr.Port,
|
||||
RelAddr: lAddr.IP.String(),
|
||||
RelPort: lAddr.Port,
|
||||
}
|
||||
c, err := NewCandidateServerReflexive(&srflxConfig)
|
||||
if err != nil {
|
||||
@@ -658,12 +658,12 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
return
|
||||
}
|
||||
|
||||
raddr := relayConn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||
rAddr := relayConn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||
relayConfig := CandidateRelayConfig{
|
||||
Network: network,
|
||||
Component: ComponentRTP,
|
||||
Address: raddr.IP.String(),
|
||||
Port: raddr.Port,
|
||||
Address: rAddr.IP.String(),
|
||||
Port: rAddr.Port,
|
||||
RelAddr: RelAddr,
|
||||
RelPort: RelPort,
|
||||
RelayProtocol: relayProtocol,
|
||||
@@ -682,7 +682,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
relayConnClose()
|
||||
|
||||
client.Close()
|
||||
closeConnAndLog(locConn, a.log, fmt.Sprintf("Failed to create relay candidate: %s %s: %v", network, raddr.String(), err))
|
||||
closeConnAndLog(locConn, a.log, fmt.Sprintf("Failed to create relay candidate: %s %s: %v", network, rAddr.String(), err))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -232,10 +232,10 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
t.Fatal("There must be two candidates")
|
||||
}
|
||||
|
||||
laddr := [2]*net.UDPAddr{nil, nil}
|
||||
lAddr := [2]*net.UDPAddr{nil, nil}
|
||||
for i, candi := range candidates {
|
||||
laddr[i] = candi.(*CandidateHost).conn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||
if candi.Port() != laddr[i].Port {
|
||||
lAddr[i] = candi.(*CandidateHost).conn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||
if candi.Port() != lAddr[i].Port {
|
||||
t.Fatalf("Unexpected candidate port: %d", candi.Port())
|
||||
}
|
||||
}
|
||||
@@ -244,21 +244,21 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
if candidates[1].Address() != externalIP1 {
|
||||
t.Fatalf("Unexpected candidate IP: %s", candidates[1].Address())
|
||||
}
|
||||
if laddr[0].IP.String() != localIP0 {
|
||||
t.Fatalf("Unexpected listen IP: %s", laddr[0].IP.String())
|
||||
if lAddr[0].IP.String() != localIP0 {
|
||||
t.Fatalf("Unexpected listen IP: %s", lAddr[0].IP.String())
|
||||
}
|
||||
if laddr[1].IP.String() != localIP1 {
|
||||
t.Fatalf("Unexpected listen IP: %s", laddr[1].IP.String())
|
||||
if lAddr[1].IP.String() != localIP1 {
|
||||
t.Fatalf("Unexpected listen IP: %s", lAddr[1].IP.String())
|
||||
}
|
||||
} else if candidates[0].Address() == externalIP1 {
|
||||
if candidates[1].Address() != externalIP0 {
|
||||
t.Fatalf("Unexpected candidate IP: %s", candidates[1].Address())
|
||||
}
|
||||
if laddr[0].IP.String() != localIP1 {
|
||||
t.Fatalf("Unexpected listen IP: %s", laddr[0].IP.String())
|
||||
if lAddr[0].IP.String() != localIP1 {
|
||||
t.Fatalf("Unexpected listen IP: %s", lAddr[0].IP.String())
|
||||
}
|
||||
if laddr[1].IP.String() != localIP0 {
|
||||
t.Fatalf("Unexpected listen IP: %s", laddr[1].IP.String())
|
||||
if lAddr[1].IP.String() != localIP0 {
|
||||
t.Fatalf("Unexpected listen IP: %s", lAddr[1].IP.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -72,9 +72,9 @@ func TestMultiTCPMux_Recv(t *testing.T) {
|
||||
require.NoError(t, err, "error writing tcp stun packet")
|
||||
|
||||
recv := make([]byte, n)
|
||||
n2, raddr, err := pktConn.ReadFrom(recv)
|
||||
n2, rAddr, err := pktConn.ReadFrom(recv)
|
||||
require.NoError(t, err, "error receiving data")
|
||||
assert.Equal(t, conn.LocalAddr(), raddr, "remote tcp address mismatch")
|
||||
assert.Equal(t, conn.LocalAddr(), rAddr, "remote tcp address mismatch")
|
||||
assert.Equal(t, n, n2, "received byte size mismatch")
|
||||
assert.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
|
||||
|
||||
+2
-2
@@ -69,9 +69,9 @@ func TestTCPMux_Recv(t *testing.T) {
|
||||
}()
|
||||
|
||||
recv := make([]byte, n)
|
||||
n2, raddr, err := pktConn.ReadFrom(recv)
|
||||
n2, rAddr, err := pktConn.ReadFrom(recv)
|
||||
require.NoError(t, err, "error receiving data")
|
||||
assert.Equal(t, conn.LocalAddr(), raddr, "remote tcp address mismatch")
|
||||
assert.Equal(t, conn.LocalAddr(), rAddr, "remote tcp address mismatch")
|
||||
assert.Equal(t, n, n2, "received byte size mismatch")
|
||||
assert.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
|
||||
|
||||
+6
-6
@@ -198,7 +198,7 @@ func (t *tcpPacketConn) isClosed() bool {
|
||||
}
|
||||
|
||||
// WriteTo is for passive and s-o candidates.
|
||||
func (t *tcpPacketConn) ReadFrom(b []byte) (n int, raddr net.Addr, err error) {
|
||||
func (t *tcpPacketConn) ReadFrom(b []byte) (n int, rAddr net.Addr, err error) {
|
||||
pkt, ok := <-t.recvChan
|
||||
|
||||
if !ok {
|
||||
@@ -219,14 +219,14 @@ func (t *tcpPacketConn) ReadFrom(b []byte) (n int, raddr net.Addr, err error) {
|
||||
}
|
||||
|
||||
// WriteTo is for active and s-o candidates.
|
||||
func (t *tcpPacketConn) WriteTo(buf []byte, raddr net.Addr) (n int, err error) {
|
||||
func (t *tcpPacketConn) WriteTo(buf []byte, rAddr net.Addr) (n int, err error) {
|
||||
t.mu.Lock()
|
||||
conn, ok := t.conns[raddr.String()]
|
||||
conn, ok := t.conns[rAddr.String()]
|
||||
t.mu.Unlock()
|
||||
|
||||
if !ok {
|
||||
return 0, io.ErrClosedPipe
|
||||
// conn, err := net.DialTCP(tcp, nil, raddr.(*net.TCPAddr))
|
||||
// conn, err := net.DialTCP(tcp, nil, rAddr.(*net.TCPAddr))
|
||||
|
||||
// if err != nil {
|
||||
// t.params.Logger.Tracef("DialTCP error: %s", err)
|
||||
@@ -234,12 +234,12 @@ func (t *tcpPacketConn) WriteTo(buf []byte, raddr net.Addr) (n int, err error) {
|
||||
// }
|
||||
|
||||
// go t.startReading(conn)
|
||||
// t.conns[raddr.String()] = conn
|
||||
// t.conns[rAddr.String()] = conn
|
||||
}
|
||||
|
||||
n, err = writeStreamingPacket(conn, buf)
|
||||
if err != nil {
|
||||
t.params.Logger.Tracef("%w %s", errWriting, raddr)
|
||||
t.params.Logger.Tracef("%w %s", errWriting, rAddr)
|
||||
return n, err
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -227,8 +227,8 @@ func (m *UDPMuxDefault) Close() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *UDPMuxDefault) writeTo(buf []byte, raddr net.Addr) (n int, err error) {
|
||||
return m.params.UDPConn.WriteTo(buf, raddr)
|
||||
func (m *UDPMuxDefault) writeTo(buf []byte, rAddr net.Addr) (n int, err error) {
|
||||
return m.params.UDPConn.WriteTo(buf, rAddr)
|
||||
}
|
||||
|
||||
func (m *UDPMuxDefault) registerConnForAddress(conn *udpMuxedConn, addr string) {
|
||||
|
||||
+6
-6
@@ -42,7 +42,7 @@ func newUDPMuxedConn(params *udpMuxedConnParams) *udpMuxedConn {
|
||||
return p
|
||||
}
|
||||
|
||||
func (c *udpMuxedConn) ReadFrom(b []byte) (n int, raddr net.Addr, err error) {
|
||||
func (c *udpMuxedConn) ReadFrom(b []byte) (n int, rAddr net.Addr, err error) {
|
||||
buf := c.params.AddrPool.Get().(*bufferHolder) //nolint:forcetypeassert
|
||||
defer c.params.AddrPool.Put(buf)
|
||||
|
||||
@@ -66,24 +66,24 @@ func (c *udpMuxedConn) ReadFrom(b []byte) (n int, raddr net.Addr, err error) {
|
||||
addrLen := int(binary.LittleEndian.Uint16(buf.buffer[offset : offset+2]))
|
||||
offset += 2
|
||||
|
||||
if raddr, err = decodeUDPAddr(buf.buffer[offset : offset+addrLen]); err != nil {
|
||||
if rAddr, err = decodeUDPAddr(buf.buffer[offset : offset+addrLen]); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
return dataLen, raddr, nil
|
||||
return dataLen, rAddr, nil
|
||||
}
|
||||
|
||||
func (c *udpMuxedConn) WriteTo(buf []byte, raddr net.Addr) (n int, err error) {
|
||||
func (c *udpMuxedConn) WriteTo(buf []byte, rAddr net.Addr) (n int, err error) {
|
||||
if c.isClosed() {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
// each time we write to a new address, we'll register it with the mux
|
||||
addr := raddr.String()
|
||||
addr := rAddr.String()
|
||||
if !c.containsAddress(addr) {
|
||||
c.addAddress(addr)
|
||||
}
|
||||
|
||||
return c.params.Mux.writeTo(buf, raddr)
|
||||
return c.params.Mux.writeTo(buf, rAddr)
|
||||
}
|
||||
|
||||
func (c *udpMuxedConn) LocalAddr() net.Addr {
|
||||
|
||||
@@ -199,9 +199,9 @@ func localInterfaces(vnet *vnet.Net, interfaceFilter func(string) bool, ipFilter
|
||||
return ips, nil
|
||||
}
|
||||
|
||||
func listenUDPInPortRange(vnet *vnet.Net, log logging.LeveledLogger, portMax, portMin int, network string, laddr *net.UDPAddr) (vnet.UDPPacketConn, error) {
|
||||
if (laddr.Port != 0) || ((portMin == 0) && (portMax == 0)) {
|
||||
return vnet.ListenUDP(network, laddr)
|
||||
func listenUDPInPortRange(vnet *vnet.Net, log logging.LeveledLogger, portMax, portMin int, network string, lAddr *net.UDPAddr) (vnet.UDPPacketConn, error) {
|
||||
if (lAddr.Port != 0) || ((portMin == 0) && (portMax == 0)) {
|
||||
return vnet.ListenUDP(network, lAddr)
|
||||
}
|
||||
var i, j int
|
||||
i = portMin
|
||||
@@ -219,12 +219,12 @@ func listenUDPInPortRange(vnet *vnet.Net, log logging.LeveledLogger, portMax, po
|
||||
portStart := globalMathRandomGenerator.Intn(j-i+1) + i
|
||||
portCurrent := portStart
|
||||
for {
|
||||
laddr = &net.UDPAddr{IP: laddr.IP, Port: portCurrent}
|
||||
c, e := vnet.ListenUDP(network, laddr)
|
||||
lAddr = &net.UDPAddr{IP: lAddr.IP, Port: portCurrent}
|
||||
c, e := vnet.ListenUDP(network, lAddr)
|
||||
if e == nil {
|
||||
return c, e //nolint:nilerr
|
||||
}
|
||||
log.Debugf("failed to listen %s: %v", laddr.String(), e)
|
||||
log.Debugf("failed to listen %s: %v", lAddr.String(), e)
|
||||
portCurrent++
|
||||
if portCurrent > j {
|
||||
portCurrent = i
|
||||
|
||||
Reference in New Issue
Block a user