chore: clean code
This commit is contained in:
parent
482062376e
commit
b725c91b05
4 changed files with 1 additions and 30 deletions
|
@ -1,7 +1,6 @@
|
||||||
package faketcp
|
package faketcp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Dreamacro/clash/log"
|
|
||||||
"github.com/Dreamacro/clash/transport/hysteria/obfs"
|
"github.com/Dreamacro/clash/transport/hysteria/obfs"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -14,7 +13,6 @@ const udpBufferSize = 65535
|
||||||
type ObfsFakeTCPConn struct {
|
type ObfsFakeTCPConn struct {
|
||||||
orig *TCPConn
|
orig *TCPConn
|
||||||
obfs obfs.Obfuscator
|
obfs obfs.Obfuscator
|
||||||
closed bool
|
|
||||||
readBuf []byte
|
readBuf []byte
|
||||||
readMutex sync.Mutex
|
readMutex sync.Mutex
|
||||||
writeBuf []byte
|
writeBuf []byte
|
||||||
|
@ -33,13 +31,7 @@ func NewObfsFakeTCPConn(orig *TCPConn, obfs obfs.Obfuscator) *ObfsFakeTCPConn {
|
||||||
func (c *ObfsFakeTCPConn) ReadFrom(p []byte) (int, net.Addr, error) {
|
func (c *ObfsFakeTCPConn) ReadFrom(p []byte) (int, net.Addr, error) {
|
||||||
for {
|
for {
|
||||||
c.readMutex.Lock()
|
c.readMutex.Lock()
|
||||||
if c.closed {
|
|
||||||
log.Infoln("read faketcp obfs before")
|
|
||||||
}
|
|
||||||
n, addr, err := c.orig.ReadFrom(c.readBuf)
|
n, addr, err := c.orig.ReadFrom(c.readBuf)
|
||||||
if c.closed {
|
|
||||||
log.Infoln("read faketcp obfs after")
|
|
||||||
}
|
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
c.readMutex.Unlock()
|
c.readMutex.Unlock()
|
||||||
return 0, addr, err
|
return 0, addr, err
|
||||||
|
@ -69,7 +61,6 @@ func (c *ObfsFakeTCPConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ObfsFakeTCPConn) Close() error {
|
func (c *ObfsFakeTCPConn) Close() error {
|
||||||
c.closed = true
|
|
||||||
return c.orig.Close()
|
return c.orig.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package udp
|
package udp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Dreamacro/clash/log"
|
|
||||||
"github.com/Dreamacro/clash/transport/hysteria/obfs"
|
"github.com/Dreamacro/clash/transport/hysteria/obfs"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -17,7 +16,6 @@ type ObfsUDPConn struct {
|
||||||
readMutex sync.Mutex
|
readMutex sync.Mutex
|
||||||
writeBuf []byte
|
writeBuf []byte
|
||||||
writeMutex sync.Mutex
|
writeMutex sync.Mutex
|
||||||
closed bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewObfsUDPConn(orig net.PacketConn, obfs obfs.Obfuscator) *ObfsUDPConn {
|
func NewObfsUDPConn(orig net.PacketConn, obfs obfs.Obfuscator) *ObfsUDPConn {
|
||||||
|
@ -32,13 +30,7 @@ func NewObfsUDPConn(orig net.PacketConn, obfs obfs.Obfuscator) *ObfsUDPConn {
|
||||||
func (c *ObfsUDPConn) ReadFrom(p []byte) (int, net.Addr, error) {
|
func (c *ObfsUDPConn) ReadFrom(p []byte) (int, net.Addr, error) {
|
||||||
for {
|
for {
|
||||||
c.readMutex.Lock()
|
c.readMutex.Lock()
|
||||||
if c.closed {
|
|
||||||
log.Infoln("read udp obfs before")
|
|
||||||
}
|
|
||||||
n, addr, err := c.orig.ReadFrom(c.readBuf)
|
n, addr, err := c.orig.ReadFrom(c.readBuf)
|
||||||
if c.closed {
|
|
||||||
log.Infoln("read udp obfs after")
|
|
||||||
}
|
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
c.readMutex.Unlock()
|
c.readMutex.Unlock()
|
||||||
return 0, addr, err
|
return 0, addr, err
|
||||||
|
@ -68,7 +60,6 @@ func (c *ObfsUDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ObfsUDPConn) Close() error {
|
func (c *ObfsUDPConn) Close() error {
|
||||||
c.closed = true
|
|
||||||
return c.orig.Close()
|
return c.orig.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ const udpBufferSize = 65535
|
||||||
type ObfsWeChatUDPConn struct {
|
type ObfsWeChatUDPConn struct {
|
||||||
orig net.PacketConn
|
orig net.PacketConn
|
||||||
obfs obfs.Obfuscator
|
obfs obfs.Obfuscator
|
||||||
closed bool
|
|
||||||
readBuf []byte
|
readBuf []byte
|
||||||
readMutex sync.Mutex
|
readMutex sync.Mutex
|
||||||
writeBuf []byte
|
writeBuf []byte
|
||||||
|
@ -37,13 +36,7 @@ func NewObfsWeChatUDPConn(orig net.PacketConn, obfs obfs.Obfuscator) *ObfsWeChat
|
||||||
func (c *ObfsWeChatUDPConn) ReadFrom(p []byte) (int, net.Addr, error) {
|
func (c *ObfsWeChatUDPConn) ReadFrom(p []byte) (int, net.Addr, error) {
|
||||||
for {
|
for {
|
||||||
c.readMutex.Lock()
|
c.readMutex.Lock()
|
||||||
if c.closed {
|
|
||||||
log.Infoln("read wechat obfs before")
|
|
||||||
}
|
|
||||||
n, addr, err := c.orig.ReadFrom(c.readBuf)
|
n, addr, err := c.orig.ReadFrom(c.readBuf)
|
||||||
if c.closed {
|
|
||||||
log.Infoln("read wechat obfs after")
|
|
||||||
}
|
|
||||||
if n <= 13 {
|
if n <= 13 {
|
||||||
c.readMutex.Unlock()
|
c.readMutex.Unlock()
|
||||||
return 0, addr, err
|
return 0, addr, err
|
||||||
|
@ -84,7 +77,6 @@ func (c *ObfsWeChatUDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ObfsWeChatUDPConn) Close() error {
|
func (c *ObfsWeChatUDPConn) Close() error {
|
||||||
c.closed = true
|
|
||||||
return c.orig.Close()
|
return c.orig.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClientTransport struct {
|
type ClientTransport struct {
|
||||||
Dialer *net.Dialer
|
Dialer *net.Dialer
|
||||||
PrefEnabled bool
|
|
||||||
PrefIPv6 bool
|
|
||||||
PrefExclusive bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *ClientTransport) quicPacketConn(proto string, server string, obfs obfs.Obfuscator, dialer PacketDialer) (net.PacketConn, error) {
|
func (ct *ClientTransport) quicPacketConn(proto string, server string, obfs obfs.Obfuscator, dialer PacketDialer) (net.PacketConn, error) {
|
||||||
|
|
Loading…
Reference in a new issue