simplesocks

package
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package simplesocks implements SimpleSocks (defined by trojan-go) protocol for proxy.Server and proxy.Client.

See https://p4gefau1t.github.io/trojan-go/developer/simplesocks/

Index

Constants

View Source
const (
	// trojan-go 的代码里,这里依然叫做connect和associate,而实际上,因为通道已经建立,所以实际含义已经不同
	// 这些命令只用于指示承载数据的传输层协议,所以我们这里重命名一下。
	CmdTCP = 0x01
	CmdUDP = 0x03

	ATypIP4    = 0x1
	ATypDomain = 0x3
	ATypIP6    = 0x4

	Name = "simplesocks"
)

Variables

This section is empty.

Functions

func GetAddrFrom

func GetAddrFrom(buf utils.ByteReader) (addr netLayer.Addr, err error)

依照trojan协议的格式读取 地址的域名、ip、port信息

func WriteAddrToBuf

func WriteAddrToBuf(target netLayer.Addr, buf *bytes.Buffer)

Types

type Client

type Client struct {
	proxy.Base
}

func (*Client) EstablishUDPChannel

func (c *Client) EstablishUDPChannel(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (netLayer.MsgConn, error)

func (*Client) GetCreator added in v1.2.4

func (*Client) GetCreator() proxy.ClientCreator

func (*Client) Handshake

func (c *Client) Handshake(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (io.ReadWriteCloser, error)

func (*Client) Name

func (c *Client) Name() string

type ClientCreator

type ClientCreator struct{ proxy.CreatorCommonStruct }

func (ClientCreator) NewClient

func (ClientCreator) NewClient(dc *proxy.DialConf) (proxy.Client, error)

func (ClientCreator) URLToDialConf added in v1.2.4

func (ClientCreator) URLToDialConf(u *url.URL, dc *proxy.DialConf, format int) (*proxy.DialConf, error)

type Server

type Server struct {
	proxy.Base
}

implements proxy.Server

func (*Server) CanFallback added in v1.2.1

func (*Server) CanFallback() bool

func (*Server) Handshake

func (s *Server) Handshake(underlay net.Conn) (result net.Conn, msgConn netLayer.MsgConn, targetAddr netLayer.Addr, returnErr error)

若握手步骤数据不对, 会返回 ErrDetail 为 utils.ErrInvalidData 的 utils.ErrInErr

func (*Server) Name

func (*Server) Name() string

type ServerCreator

type ServerCreator struct{ proxy.CreatorCommonStruct }

func (ServerCreator) NewServer

func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error)

func (ServerCreator) URLToListenConf added in v1.2.4

func (ServerCreator) URLToListenConf(u *url.URL, lc *proxy.ListenConf, format int) (*proxy.ListenConf, error)

type TCPConn

type TCPConn struct {
	net.Conn
	// contains filtered or unexported fields
}

实现 utils.User, utils.UserAssigner

func (*TCPConn) AuthBytes added in v1.2.5

func (c *TCPConn) AuthBytes() []byte

func (*TCPConn) AuthStr added in v1.2.5

func (c *TCPConn) AuthStr() string

func (*TCPConn) CanSpliceRead added in v1.2.5

func (c *TCPConn) CanSpliceRead() (bool, *net.TCPConn, *net.UnixConn)

func (*TCPConn) CanSpliceWrite added in v1.2.5

func (c *TCPConn) CanSpliceWrite() (r bool, conn *net.TCPConn)

func (*TCPConn) EverPossibleToSpliceRead added in v1.2.5

func (c *TCPConn) EverPossibleToSpliceRead() bool

当底层链接可以暴露为 tcp或 unix链接时,返回true

func (*TCPConn) EverPossibleToSpliceWrite added in v1.2.5

func (c *TCPConn) EverPossibleToSpliceWrite() bool

func (*TCPConn) IdentityBytes added in v1.2.5

func (c *TCPConn) IdentityBytes() []byte

func (*TCPConn) IdentityStr added in v1.2.5

func (c *TCPConn) IdentityStr() string

func (*TCPConn) Read

func (c *TCPConn) Read(p []byte) (int, error)

func (*TCPConn) ReadFrom

func (c *TCPConn) ReadFrom(r io.Reader) (written int64, err error)

func (*TCPConn) SetUser added in v1.2.5

func (c *TCPConn) SetUser(u utils.User)

实现 utils.UserAssigner

func (*TCPConn) Upstream added in v1.2.5

func (c *TCPConn) Upstream() net.Conn

func (*TCPConn) Write

func (c *TCPConn) Write(p []byte) (int, error)

func (*TCPConn) WriteBuffers

func (c *TCPConn) WriteBuffers(buffers [][]byte) (int64, error)

type UDPConn

type UDPConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewUDPConn

func NewUDPConn(conn net.Conn, optionalReader io.Reader) (uc *UDPConn)

func (*UDPConn) AuthBytes added in v1.2.5

func (c *UDPConn) AuthBytes() []byte

func (*UDPConn) AuthStr added in v1.2.5

func (c *UDPConn) AuthStr() string

func (*UDPConn) CloseConnWithRaddr

func (u *UDPConn) CloseConnWithRaddr(raddr netLayer.Addr) error

func (*UDPConn) Fullcone

func (u *UDPConn) Fullcone() bool

func (*UDPConn) IdentityBytes added in v1.2.5

func (c *UDPConn) IdentityBytes() []byte

func (*UDPConn) IdentityStr added in v1.2.5

func (c *UDPConn) IdentityStr() string

func (*UDPConn) ReadMsg added in v1.2.5

func (u *UDPConn) ReadMsg() ([]byte, netLayer.Addr, error)

func (*UDPConn) SetUser added in v1.2.5

func (c *UDPConn) SetUser(u utils.User)

func (*UDPConn) WriteMsg added in v1.2.5

func (u *UDPConn) WriteMsg(bs []byte, addr netLayer.Addr) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL