From b14464ddefa6dd4d0f3096a3c8f83f33c39574f6 Mon Sep 17 00:00:00 2001 From: sbruens Date: Thu, 21 Mar 2024 13:56:32 -0400 Subject: [PATCH] Use `netip.Addr` as IP type in the `IPKey` struct. --- cmd/outline-ss-server/metrics.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/outline-ss-server/metrics.go b/cmd/outline-ss-server/metrics.go index fcf1abd5..b85f7e9f 100644 --- a/cmd/outline-ss-server/metrics.go +++ b/cmd/outline-ss-server/metrics.go @@ -17,6 +17,7 @@ package main import ( "fmt" "net" + "net/netip" "strconv" "sync" "time" @@ -72,7 +73,7 @@ type activeClient struct { } type IPKey struct { - ip string + ip netip.Addr accessKey string } @@ -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() @@ -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()