Skip to content

Commit

Permalink
Use netip.Addr as IP type in the IPKey struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Mar 21, 2024
1 parent a3d7a57 commit b14464d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cmd/outline-ss-server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"fmt"
"net"
"net/netip"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -72,7 +73,7 @@ type activeClient struct {
}

type IPKey struct {
ip string
ip netip.Addr
accessKey string
}

Expand Down Expand Up @@ -109,7 +110,7 @@ func (t *tunnelTimeTracker) reportDuration(c *activeClient, now time.Time) {
// Registers a new active connection for a client [net.Addr] and access key.
func (t *tunnelTimeTracker) startConnection(clientInfo ipinfo.IPInfo, clientAddr net.Addr, accessKey string) {
hostname, _, _ := net.SplitHostPort(clientAddr.String())
ipKey := IPKey{ip: hostname, accessKey: accessKey}
ipKey := IPKey{ip: netip.MustParseAddr(hostname), accessKey: accessKey}

t.mu.Lock()
defer t.mu.Unlock()
Expand All @@ -128,7 +129,7 @@ func (t *tunnelTimeTracker) startConnection(clientInfo ipinfo.IPInfo, clientAddr
// Removes an active connection for a client [net.Addr] and access key.
func (t *tunnelTimeTracker) stopConnection(clientAddr net.Addr, accessKey string) {
hostname, _, _ := net.SplitHostPort(clientAddr.String())
ipKey := IPKey{ip: hostname, accessKey: accessKey}
ipKey := IPKey{ip: netip.MustParseAddr(hostname), accessKey: accessKey}

t.mu.Lock()
defer t.mu.Unlock()
Expand Down

0 comments on commit b14464d

Please sign in to comment.