Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efbbb25

Browse files
committed
lol
1 parent be86d60 commit efbbb25

File tree

5 files changed

+17
-33
lines changed

5 files changed

+17
-33
lines changed

agent/agent.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,9 @@ func (a *agent) trackConnGoroutine(fn func()) error {
397397

398398
func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_ *tailnet.Conn, err error) {
399399
network, err := tailnet.NewConn(&tailnet.Options{
400-
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.WorkspaceAgentIP, 128)},
401-
DERPMap: derpMap,
402-
Logger: a.logger.Named("tailnet"),
403-
EnableTrafficStats: true,
400+
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.WorkspaceAgentIP, 128)},
401+
DERPMap: derpMap,
402+
Logger: a.logger.Named("tailnet"),
404403
})
405404
if err != nil {
406405
return nil, xerrors.Errorf("create tailnet: %w", err)

agent/agent_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,17 +1103,16 @@ func setupAgent(t *testing.T, metadata agentsdk.Metadata, ptyTimeout time.Durati
11031103
closer := agent.New(agent.Options{
11041104
Client: c,
11051105
Filesystem: fs,
1106-
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
1106+
Logger: slogtest.Make(t, nil).Named("agent").Leveled(slog.LevelDebug),
11071107
ReconnectingPTYTimeout: ptyTimeout,
11081108
})
11091109
t.Cleanup(func() {
11101110
_ = closer.Close()
11111111
})
11121112
conn, err := tailnet.NewConn(&tailnet.Options{
1113-
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
1114-
DERPMap: metadata.DERPMap,
1115-
Logger: slogtest.Make(t, nil).Named("client").Leveled(slog.LevelDebug),
1116-
EnableTrafficStats: true,
1113+
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
1114+
DERPMap: metadata.DERPMap,
1115+
Logger: slogtest.Make(t, nil).Named("client").Leveled(slog.LevelDebug),
11171116
})
11181117
require.NoError(t, err)
11191118
clientConn, serverConn := net.Pipe()

cli/vscodessh.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ func vscodeSSH() *cobra.Command {
120120
}
121121
}
122122

123-
agentConn, err := client.DialWorkspaceAgent(ctx, agent.ID, &codersdk.DialWorkspaceAgentOptions{
124-
EnableTrafficStats: true,
125-
})
123+
agentConn, err := client.DialWorkspaceAgent(ctx, agent.ID, &codersdk.DialWorkspaceAgentOptions{})
126124
if err != nil {
127125
return xerrors.Errorf("dial workspace agent: %w", err)
128126
}

codersdk/workspaceagents.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ type WorkspaceAgentConnectionInfo struct {
9696
type DialWorkspaceAgentOptions struct {
9797
Logger slog.Logger
9898
// BlockEndpoints forced a direct connection through DERP.
99-
BlockEndpoints bool
100-
EnableTrafficStats bool
99+
BlockEndpoints bool
101100
}
102101

103102
func (c *Client) DialWorkspaceAgent(ctx context.Context, agentID uuid.UUID, options *DialWorkspaceAgentOptions) (*WorkspaceAgentConn, error) {
@@ -120,11 +119,10 @@ func (c *Client) DialWorkspaceAgent(ctx context.Context, agentID uuid.UUID, opti
120119

121120
ip := tailnet.IP()
122121
conn, err := tailnet.NewConn(&tailnet.Options{
123-
Addresses: []netip.Prefix{netip.PrefixFrom(ip, 128)},
124-
DERPMap: connInfo.DERPMap,
125-
Logger: options.Logger,
126-
BlockEndpoints: options.BlockEndpoints,
127-
EnableTrafficStats: options.EnableTrafficStats,
122+
Addresses: []netip.Prefix{netip.PrefixFrom(ip, 128)},
123+
DERPMap: connInfo.DERPMap,
124+
Logger: options.Logger,
125+
BlockEndpoints: options.BlockEndpoints,
128126
})
129127
if err != nil {
130128
return nil, xerrors.Errorf("create tailnet: %w", err)

tailnet/conn.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ type Options struct {
5656
// If so, only DERPs can establish connections.
5757
BlockEndpoints bool
5858
Logger slog.Logger
59-
60-
// EnableTrafficStats enables per-connection traffic statistics.
61-
// ExtractTrafficStats must be called to reset the counters and be
62-
// periodically called while enabled to avoid unbounded memory use.
63-
EnableTrafficStats bool
6459
}
6560

6661
// NewConn constructs a new Wireguard server that will accept connections from the addresses provided.
@@ -74,6 +69,7 @@ func NewConn(options *Options) (*Conn, error) {
7469
if options.DERPMap == nil {
7570
return nil, xerrors.New("DERPMap must be provided")
7671
}
72+
7773
nodePrivateKey := key.NewNode()
7874
nodePublicKey := nodePrivateKey.Public()
7975

@@ -712,21 +708,15 @@ func (c *Conn) forwardTCPToLocal(conn net.Conn, port uint16) {
712708
c.logger.Debug(c.dialContext, "forwarded connection closed", slog.F("local_addr", dialAddrStr))
713709
}
714710

715-
// ExtractTrafficStats extracts and resets the counters for all active
716-
// connections. It must be called periodically otherwise the memory used is
717-
// unbounded. EnableTrafficStats must be true when calling NewConn.
718-
// func (c *Conn) ExtractTrafficStats() map[netlogtype.Connection]netlogtype.Counts {
719-
// virt, _ := c.trafficStats.TestExtract()
720-
// return virt
721-
// }
722-
711+
// SetConnStatsCallback sets a callback to be called after maxPeriod or
712+
// maxConns, whichever comes first. Multiple calls overwrites the callback.
723713
func (c *Conn) SetConnStatsCallback(maxPeriod time.Duration, maxConns int, dump func(start, end time.Time, virtual, physical map[netlogtype.Connection]netlogtype.Counts)) {
724714
connStats := connstats.NewStatistics(maxPeriod, maxConns, dump)
725715

726716
c.mutex.Lock()
727717
old := c.trafficStats
728718
c.trafficStats = connStats
729-
c.mutex.Lock()
719+
c.mutex.Unlock()
730720

731721
// Make sure to shutdown the old callback.
732722
if old != nil {

0 commit comments

Comments
 (0)