add socks5 udp relay
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package kcp
|
||||
|
||||
import (
|
||||
"net"
|
75
pkg/internal/utils/mux/mux.go
Normal file
75
pkg/internal/utils/mux/mux.go
Normal 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()
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package quic
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
18
pkg/internal/utils/socks/socks.go
Normal file
18
pkg/internal/utils/socks/socks.go
Normal 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
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package ss
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package tls
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package ws
|
||||
|
||||
import (
|
||||
"net"
|
Reference in New Issue
Block a user