Skip to content

Commit 6f706c7

Browse files
committed
Make activeClients a map of pointers.
1 parent 09fd19e commit 6f706c7

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

cmd/outline-ss-server/metrics.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type IPKey struct {
7575
}
7676

7777
type tunnelTimeTracker struct {
78-
activeClients map[IPKey]activeClient
78+
activeClients map[IPKey]*activeClient
7979
reportTunnelTime ReportTunnelTimeFunc
8080
}
8181

@@ -91,14 +91,12 @@ func (t *tunnelTimeTracker) reportAll(now time.Time) {
9191
}
9292

9393
// Reports time connected for a given active client.
94-
func (t *tunnelTimeTracker) reportDuration(c activeClient, now time.Time) {
94+
func (t *tunnelTimeTracker) reportDuration(c *activeClient, now time.Time) {
9595
connDuration := now.Sub(c.startTime)
9696
logger.Debugf("Reporting activity for key `%v`, duration: %v", c.IPKey.accessKey, connDuration)
9797
t.reportTunnelTime(c.IPKey, c.clientInfo, connDuration)
98-
9998
// Reset the start time now that it's been reported.
10099
c.startTime = Now()
101-
t.activeClients[c.IPKey] = c
102100
}
103101

104102
// Registers a new active connection for a client [net.Addr] and access key.
@@ -108,7 +106,7 @@ func (t *tunnelTimeTracker) startConnection(clientInfo ipinfo.IPInfo, clientAddr
108106

109107
c, exists := t.activeClients[ipKey]
110108
if !exists {
111-
c = activeClient{ipKey, clientInfo, 0, Now()}
109+
c = &activeClient{ipKey, clientInfo, 0, Now()}
112110
}
113111
c.connectionCount++
114112
t.activeClients[ipKey] = c
@@ -119,7 +117,6 @@ func (t *tunnelTimeTracker) stopConnection(clientAddr net.Addr, accessKey string
119117
hostname, _, _ := net.SplitHostPort(clientAddr.String())
120118
ipKey := IPKey{ip: hostname, accessKey: accessKey}
121119

122-
c := t.activeClients[ipKey]
123120
c, exists := t.activeClients[ipKey]
124121
if !exists {
125122
logger.Warningf("Failed to find active client")
@@ -135,7 +132,7 @@ func (t *tunnelTimeTracker) stopConnection(clientAddr net.Addr, accessKey string
135132
}
136133

137134
func newTunnelTimeTracker(report ReportTunnelTimeFunc) *tunnelTimeTracker {
138-
tracker := &tunnelTimeTracker{activeClients: make(map[IPKey]activeClient), reportTunnelTime: report}
135+
tracker := &tunnelTimeTracker{activeClients: make(map[IPKey]*activeClient), reportTunnelTime: report}
139136
ticker := time.NewTicker(tunnelTimeTrackerReportingInterval)
140137
go func() {
141138
for t := range ticker.C {

0 commit comments

Comments
 (0)