Finalize transport stabilization, cleanup, and debug tracing

This commit is contained in:
Amin.MasterkinG
2026-04-20 20:21:48 +03:30
parent 025923fe89
commit c4776c88e1
4 changed files with 63 additions and 3 deletions
+21 -2
View File
@@ -91,12 +91,17 @@ func (s *SOCKSConnectionStore) New(clientSessionKey string, clientAddress string
return socksConn
}
func (s *SOCKSConnection) WaitForConnect(timeout time.Duration) error {
func (s *SOCKSConnection) WaitForConnect(ctx context.Context, timeout time.Duration) error {
timer := time.NewTimer(timeout)
defer timer.Stop()
select {
case err := <-s.connectResultC:
return err
case <-time.After(timeout):
case <-timer.C:
return ErrSOCKSConnectTimeout
case <-ctx.Done():
return ctx.Err()
}
}
@@ -192,6 +197,20 @@ func (s *SOCKSConnectionStore) Delete(id uint64) {
s.mu.Unlock()
}
func (s *SOCKSConnectionStore) CloseAll() {
s.mu.Lock()
items := make([]*SOCKSConnection, 0, len(s.items))
for _, item := range s.items {
items = append(items, item)
}
s.items = make(map[uint64]*SOCKSConnection)
s.mu.Unlock()
for _, item := range items {
_ = item.CloseLocal()
}
}
func (s *SOCKSConnectionStore) Snapshot() []*SOCKSConnection {
s.mu.RLock()
defer s.mu.RUnlock()