Skip to content

Commit b14464d

Browse files
committed
Use netip.Addr as IP type in the IPKey struct.
1 parent a3d7a57 commit b14464d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cmd/outline-ss-server/metrics.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package main
1717
import (
1818
"fmt"
1919
"net"
20+
"net/netip"
2021
"strconv"
2122
"sync"
2223
"time"
@@ -72,7 +73,7 @@ type activeClient struct {
7273
}
7374

7475
type IPKey struct {
75-
ip string
76+
ip netip.Addr
7677
accessKey string
7778
}
7879

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

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

133134
t.mu.Lock()
134135
defer t.mu.Unlock()

0 commit comments

Comments
 (0)