Repository: pion/ice
Pull request #490 (2022-11-12 14:08:37)

Cleanups
I've spent some time auditing the code base for gaining a better understanding.

Here are a few cleanups and refactorings.

The PR includes no functional changes.

codecov[bot]: # [Codecov](https://codecov.io/gh/pion/ice/pull/490?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) Report
Base: **77.86**% // Head: **24.58**% // Decreases project coverage by **`-53.27%`** :warning:
> Coverage data is based on head [(`f11c185`)](https://codecov.io/gh/pion/ice/pull/490?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) compared to base [(`7f2d498`)](https://codecov.io/gh/pion/ice/commit/7f2d498367cbb827d76b9ba5443d11c9dfe4febd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).
> Patch coverage: 3.89% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##           master     #490       +/-   ##
===========================================
- Coverage   77.86%   24.58%   -53.28%     
===========================================
  Files          36       36               
  Lines        4237     4238        +1     
===========================================
- Hits         3299     1042     -2257     
- Misses        729     3156     +2427     
+ Partials      209       40      -169     
```

| Flag | Coverage Δ | |
|---|---|---|
| go | `?` | |
| wasm | `24.58% <3.89%> (-0.01%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/pion/ice/pull/490?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | Coverage Δ | |
|---|---|---|
| [agent.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-YWdlbnQuZ28=) | `0.00% <0.00%> (-82.40%)` | :arrow_down: |
| [agent\_config.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-YWdlbnRfY29uZmlnLmdv) | `0.00% <ø> (-82.15%)` | :arrow_down: |
| [candidate\_base.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-Y2FuZGlkYXRlX2Jhc2UuZ28=) | `60.48% <0.00%> (-25.49%)` | :arrow_down: |
| [gather.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-Z2F0aGVyLmdv) | `0.00% <0.00%> (-65.99%)` | :arrow_down: |
| [ice.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-aWNlLmdv) | `100.00% <ø> (ø)` | |
| [tcp\_mux\_multi.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-dGNwX211eF9tdWx0aS5nbw==) | `0.00% <0.00%> (-63.16%)` | :arrow_down: |
| [tcptype.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-dGNwdHlwZS5nbw==) | `100.00% <ø> (ø)` | |
| [udp\_mux.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-dWRwX211eC5nbw==) | `0.00% <0.00%> (-82.28%)` | :arrow_down: |
| [udp\_mux\_multi.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-dWRwX211eF9tdWx0aS5nbw==) | `0.00% <0.00%> (-52.48%)` | :arrow_down: |
| [udp\_muxed\_conn.go](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-dWRwX211eGVkX2Nvbm4uZ28=) | `0.00% <0.00%> (-71.96%)` | :arrow_down: |
| ... and [26 more](https://codecov.io/gh/pion/ice/pull/490/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/pion/ice/pull/490?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).

stv0g: @cnderrauber Do you mind reviewing this PR?
Sean-Der: Really great changes @stv0g. Really inspired by your work on this. Working on older code bases is hard, and you are making it look easy. Great to see the refactoring/typo clean ups.

 In a few cases the changes seem subjective (you have a naming scheme you prefer vs others). Unless we create tooling that makes the new way official I would caution against changes like that.

In the future someone will just come and make the changes back to the way it was before.
Sean-Der: This is my reasoning around some changes. I don't feel strongly around any of these, but I think worth discussing

```
* raddr -> rAddr - Makes it more readable with casing. Like that change!
* srcAddr -> sAddr - I think it makes the code harder to understand. `src` is more self explanatory then `s`
* buffer -> buff, muxs -> muxes - Neutral change. The churn on the code does make it harder to bisect in the future though.

```
stv0g: Hi @Sean-Der,

thanks a lot for your quick feedback :) I really appreciate it. I know its a lot of noise for a maintainer of such a big project.

Let me explain my reasoning for some of the changed variable names. Similarly to you, I don't feel strongly about any of those.

However, something I value is consistency which was also one of the main motivation for these changes.
And it triggers my OCD (which is probably a good thing for open-source projects.. So I am happy to tidy up the code-base :D)

> * srcAddr -> sAddr - I think it makes the code harder to understand. `src` is more self explanatory then `s`

Agreed. I will change it to `srcAddr`.

> * raddr -> rAddr - Makes it more readable with casing. Like that change!

To satisfy my demand for consistency, I thought about naming it `remAddr`. However, I disliked it and went for the shorter `rAddr`. Hence, for consistency reasons also for `sAddr`. Yeah, sorry I know its nitpicking. But I am also happy with `srcAddr` / `rAddr`..

> In a few cases the changes seem subjective (you have a naming scheme you prefer vs others).
> Unless we create tooling that makes the new way official I would caution against changes like that.

Yes that is a good point. In my case the tooling is a spell checker extension for VSCode which complains about capitalizations like `portmin` but succeeds to check camel case wording like `portMin`.
We could probably add a spell checker into the CI pipeline, however I think it would produce a lot of false positives and demotivate contributors which are annoyed by failing CI checks.

(E.g. The commit message linter is another example of such an annoyance in my opinion.. Maybe it just takes a bit to get used to it.. But I see almost all first-time contributors stumble over it..)

And another good tool for refactoring code like this is the Go VSCode extension as it makes it really easy to perform project wide refactorings and helps a lot with which code navigation.
stv0g: @Sean-Der I think I addressed all your comments.

Let me know, if you want me to change something else 😃 
Sean-Der: I think this is great, thanks @stv0g !

 Keep these changes coming :) I like the nitpicking, no one wants nits!

Patch:
diff --git a/agent.go b/agent.go
index 2ed2879..5881021 100644
--- a/agent.go
+++ b/agent.go
@@ -64,8 +64,8 @@ type Agent struct {
 	prflxAcceptanceMinWait time.Duration
 	relayAcceptanceMinWait time.Duration
 
-	portmin uint16
-	portmax uint16
+	portMin uint16
+	portMax uint16
 
 	candidateTypes []CandidateType
 
@@ -100,7 +100,7 @@ type Agent struct {
 	urls         []*URL
 	networkTypes []NetworkType
 
-	buffer *packetio.Buffer
+	buf *packetio.Buffer
 
 	// LRU of outbound Binding request Transaction IDs
 	pendingBindingRequests []bindingRequest
@@ -205,7 +205,7 @@ func (a *Agent) taskLoop() {
 		a.deleteAllCandidates()
 		a.startedFn()
 
-		if err := a.buffer.Close(); err != nil {
+		if err := a.buf.Close(); err != nil {
 			a.log.Warnf("failed to close buffer: %v", err)
 		}
 
@@ -292,13 +292,13 @@ func NewAgent(config *AgentConfig) (*Agent, error) { //nolint:gocognit
 		urls:              config.Urls,
 		networkTypes:      config.NetworkTypes,
 		onConnected:       make(chan struct{}),
-		buffer:            packetio.NewBuffer(),
+		buf:               packetio.NewBuffer(),
 		done:              make(chan struct{}),
 		taskLoopDone:      make(chan struct{}),
 		startedCh:         startedCtx.Done(),
 		startedFn:         startedFn,
-		portmin:           config.PortMin,
-		portmax:           config.PortMax,
+		portMin:           config.PortMin,
+		portMax:           config.PortMax,
 		loggerFactory:     loggerFactory,
 		log:               log,
 		net:               config.Net,
@@ -340,7 +340,7 @@ func NewAgent(config *AgentConfig) (*Agent, error) { //nolint:gocognit
 	// Make sure the buffer doesn't grow indefinitely.
 	// NOTE: We actually won't get anywhere close to this limit.
 	// SRTP will constantly read from the endpoint and drop packets if it's full.
-	a.buffer.SetLimitSize(maxBufferSize)
+	a.buf.SetLimitSize(maxBufferSize)
 
 	if a.lite && (len(a.candidateTypes) != 1 || a.candidateTypes[0] != CandidateTypeHost) {
 		closeMDNSConn()
@@ -722,9 +722,9 @@ func (a *Agent) AddRemoteCandidate(c Candidate) error {
 	}
 
 	// cannot check for network yet because it might not be applied
-	// when mDNS hostame is used.
+	// when mDNS hostname is used.
 	if c.TCPType() == TCPTypeActive {
-		// TCP Candidates with tcptype active will probe server passive ones, so
+		// TCP Candidates with TCP type active will probe server passive ones, so
 		// no need to do anything with them.
 		a.log.Infof("Ignoring remote candidate with tcpType active: %s", c)
 		return nil
@@ -1000,12 +1000,11 @@ func (a *Agent) sendBindingSuccess(m *stun.Message, local, remote Candidate) {
 	}
 }
 
-/* Removes pending binding requests that are over maxBindingRequestTimeout old
-
-   Let HTO be the transaction timeout, which SHOULD be 2*RTT if
-   RTT is known or 500 ms otherwise.
-   https://tools.ietf.org/html/rfc8445#appendix-B.1
-*/
+// Removes pending binding requests that are over maxBindingRequestTimeout old
+//
+// Let HTO be the transaction timeout, which SHOULD be 2*RTT if
+// RTT is known or 500 ms otherwise.
+// https://tools.ietf.org/html/rfc8445#appendix-B.1
 func (a *Agent) invalidatePendingBindingRequests(filterTime time.Time) {
 	initialSize := len(a.pendingBindingRequests)
 
diff --git a/agent_config.go b/agent_config.go
index 7e5cedd..98bbbff 100644
--- a/agent_config.go
+++ b/agent_config.go
@@ -109,14 +109,14 @@ type AgentConfig struct {
 	// NAT1To1IPCandidateType is used along with NAT1To1IPs to specify which candidate type
 	// the 1:1 NAT IP addresses should be mapped to.
 	// If unspecified or CandidateTypeHost, NAT1To1IPs are used to replace host candidate IPs.
-	// If CandidateTypeServerReflexive, it will insert a srflx candidate (as if it was dervied
+	// If CandidateTypeServerReflexive, it will insert a srflx candidate (as if it was derived
 	// from a STUN server) with its port number being the one for the actual host candidate.
 	// Other values will result in an error.
 	NAT1To1IPCandidateType CandidateType
 
 	// NAT1To1IPs contains a list of public IP addresses that are to be used as a host
 	// candidate or srflx candidate. This is used typically for servers that are behind
-	// 1:1 D-NAT (e.g. AWS EC2 instances) and to eliminate the need of server reflexisive
+	// 1:1 D-NAT (e.g. AWS EC2 instances) and to eliminate the need of server reflexive
 	// candidate gathering.
 	NAT1To1IPs []string
 
diff --git a/candidate_base.go b/candidate_base.go
index 94e330e..286e836 100644
--- a/candidate_base.go
+++ b/candidate_base.go
@@ -10,7 +10,6 @@ import (
 	"sync/atomic"
 	"time"
 
-	"github.com/pion/logging"
 	"github.com/pion/stun"
 )
 
@@ -206,9 +205,9 @@ func (c *candidateBase) start(a *Agent, conn net.PacketConn, initializedCh <-cha
 }
 
 func (c *candidateBase) recvLoop(initializedCh <-chan struct{}) {
-	defer func() {
-		close(c.closedCh)
-	}()
+	a := c.agent()
+
+	defer close(c.closedCh)
 
 	select {
 	case <-initializedCh:
@@ -216,47 +215,52 @@ func (c *candidateBase) recvLoop(initializedCh <-chan struct{}) {
 		return
 	}
 
-	log := c.agent().log
-	buffer := make([]byte, receiveMTU)
+	buf := make([]byte, receiveMTU)
 	for {
-		n, srcAddr, err := c.conn.ReadFrom(buffer)
+		n, srcAddr, err := c.conn.ReadFrom(buf)
 		if err != nil {
+			a.log.Warnf("Failed to read from candidate %s: %v", c, err)
 			return
 		}
 
-		handleInboundCandidateMsg(c, c, buffer[:n], srcAddr, log)
+		c.handleInboundPacket(buf[:n], srcAddr)
 	}
 }
 
-func handleInboundCandidateMsg(ctx context.Context, c Candidate, buffer []byte, srcAddr net.Addr, log logging.LeveledLogger) {
-	if stun.IsMessage(buffer) {
+func (c *candidateBase) handleInboundPacket(buf []byte, srcAddr net.Addr) {
+	a := c.agent()
+
+	if stun.IsMessage(buf) {
 		m := &stun.Message{
-			Raw: make([]byte, len(buffer)),
+			Raw: make([]byte, len(buf)),
 		}
+
 		// Explicitly copy raw buffer so Message can own the memory.
-		copy(m.Raw, buffer)
+		copy(m.Raw, buf)
+
 		if err := m.Decode(); err != nil {
-			log.Warnf("Failed to handle decode ICE from %s to %s: %v", c.addr(), srcAddr, err)
+			a.log.Warnf("Failed to handle decode ICE from %s to %s: %v", c.addr(), srcAddr, err)
 			return
 		}
-		err := c.agent().run(ctx, func(ctx context.Context, agent *Agent) {
-			agent.handleInbound(m, c, srcAddr)
-		})
-		if err != nil {
-			log.Warnf("Failed to handle message: %v", err)
+
+		if err := a.run(c, func(ctx context.Context, a *Agent) {
+			a.handleInbound(m, c, srcAddr)
+		}); err != nil {
+			a.log.Warnf("Failed to handle message: %v", err)
 		}
 
 		return
 	}
 
-	if !c.agent().validateNonSTUNTraffic(c, srcAddr) { //nolint:contextcheck
-		log.Warnf("Discarded message from %s, not a valid remote candidate", c.addr())
+	if !a.validateNonSTUNTraffic(c, srcAddr) { //nolint:contextcheck
+		a.log.Warnf("Discarded message from %s, not a valid remote candidate", c.addr())
 		return
 	}
 
-	// NOTE This will return packetio.ErrFull if the buffer ever manages to fill up.
-	if _, err := c.agent().buffer.Write(buffer); err != nil {
-		log.Warnf("failed to write packet")
+	// Note: This will return packetio.ErrFull if the buffer ever manages to fill up.
+	if _, err := a.buf.Write(buf); err != nil {
+		a.log.Warnf("Failed to write packet: %s", err)
+		return
 	}
 }
 
@@ -484,7 +488,7 @@ func UnmarshalCandidate(raw string) (Candidate, error) {
 			relatedPort = int(rawRelatedPort)
 		} else if split[0] == "tcptype" {
 			if len(split) < 2 {
-				return nil, fmt.Errorf("%w: incorrect length", errParseTypType)
+				return nil, fmt.Errorf("%w: incorrect length", errParseTCPType)
 			}
 
 			tcpType = NewTCPType(split[1])
diff --git a/errors.go b/errors.go
index dbda8bd..647b2be 100644
--- a/errors.go
+++ b/errors.go
@@ -118,7 +118,7 @@ var (
 	errParsePriority                 = errors.New("could not parse priority")
 	errParsePort                     = errors.New("could not parse port")
 	errParseRelatedAddr              = errors.New("could not parse related addresses")
-	errParseTypType                  = errors.New("could not parse typtype")
+	errParseTCPType                  = errors.New("could not parse TCP type")
 	errGetXorMappedAddrResponse      = errors.New("failed to get XOR-MAPPED-ADDRESS response")
 	errConnectionAddrAlreadyExist    = errors.New("connection with same remote address already exists")
 	errReadingStreamingPacket        = errors.New("error reading streaming packet")
diff --git a/gather.go b/gather.go
index 78ca8e2..6cde60a 100644
--- a/gather.go
+++ b/gather.go
@@ -221,7 +221,7 @@ func (a *Agent) gatherCandidatesLocal(ctx context.Context, networkTypes []Networ
 				// is there a way to verify that the listen address is even
 				// accessible from the current interface.
 			case udp:
-				conn, err := listenUDPInPortRange(a.net, a.log, int(a.portmax), int(a.portmin), network, &net.UDPAddr{IP: ip, Port: 0})
+				conn, err := listenUDPInPortRange(a.net, a.log, int(a.portMax), int(a.portMin), network, &net.UDPAddr{IP: ip, Port: 0})
 				if err != nil {
 					a.log.Warnf("could not listen %s %s", network, ip)
 					continue
@@ -334,38 +334,38 @@ func (a *Agent) gatherCandidatesSrflxMapped(ctx context.Context, networkTypes []
 		go func() {
 			defer wg.Done()
 
-			conn, err := listenUDPInPortRange(a.net, a.log, int(a.portmax), int(a.portmin), network, &net.UDPAddr{IP: nil, Port: 0})
+			conn, err := listenUDPInPortRange(a.net, a.log, int(a.portMax), int(a.portMin), network, &net.UDPAddr{IP: nil, Port: 0})
 			if err != nil {
 				a.log.Warnf("Failed to listen %s: %v", network, err)
 				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,
@@ -469,7 +469,7 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT
 					return
 				}
 
-				conn, err := listenUDPInPortRange(a.net, a.log, int(a.portmax), int(a.portmin), network, &net.UDPAddr{IP: nil, Port: 0})
+				conn, err := listenUDPInPortRange(a.net, a.log, int(a.portMax), int(a.portMin), network, &net.UDPAddr{IP: nil, Port: 0})
 				if err != nil {
 					closeConnAndLog(conn, a.log, fmt.Sprintf("Failed to listen for %s: %v", serverAddr.String(), err))
 					return
@@ -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
 			}
 
diff --git a/ice.go b/ice.go
index d7094f6..7991c89 100644
--- a/ice.go
+++ b/ice.go
@@ -52,13 +52,13 @@ func (c ConnectionState) String() string {
 type GatheringState int
 
 const (
-	// GatheringStateNew indicates candidate gatering is not yet started
+	// GatheringStateNew indicates candidate gathering is not yet started
 	GatheringStateNew GatheringState = iota + 1
 
-	// GatheringStateGathering indicates candidate gatering is ongoing
+	// GatheringStateGathering indicates candidate gathering is ongoing
 	GatheringStateGathering
 
-	// GatheringStateComplete indicates candidate gatering has been completed
+	// GatheringStateComplete indicates candidate gathering has been completed
 	GatheringStateComplete
 )
 
diff --git a/stats.go b/stats.go
index f59d89f..26c03e5 100644
--- a/stats.go
+++ b/stats.go
@@ -104,7 +104,7 @@ type CandidatePairStats struct {
 	// ResponsesReceived represents the total number of connectivity check responses received.
 	ResponsesReceived uint64
 
-	// ResponsesSent epresents the total number of connectivity check responses sent.
+	// ResponsesSent represents the total number of connectivity check responses sent.
 	// Since we cannot distinguish connectivity check requests and consent requests,
 	// all responses are counted.
 	ResponsesSent uint64
diff --git a/tcp_mux.go b/tcp_mux.go
index 100da53..779ee45 100644
--- a/tcp_mux.go
+++ b/tcp_mux.go
@@ -403,11 +403,11 @@ func readStreamingPacket(conn net.Conn, buf []byte) (int, error) {
 }
 
 func writeStreamingPacket(conn net.Conn, buf []byte) (int, error) {
-	bufferCopy := make([]byte, streamingPacketHeaderLen+len(buf))
-	binary.BigEndian.PutUint16(bufferCopy, uint16(len(buf)))
-	copy(bufferCopy[2:], buf)
+	bufCopy := make([]byte, streamingPacketHeaderLen+len(buf))
+	binary.BigEndian.PutUint16(bufCopy, uint16(len(buf)))
+	copy(bufCopy[2:], buf)
 
-	n, err := conn.Write(bufferCopy)
+	n, err := conn.Write(bufCopy)
 	if err != nil {
 		return 0, err
 	}
diff --git a/tcp_mux_multi.go b/tcp_mux_multi.go
index d6e7649..ae9c625 100644
--- a/tcp_mux_multi.go
+++ b/tcp_mux_multi.go
@@ -17,14 +17,14 @@ type AllConnsGetter interface {
 // allowing users to pass multiple TCPMux instances to the ICE agent
 // configuration.
 type MultiTCPMuxDefault struct {
-	muxs []TCPMux
+	muxes []TCPMux
 }
 
 // NewMultiTCPMuxDefault creates an instance of MultiTCPMuxDefault that
 // uses the provided TCPMux instances.
-func NewMultiTCPMuxDefault(muxs ...TCPMux) *MultiTCPMuxDefault {
+func NewMultiTCPMuxDefault(muxes ...TCPMux) *MultiTCPMuxDefault {
 	return &MultiTCPMuxDefault{
-		muxs: muxs,
+		muxes: muxes,
 	}
 }
 
@@ -35,28 +35,28 @@ func NewMultiTCPMuxDefault(muxs ...TCPMux) *MultiTCPMuxDefault {
 func (m *MultiTCPMuxDefault) GetConnByUfrag(ufrag string, isIPv6 bool, local net.IP) (net.PacketConn, error) {
 	// NOTE: We always use the first element here in order to maintain the
 	// behavior of using an existing connection if one exists.
-	if len(m.muxs) == 0 {
+	if len(m.muxes) == 0 {
 		return nil, errNoTCPMuxAvailable
 	}
-	return m.muxs[0].GetConnByUfrag(ufrag, isIPv6, local)
+	return m.muxes[0].GetConnByUfrag(ufrag, isIPv6, local)
 }
 
 // RemoveConnByUfrag stops and removes the muxed packet connection
 // from all underlying TCPMux instances.
 func (m *MultiTCPMuxDefault) RemoveConnByUfrag(ufrag string) {
-	for _, mux := range m.muxs {
+	for _, mux := range m.muxes {
 		mux.RemoveConnByUfrag(ufrag)
 	}
 }
 
 // GetAllConns returns a PacketConn for each underlying TCPMux
 func (m *MultiTCPMuxDefault) GetAllConns(ufrag string, isIPv6 bool, local net.IP) ([]net.PacketConn, error) {
-	if len(m.muxs) == 0 {
+	if len(m.muxes) == 0 {
 		// Make sure that we either return at least one connection or an error.
 		return nil, errNoTCPMuxAvailable
 	}
 	var conns []net.PacketConn
-	for _, mux := range m.muxs {
+	for _, mux := range m.muxes {
 		conn, err := mux.GetConnByUfrag(ufrag, isIPv6, local)
 		if err != nil {
 			// For now, this implementation is all or none.
@@ -72,7 +72,7 @@ func (m *MultiTCPMuxDefault) GetAllConns(ufrag string, isIPv6 bool, local net.IP
 // Close the multi mux, no further connections could be created
 func (m *MultiTCPMuxDefault) Close() error {
 	var err error
-	for _, mux := range m.muxs {
+	for _, mux := range m.muxes {
 		if e := mux.Close(); e != nil {
 			err = e
 		}
diff --git a/tcp_packet_conn.go b/tcp_packet_conn.go
index 5241222..30aed5b 100644
--- a/tcp_packet_conn.go
+++ b/tcp_packet_conn.go
@@ -15,20 +15,20 @@ import (
 
 type bufferedConn struct {
 	net.Conn
-	buffer *packetio.Buffer
+	buf    *packetio.Buffer
 	logger logging.LeveledLogger
 	closed int32
 }
 
-func newBufferedConn(conn net.Conn, bufferSize int, logger logging.LeveledLogger) net.Conn {
-	buffer := packetio.NewBuffer()
-	if bufferSize > 0 {
-		buffer.SetLimitSize(bufferSize)
+func newBufferedConn(conn net.Conn, bufSize int, logger logging.LeveledLogger) net.Conn {
+	buf := packetio.NewBuffer()
+	if bufSize > 0 {
+		buf.SetLimitSize(bufSize)
 	}
 
 	bc := &bufferedConn{
 		Conn:   conn,
-		buffer: buffer,
+		buf:    buf,
 		logger: logger,
 	}
 
@@ -37,7 +37,7 @@ func newBufferedConn(conn net.Conn, bufferSize int, logger logging.LeveledLogger
 }
 
 func (bc *bufferedConn) Write(b []byte) (int, error) {
-	n, err := bc.buffer.Write(b)
+	n, err := bc.buf.Write(b)
 	if err != nil {
 		return n, err
 	}
@@ -47,7 +47,7 @@ func (bc *bufferedConn) Write(b []byte) (int, error) {
 func (bc *bufferedConn) writeProcess() {
 	pktBuf := make([]byte, receiveMTU)
 	for atomic.LoadInt32(&bc.closed) == 0 {
-		n, err := bc.buffer.Read(pktBuf)
+		n, err := bc.buf.Read(pktBuf)
 		if errors.Is(err, io.EOF) {
 			return
 		}
@@ -66,7 +66,7 @@ func (bc *bufferedConn) writeProcess() {
 
 func (bc *bufferedConn) Close() error {
 	atomic.StoreInt32(&bc.closed, 1)
-	_ = bc.buffer.Close()
+	_ = bc.buf.Close()
 	return bc.Conn.Close()
 }
 
@@ -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
 	}
 
diff --git a/tcptype.go b/tcptype.go
index 6700fe5..509167d 100644
--- a/tcptype.go
+++ b/tcptype.go
@@ -3,7 +3,7 @@ package ice
 import "strings"
 
 // TCPType is the type of ICE TCP candidate as described in
-// ttps://tools.ietf.org/html/rfc6544#section-4.5
+// https://tools.ietf.org/html/rfc6544#section-4.5
 type TCPType int
 
 const (
diff --git a/transport.go b/transport.go
index 08b1b6f..2e52656 100644
--- a/transport.go
+++ b/transport.go
@@ -70,7 +70,7 @@ func (c *Conn) Read(p []byte) (int, error) {
 		return 0, err
 	}
 
-	n, err := c.agent.buffer.Read(p)
+	n, err := c.agent.buf.Read(p)
 	atomic.AddUint64(&c.bytesReceived, uint64(n))
 	return n, err
 }
diff --git a/udp_mux.go b/udp_mux.go
index f31d4be..9cbd285 100644
--- a/udp_mux.go
+++ b/udp_mux.go
@@ -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) {
@@ -338,11 +338,11 @@ func (m *UDPMuxDefault) getConn(ufrag string, isIPv6 bool) (val *udpMuxedConn, o
 }
 
 type bufferHolder struct {
-	buffer []byte
+	buf []byte
 }
 
 func newBufferHolder(size int) *bufferHolder {
 	return &bufferHolder{
-		buffer: make([]byte, size),
+		buf: make([]byte, size),
 	}
 }
diff --git a/udp_mux_multi.go b/udp_mux_multi.go
index ff5cdcc..47ce404 100644
--- a/udp_mux_multi.go
+++ b/udp_mux_multi.go
@@ -14,21 +14,21 @@ import (
 // allowing users to pass multiple UDPMux instances to the ICE agent
 // configuration.
 type MultiUDPMuxDefault struct {
-	muxs           []UDPMux
+	muxes          []UDPMux
 	localAddrToMux map[string]UDPMux
 }
 
 // NewMultiUDPMuxDefault creates an instance of MultiUDPMuxDefault that
 // uses the provided UDPMux instances.
-func NewMultiUDPMuxDefault(muxs ...UDPMux) *MultiUDPMuxDefault {
+func NewMultiUDPMuxDefault(muxes ...UDPMux) *MultiUDPMuxDefault {
 	addrToMux := make(map[string]UDPMux)
-	for _, mux := range muxs {
+	for _, mux := range muxes {
 		for _, addr := range mux.GetListenAddresses() {
 			addrToMux[addr.String()] = mux
 		}
 	}
 	return &MultiUDPMuxDefault{
-		muxs:           muxs,
+		muxes:          muxes,
 		localAddrToMux: addrToMux,
 	}
 }
@@ -46,7 +46,7 @@ func (m *MultiUDPMuxDefault) GetConn(ufrag string, addr net.Addr) (net.PacketCon
 // RemoveConnByUfrag stops and removes the muxed packet connection
 // from all underlying UDPMux instances.
 func (m *MultiUDPMuxDefault) RemoveConnByUfrag(ufrag string) {
-	for _, mux := range m.muxs {
+	for _, mux := range m.muxes {
 		mux.RemoveConnByUfrag(ufrag)
 	}
 }
@@ -54,7 +54,7 @@ func (m *MultiUDPMuxDefault) RemoveConnByUfrag(ufrag string) {
 // Close the multi mux, no further connections could be created
 func (m *MultiUDPMuxDefault) Close() error {
 	var err error
-	for _, mux := range m.muxs {
+	for _, mux := range m.muxes {
 		if e := mux.Close(); e != nil {
 			err = e
 		}
@@ -65,7 +65,7 @@ func (m *MultiUDPMuxDefault) Close() error {
 // GetListenAddresses returns the list of addresses that this mux is listening on
 func (m *MultiUDPMuxDefault) GetListenAddresses() []net.Addr {
 	addrs := make([]net.Addr, 0, len(m.localAddrToMux))
-	for _, mux := range m.muxs {
+	for _, mux := range m.muxes {
 		addrs = append(addrs, mux.GetListenAddresses()...)
 	}
 	return addrs
@@ -109,13 +109,13 @@ func NewMultiUDPMuxFromPort(port int, opts ...UDPMuxFromPortOption) (*MultiUDPMu
 		return nil, err
 	}
 
-	muxs := make([]UDPMux, 0, len(conns))
+	muxes := make([]UDPMux, 0, len(conns))
 	for _, conn := range conns {
 		mux := NewUDPMuxDefault(UDPMuxParams{Logger: params.logger, UDPConn: conn})
-		muxs = append(muxs, mux)
+		muxes = append(muxes, mux)
 	}
 
-	return NewMultiUDPMuxDefault(muxs...), nil
+	return NewMultiUDPMuxDefault(muxes...), nil
 }
 
 // UDPMuxFromPortOption provide options for NewMultiUDPMuxFromPort
diff --git a/udp_muxed_conn.go b/udp_muxed_conn.go
index 6775ea1..ac7b704 100644
--- a/udp_muxed_conn.go
+++ b/udp_muxed_conn.go
@@ -26,7 +26,7 @@ type udpMuxedConn struct {
 	addresses []string
 
 	// channel holding incoming packets
-	buffer     *packetio.Buffer
+	buf        *packetio.Buffer
 	closedChan chan struct{}
 	closeOnce  sync.Once
 	mu         sync.Mutex
@@ -35,55 +35,55 @@ type udpMuxedConn struct {
 func newUDPMuxedConn(params *udpMuxedConnParams) *udpMuxedConn {
 	p := &udpMuxedConn{
 		params:     params,
-		buffer:     packetio.NewBuffer(),
+		buf:        packetio.NewBuffer(),
 		closedChan: make(chan struct{}),
 	}
 
 	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)
 
 	// read address
-	total, err := c.buffer.Read(buf.buffer)
+	total, err := c.buf.Read(buf.buf)
 	if err != nil {
 		return 0, nil, err
 	}
 
-	dataLen := int(binary.LittleEndian.Uint16(buf.buffer[:2]))
+	dataLen := int(binary.LittleEndian.Uint16(buf.buf[:2]))
 	if dataLen > total || dataLen > len(b) {
 		return 0, nil, io.ErrShortBuffer
 	}
 
 	// read data and then address
 	offset := 2
-	copy(b, buf.buffer[offset:offset+dataLen])
+	copy(b, buf.buf[offset:offset+dataLen])
 	offset += dataLen
 
 	// read address len & decode address
-	addrLen := int(binary.LittleEndian.Uint16(buf.buffer[offset : offset+2]))
+	addrLen := int(binary.LittleEndian.Uint16(buf.buf[offset : offset+2]))
 	offset += 2
 
-	if raddr, err = decodeUDPAddr(buf.buffer[offset : offset+addrLen]); err != nil {
+	if rAddr, err = decodeUDPAddr(buf.buf[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 {
@@ -109,7 +109,7 @@ func (c *udpMuxedConn) CloseChannel() <-chan struct{} {
 func (c *udpMuxedConn) Close() error {
 	var err error
 	c.closeOnce.Do(func() {
-		err = c.buffer.Close()
+		err = c.buf.Close()
 		close(c.closedChan)
 	})
 	return err
@@ -172,46 +172,46 @@ func (c *udpMuxedConn) writePacket(data []byte, addr *net.UDPAddr) error {
 	defer c.params.AddrPool.Put(buf)
 
 	// format of buffer | data len | data bytes | addr len | addr bytes |
-	if len(buf.buffer) < len(data)+maxAddrSize {
+	if len(buf.buf) < len(data)+maxAddrSize {
 		return io.ErrShortBuffer
 	}
 	// data len
-	binary.LittleEndian.PutUint16(buf.buffer, uint16(len(data)))
+	binary.LittleEndian.PutUint16(buf.buf, uint16(len(data)))
 	offset := 2
 
 	// data
-	copy(buf.buffer[offset:], data)
+	copy(buf.buf[offset:], data)
 	offset += len(data)
 
 	// write address first, leaving room for its length
-	n, err := encodeUDPAddr(addr, buf.buffer[offset+2:])
+	n, err := encodeUDPAddr(addr, buf.buf[offset+2:])
 	if err != nil {
 		return err
 	}
 	total := offset + n + 2
 
 	// address len
-	binary.LittleEndian.PutUint16(buf.buffer[offset:], uint16(n))
+	binary.LittleEndian.PutUint16(buf.buf[offset:], uint16(n))
 
-	if _, err := c.buffer.Write(buf.buffer[:total]); err != nil {
+	if _, err := c.buf.Write(buf.buf[:total]); err != nil {
 		return err
 	}
 	return nil
 }
 
 func encodeUDPAddr(addr *net.UDPAddr, buf []byte) (int, error) {
-	ipdata, err := addr.IP.MarshalText()
+	ipData, err := addr.IP.MarshalText()
 	if err != nil {
 		return 0, err
 	}
-	total := 2 + len(ipdata) + 2 + len(addr.Zone)
+	total := 2 + len(ipData) + 2 + len(addr.Zone)
 	if total > len(buf) {
 		return 0, io.ErrShortBuffer
 	}
 
-	binary.LittleEndian.PutUint16(buf, uint16(len(ipdata)))
+	binary.LittleEndian.PutUint16(buf, uint16(len(ipData)))
 	offset := 2
-	n := copy(buf[offset:], ipdata)
+	n := copy(buf[offset:], ipData)
 	offset += n
 	binary.LittleEndian.PutUint16(buf[offset:], uint16(addr.Port))
 	offset += 2
diff --git a/util.go b/util.go
index 011fd8c..22260de 100644
--- a/util.go
+++ b/util.go
@@ -94,8 +94,8 @@ func getXORMappedAddr(conn net.PacketConn, serverAddr net.Addr, deadline time.Du
 	}()
 	resp, err := stunRequest(
 		func(p []byte) (int, error) {
-			n, _, errr := conn.ReadFrom(p)
-			return n, errr
+			n, _, err := conn.ReadFrom(p)
+			return n, err
 		},
 		func(b []byte) (int, error) {
 			return conn.WriteTo(b, serverAddr)
@@ -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


Test patch:
diff --git a/agent_test.go b/agent_test.go
index 84c273c..befb02f 100644
--- a/agent_test.go
+++ b/agent_test.go
@@ -235,7 +235,7 @@ func TestHandlePeerReflexive(t *testing.T) {
 	lim := test.TimeOut(time.Second * 2)
 	defer lim.Stop()
 
-	t.Run("UDP pflx candidate from handleInbound()", func(t *testing.T) {
+	t.Run("UDP prflx candidate from handleInbound()", func(t *testing.T) {
 		var config AgentConfig
 		runAgentTest(t, &config, func(ctx context.Context, a *Agent) {
 			a.selector = &controllingSelector{agent: a, log: a.log}
@@ -920,7 +920,7 @@ func TestCandidatePairStats(t *testing.T) {
 	}
 
 	if prflxPairStat.State != CandidatePairStateFailed {
-		t.Fatalf("expected host-prfflx pair to have state failed, it has state %s instead",
+		t.Fatalf("expected host-prflx pair to have state failed, it has state %s instead",
 			prflxPairStat.State.String())
 	}
 
@@ -1232,7 +1232,7 @@ func TestAgentCredentials(t *testing.T) {
 	report := test.CheckRoutines(t)
 	defer report()
 
-	// Make sure to pass travis check by disabling the logs
+	// Make sure to pass Travis check by disabling the logs
 	log := logging.NewDefaultLoggerFactory()
 	log.DefaultLogLevel = logging.LogLevelDisabled
 
@@ -1467,7 +1467,7 @@ func TestAgentRestart(t *testing.T) {
 		<-aConnected
 		<-bConnected
 
-		// Assert that we have new candiates each time
+		// Assert that we have new candidates each time
 		assert.NotEqual(t, connAFirstCandidates, generateCandidateAddressStrings(connA.agent.GetLocalCandidates()))
 		assert.NotEqual(t, connBFirstCandidates, generateCandidateAddressStrings(connB.agent.GetLocalCandidates()))
 
diff --git a/agent_udpmux_test.go b/agent_udpmux_test.go
index 660984c..7572c8b 100644
--- a/agent_udpmux_test.go
+++ b/agent_udpmux_test.go
@@ -66,18 +66,18 @@ func TestMuxAgent(t *testing.T) {
 			_, err = conn.Write(data)
 			require.NoError(t, err)
 
-			buffer := make([]byte, 1024)
-			n, err := muxedConn.Read(buffer)
+			buf := make([]byte, 1024)
+			n, err := muxedConn.Read(buf)
 			require.NoError(t, err)
-			require.Equal(t, data, buffer[:n])
+			require.Equal(t, data, buf[:n])
 
 			// send a packet from Mux
 			_, err = muxedConn.Write(data)
 			require.NoError(t, err)
 
-			n, err = conn.Read(buffer)
+			n, err = conn.Read(buf)
 			require.NoError(t, err)
-			require.Equal(t, data, buffer[:n])
+			require.Equal(t, data, buf[:n])
 
 			// close it down
 			require.NoError(t, conn.Close())
diff --git a/external_ip_mapper_test.go b/external_ip_mapper_test.go
index 63a3b2f..7cbce23 100644
--- a/external_ip_mapper_test.go
+++ b/external_ip_mapper_test.go
@@ -189,15 +189,15 @@ func TestExternalIPMapper(t *testing.T) {
 		assert.Nil(t, m, "should be nil")
 	})
 
-	t.Run("newExternalIPMapper with inplicit and explicit local IP", func(t *testing.T) {
-		// Mixing inpicit and explicit local IPs not allowed
+	t.Run("newExternalIPMapper with implicit and explicit local IP", func(t *testing.T) {
+		// Mixing implicit and explicit local IPs not allowed
 		_, err := newExternalIPMapper(CandidateTypeUnspecified, []string{
 			"1.2.3.4",
 			"1.2.3.5/10.0.0.1",
 		})
 		assert.Error(t, err, "should fail")
 
-		// Mixing inpicit and explicit local IPs not allowed
+		// Mixing implicit and explicit local IPs not allowed
 		_, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
 			"1.2.3.5/10.0.0.1",
 			"1.2.3.4",
@@ -226,7 +226,7 @@ func TestExternalIPMapper(t *testing.T) {
 		assert.Equal(t, "1.2.3.4", extIP.String(), "should match")
 
 		// find external IPv6
-		extIP, err = m.findExternalIP("fe80::0001") // use '0001' instead of '1' on purpse
+		extIP, err = m.findExternalIP("fe80::0001") // use '0001' instead of '1' on purpose
 		assert.NoError(t, err, "should succeed")
 		assert.Equal(t, "2200::1", extIP.String(), "should match")
 
@@ -263,11 +263,11 @@ func TestExternalIPMapper(t *testing.T) {
 		assert.Error(t, err, "should fail")
 
 		// find external IPv6
-		extIP, err = m.findExternalIP("fe80::0001") // use '0001' instead of '1' on purpse
+		extIP, err = m.findExternalIP("fe80::0001") // use '0001' instead of '1' on purpose
 		assert.NoError(t, err, "should succeed")
 		assert.Equal(t, "2200::1", extIP.String(), "should match")
 
-		extIP, err = m.findExternalIP("fe80::0002") // use '0002' instead of '2' on purpse
+		extIP, err = m.findExternalIP("fe80::0002") // use '0002' instead of '2' on purpose
 		assert.NoError(t, err, "should succeed")
 		assert.Equal(t, "2200::2", extIP.String(), "should match")
 
diff --git a/gather_vnet_test.go b/gather_vnet_test.go
index f03771a..87d8130 100644
--- a/gather_vnet_test.go
+++ b/gather_vnet_test.go
@@ -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())
 			}
 		}
 	})
diff --git a/tcp_mux_multi_test.go b/tcp_mux_multi_test.go
index 4feddc5..9a770e2 100644
--- a/tcp_mux_multi_test.go
+++ b/tcp_mux_multi_test.go
@@ -16,11 +16,11 @@ import (
 )
 
 func TestMultiTCPMux_Recv(t *testing.T) {
-	for name, buffersize := range map[string]int{
+	for name, bufSize := range map[string]int{
 		"no buffer":    0,
 		"buffered 4MB": 4 * 1024 * 1024,
 	} {
-		bufSize := buffersize
+		bufSize := bufSize
 		t.Run(name, func(t *testing.T) {
 			report := test.CheckRoutines(t)
 			defer report()
@@ -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")
 
diff --git a/tcp_mux_test.go b/tcp_mux_test.go
index 3ec36fb..ec97306 100644
--- a/tcp_mux_test.go
+++ b/tcp_mux_test.go
@@ -18,11 +18,11 @@ var (
 )
 
 func TestTCPMux_Recv(t *testing.T) {
-	for name, buffersize := range map[string]int{
+	for name, bufSize := range map[string]int{
 		"no buffer":    0,
 		"buffered 4MB": 4 * 1024 * 1024,
 	} {
-		bufSize := buffersize
+		bufSize := bufSize
 		t.Run(name, func(t *testing.T) {
 			report := test.CheckRoutines(t)
 			defer report()
@@ -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")
 
diff --git a/transport_test.go b/transport_test.go
index 90c90c4..199f88f 100644
--- a/transport_test.go
+++ b/transport_test.go
@@ -27,9 +27,9 @@ func TestStressDuplex(t *testing.T) {
 }
 
 func testTimeout(t *testing.T, c *Conn, timeout time.Duration) {
-	const pollrate = 100 * time.Millisecond
+	const pollRate = 100 * time.Millisecond
 	const margin = 20 * time.Millisecond // allow 20msec error in time
-	ticker := time.NewTicker(pollrate)
+	ticker := time.NewTicker(pollRate)
 	defer func() {
 		ticker.Stop()
 		err := c.Close()
@@ -40,7 +40,7 @@ func testTimeout(t *testing.T, c *Conn, timeout time.Duration) {
 
 	startedAt := time.Now()
 
-	for cnt := time.Duration(0); cnt <= timeout+defaultKeepaliveInterval+pollrate; cnt += pollrate {
+	for cnt := time.Duration(0); cnt <= timeout+defaultKeepaliveInterval+pollRate; cnt += pollRate {
 		<-ticker.C
 
 		var cs ConnectionState
diff --git a/udp_mux_multi_test.go b/udp_mux_multi_test.go
index 82e3e9b..ce476a0 100644
--- a/udp_mux_multi_test.go
+++ b/udp_mux_multi_test.go
@@ -120,7 +120,7 @@ func TestUnspecifiedUDPMux(t *testing.T) {
 	}))
 	require.NoError(t, err)
 
-	require.GreaterOrEqual(t, len(udpMuxMulti.muxs), 1, "at least have 1 muxs")
+	require.GreaterOrEqual(t, len(udpMuxMulti.muxes), 1, "at least have 1 muxes")
 	defer func() {
 		_ = udpMuxMulti.Close()
 	}()