github.com/kelleygo/clashcore@v1.0.2/component/proxydialer/slowdown_sing.go (about)

     1  package proxydialer
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  
     7  	"github.com/kelleygo/clashcore/component/slowdown"
     8  	M "github.com/sagernet/sing/common/metadata"
     9  )
    10  
    11  type SlowDownSingDialer struct {
    12  	SingDialer
    13  	Slowdown *slowdown.SlowDown
    14  }
    15  
    16  func (d SlowDownSingDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
    17  	return slowdown.Do(d.Slowdown, ctx, func() (net.Conn, error) {
    18  		return d.SingDialer.DialContext(ctx, network, destination)
    19  	})
    20  }
    21  
    22  func (d SlowDownSingDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
    23  	return slowdown.Do(d.Slowdown, ctx, func() (net.PacketConn, error) {
    24  		return d.SingDialer.ListenPacket(ctx, destination)
    25  	})
    26  }
    27  
    28  func NewSlowDownSingDialer(d SingDialer, sd *slowdown.SlowDown) SlowDownSingDialer {
    29  	return SlowDownSingDialer{
    30  		SingDialer: d,
    31  		Slowdown:   sd,
    32  	}
    33  }