add socks5 udp relay

This commit is contained in:
ginuerzh
2021-11-07 23:39:35 +08:00
parent e8f040cbdf
commit 16f34d3e94
39 changed files with 728 additions and 131 deletions

View File

@ -1,4 +1,4 @@
package utils
package kcp
import (
"net"

View File

@ -0,0 +1,75 @@
package mux
import (
"net"
smux "github.com/xtaci/smux"
)
type MuxSession struct {
conn net.Conn
session *smux.Session
}
func NewMuxSession(conn net.Conn) (*MuxSession, error) {
// Upgrade connection to multiplex stream.
s, err := smux.Client(conn, smux.DefaultConfig())
if err != nil {
return nil, err
}
return &MuxSession{
conn: conn,
session: s,
}, nil
}
func (session *MuxSession) GetConn() (net.Conn, error) {
stream, err := session.session.OpenStream()
if err != nil {
return nil, err
}
return &muxStreamConn{Conn: session.conn, stream: stream}, nil
}
func (session *MuxSession) Accept() (net.Conn, error) {
stream, err := session.session.AcceptStream()
if err != nil {
return nil, err
}
return &muxStreamConn{Conn: session.conn, stream: stream}, nil
}
func (session *MuxSession) Close() error {
if session.session == nil {
return nil
}
return session.session.Close()
}
func (session *MuxSession) IsClosed() bool {
if session.session == nil {
return true
}
return session.session.IsClosed()
}
func (session *MuxSession) NumStreams() int {
return session.session.NumStreams()
}
type muxStreamConn struct {
net.Conn
stream *smux.Stream
}
func (c *muxStreamConn) Read(b []byte) (n int, err error) {
return c.stream.Read(b)
}
func (c *muxStreamConn) Write(b []byte) (n int, err error) {
return c.stream.Write(b)
}
func (c *muxStreamConn) Close() error {
return c.stream.Close()
}

View File

@ -1,4 +1,4 @@
package utils
package quic
import (
"crypto/aes"

View File

@ -0,0 +1,18 @@
package socks
const (
// MethodTLS is an extended SOCKS5 method with tls encryption support.
MethodTLS uint8 = 0x80
// MethodTLSAuth is an extended SOCKS5 method with tls encryption and authentication support.
MethodTLSAuth uint8 = 0x82
// MethodMux is an extended SOCKS5 method for stream multiplexing.
MethodMux = 0x88
)
const (
// CmdMuxBind is an extended SOCKS5 request CMD for
// multiplexing transport with the binding server.
CmdMuxBind uint8 = 0xF2
// CmdUDPTun is an extended SOCKS5 request CMD for UDP over TCP.
CmdUDPTun uint8 = 0xF3
)

View File

@ -1,4 +1,4 @@
package utils
package ss
import (
"bytes"

View File

@ -1,4 +1,4 @@
package utils
package tls
import (
"crypto/tls"

View File

@ -1,4 +1,4 @@
package utils
package ws
import (
"net"