Skip to content

Commit ea9f5b8

Browse files
committed
remove unnecessary connection storing
1 parent a71a5c2 commit ea9f5b8

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

tracker/clientcontext/manager.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"github.com/sagernet/sing/common/bufio"
1818
"github.com/sagernet/sing/common/metadata"
1919
N "github.com/sagernet/sing/common/network"
20-
21-
isync "github.com/getlantern/lantern-box/internal/sync"
2220
)
2321

2422
var _ (adapter.ConnectionTracker) = (*Manager)(nil)
@@ -38,9 +36,8 @@ func ClientInfoFromContext(ctx context.Context) (ClientInfo, bool) {
3836

3937
// Manager is a ConnectionTracker that manages ClientInfo for connections.
4038
type Manager struct {
41-
connections isync.TypedMap[io.Closer, *ClientInfo]
42-
logger log.ContextLogger
43-
trackers []adapter.ConnectionTracker
39+
logger log.ContextLogger
40+
trackers []adapter.ConnectionTracker
4441

4542
inboundRule *boundsRule
4643
outboundRule *boundsRule
@@ -49,7 +46,6 @@ type Manager struct {
4946
// NewManager creates a new ClientContext Manager.
5047
func NewManager(bounds MatchBounds, logger log.ContextLogger) *Manager {
5148
return &Manager{
52-
connections: isync.TypedMap[io.Closer, *ClientInfo]{},
5349
trackers: []adapter.ConnectionTracker{},
5450
logger: logger,
5551
inboundRule: newBoundsRule(bounds.Inbound),
@@ -62,10 +58,6 @@ func (m *Manager) AppendTracker(tracker adapter.ConnectionTracker) {
6258
m.trackers = append(m.trackers, tracker)
6359
}
6460

65-
func (m *Manager) deleteConnection(conn io.Closer) {
66-
m.connections.Delete(conn)
67-
}
68-
6961
func (m *Manager) RoutedConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) net.Conn {
7062
if !m.inboundRule.match(metadata.Inbound) || !m.outboundRule.match(matchOutbound.Tag()) {
7163
return conn
@@ -79,7 +71,6 @@ func (m *Manager) RoutedConnection(ctx context.Context, conn net.Conn, metadata
7971
if err != c.readErr {
8072
m.logger.Error("failed to read client info ", "tag", "clientcontext-tracker", "error", err)
8173
}
82-
m.connections.Store(c, info)
8374
if err != nil {
8475
return c
8576
}
@@ -106,7 +97,6 @@ func (m *Manager) RoutedPacketConnection(ctx context.Context, conn N.PacketConn,
10697
if err != c.readErr {
10798
m.logger.Error("failed to read client info ", "tag", "clientcontext-tracker", "error", err)
10899
}
109-
m.connections.Store(c, info)
110100
if err != nil {
111101
return c
112102
}
@@ -143,13 +133,6 @@ func (c *readConn) Read(b []byte) (n int, err error) {
143133
return c.reader.Read(b)
144134
}
145135

146-
func (c *readConn) Close() error {
147-
if !c.closed.Swap(true) {
148-
c.mgr.deleteConnection(c)
149-
}
150-
return c.Conn.Close()
151-
}
152-
153136
// readInfo reads and decodes client info, then sends an HTTP 200 OK response.
154137
func (c *readConn) readInfo() (*ClientInfo, error) {
155138
var buf [32]byte
@@ -198,11 +181,6 @@ func (c *readPacketConn) ReadPacket(b *buf.Buffer) (destination metadata.Socksad
198181
return c.PacketConn.ReadPacket(b)
199182
}
200183

201-
func (c *readPacketConn) Close() error {
202-
c.mgr.deleteConnection(c)
203-
return c.PacketConn.Close()
204-
}
205-
206184
// readInfo reads and decodes client info if the first packet is a CLIENTINFO packet, then sends an
207185
// OK response.
208186
func (c *readPacketConn) readInfo() (*ClientInfo, error) {

0 commit comments

Comments
 (0)