mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-03 20:27:31 +00:00
chore: rebuild slowdown code
This commit is contained in:
34
component/proxydialer/slowdown.go
Normal file
34
component/proxydialer/slowdown.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package proxydialer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/metacubex/mihomo/component/slowdown"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
)
|
||||
|
||||
type SlowDownDialer struct {
|
||||
C.Dialer
|
||||
Slowdown *slowdown.SlowDown
|
||||
}
|
||||
|
||||
func (d SlowDownDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return slowdown.Do(d.Slowdown, ctx, func() (net.Conn, error) {
|
||||
return d.Dialer.DialContext(ctx, network, address)
|
||||
})
|
||||
}
|
||||
|
||||
func (d SlowDownDialer) ListenPacket(ctx context.Context, network, address string, rAddrPort netip.AddrPort) (net.PacketConn, error) {
|
||||
return slowdown.Do(d.Slowdown, ctx, func() (net.PacketConn, error) {
|
||||
return d.Dialer.ListenPacket(ctx, network, address, rAddrPort)
|
||||
})
|
||||
}
|
||||
|
||||
func NewSlowDownDialer(d C.Dialer, sd *slowdown.SlowDown) SlowDownDialer {
|
||||
return SlowDownDialer{
|
||||
Dialer: d,
|
||||
Slowdown: sd,
|
||||
}
|
||||
}
|
||||
33
component/proxydialer/slowdown_sing.go
Normal file
33
component/proxydialer/slowdown_sing.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package proxydialer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/metacubex/mihomo/component/slowdown"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
)
|
||||
|
||||
type SlowDownSingDialer struct {
|
||||
SingDialer
|
||||
Slowdown *slowdown.SlowDown
|
||||
}
|
||||
|
||||
func (d SlowDownSingDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
return slowdown.Do(d.Slowdown, ctx, func() (net.Conn, error) {
|
||||
return d.SingDialer.DialContext(ctx, network, destination)
|
||||
})
|
||||
}
|
||||
|
||||
func (d SlowDownSingDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
return slowdown.Do(d.Slowdown, ctx, func() (net.PacketConn, error) {
|
||||
return d.SingDialer.ListenPacket(ctx, destination)
|
||||
})
|
||||
}
|
||||
|
||||
func NewSlowDownSingDialer(d SingDialer, sd *slowdown.SlowDown) SlowDownSingDialer {
|
||||
return SlowDownSingDialer{
|
||||
SingDialer: d,
|
||||
Slowdown: sd,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user