Skip to content

Commit

Permalink
add udp config support
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Aug 29, 2023
1 parent 14214e7 commit 83b8cdd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
12 changes: 8 additions & 4 deletions cmd/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ type Config struct {
EnableDNSFragmentation bool `mapstructure:"EnableDNSFragmentation"`
RemoteDNSAddr string `mapstructure:"RemoteDNSAddr"`
BindAddress string `mapstructure:"BindAddress"`
UDPBindAddress string `mapstructure:"UDPBindAddress"`
ChunksLengthBeforeSni [2]int `mapstructure:"ChunksLengthBeforeSni"`
UDPReadTimeout int `mapstructure:"UDPReadTimeout"`
UDPWriteTimeout int `mapstructure:"UDPWriteTimeout"`
UDPLinkIdleTimeout int64 `mapstructure:"UDPLinkIdleTimeout"`
SniChunksLength [2]int `mapstructure:"SniChunksLength"`
ChunksLengthAfterSni [2]int `mapstructure:"ChunksLengthAfterSni"`
DelayBetweenChunks [2]int `mapstructure:"DelayBetweenChunks"`
Expand Down Expand Up @@ -72,9 +76,9 @@ func RunServer(config *Config, captureCTRLC bool) error {
BindAddress: config.BindAddress,
Dialer: dialer_,
Logger: appLogger,
ReadTimeout: 300,
WriteTimeout: 300,
LinkIdleTimeout: 300,
ReadTimeout: config.UDPReadTimeout,
WriteTimeout: config.UDPWriteTimeout,
LinkIdleTimeout: config.UDPLinkIdleTimeout,
EstablishedTunnels: make(map[string]*transport.EstablishedTunnel),
ShortClientID: utils.ShortID(6),
}
Expand All @@ -85,7 +89,7 @@ func RunServer(config *Config, captureCTRLC bool) error {
Logger: appLogger,
Dialer: dialer_,
BufferPool: bufferpool.NewPool(32 * 1024),
UDPBind: "20.1.1.18:0",
UDPBind: config.UDPBindAddress,
Tunnel: wsTunnel,
}

Expand Down
33 changes: 26 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
{
"TLSHeaderLength": 5,
"TLSPaddingEnabled": false,
"TLSPaddingSize": [40, 80],
"TLSPaddingSize": [
40,
80
],
"RemoteDNSAddr": "https://yarp.lefolgoc.net/dns-query",
"EnableDNSFragmentation": false,
"DnsCacheTTL": 3000000,
"DnsRequestTimeout": 10,
"BindAddress": "0.0.0.0:8085",
"ChunksLengthBeforeSni": [2000, 2000],
"SniChunksLength": [5, 10],
"ChunksLengthAfterSni": [2000, 2000],
"DelayBetweenChunks": [10, 20],
"WorkerAddress": "https://uoosef-worker.uoosef.workers.dev/dns-query",
"ChunksLengthBeforeSni": [
2000,
2000
],
"SniChunksLength": [
5,
10
],
"ChunksLengthAfterSni": [
2000,
2000
],
"DelayBetweenChunks": [
10,
20
],
"WorkerAddress": "https://<your_worker>.workers.dev/dns-query",
"WorkerIPPortAddress": "104.17.196.93:2096",
"WorkerEnabled": true,
"WorkerDNSOnly": false,
Expand All @@ -21,5 +36,9 @@
"Domain": "yarp.lefolgoc.net",
"IP": "5.39.88.20"
}
]
],
"UDPBindAddress": "0.0.0.0",
"UDPReadTimeout": 120,
"UDPWriteTimeout": 120,
"UDPLinkIdleTimeout": 120
}
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (s *Server) resolveDestination(ctx context.Context, req *socks5.Request) (s
// sendChunks sends chunks from bepass to dst
func (s *Server) sendChunks(dst io.Writer, src io.Reader, shouldSplit bool, wg *sync.WaitGroup) {
defer wg.Done()
dataBuffer := make([]byte, 256*1024)
dataBuffer := make([]byte, 32*1024)

for index := 0; ; index++ {
bytesRead, err := src.Read(dataBuffer)
Expand Down
4 changes: 2 additions & 2 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ func (t *Transport) Handle(network string, w io.Writer, req *socks5.Request) err
}

func (t *Transport) Copy(reader io.Reader, writer io.Writer) error {
buf := make([]byte, 256*1024)
buf := make([]byte, 32*1024)

_, err := io.CopyBuffer(writer, reader, buf[:cap(buf)])
return err
}

func (t *Transport) TunnelUDP(w io.Writer, req *socks5.Request) error {
udpAddr, err := net.ResolveUDPAddr("udp", "192.168.12.2:0")
udpAddr, err := net.ResolveUDPAddr("udp", t.UDPBind+":0")
// connect to remote server via ws
bindLn, err := net.ListenUDP("udp", udpAddr)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion transport/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (w *WSTunnel) PersistentDial(tunnelEndpoint string, bindWriteChannel chan U
//1- unpack the message
//2- find the channel that message should write on
//3- write the message on that channel
rawPacket := make([]byte, 256*1024)
rawPacket := make([]byte, 32*1024)
n, err := conn.Read(rawPacket)
if n < 2 && err == nil {
continue
Expand Down

0 comments on commit 83b8cdd

Please sign in to comment.