trojan

package
v1.1.9-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

package trojan implements proxy.Client and proxy.Server with trojan protocol.

See https://trojan-gfw.github.io/trojan/protocol .

Index

Constants

View Source
const (
	ATypIP4    = 0x1
	ATypDomain = 0x3
	ATypIP6    = 0x4
	Name       = "trojan"
)
View Source
const (
	CmdConnect      = 0x01
	CmdUDPAssociate = 0x03
	CmdMux          = 0x7f //trojan-gfw 那个文档里并没有提及Mux, 这个定义作者似乎没有在任何文档中提及,所以这个是在trojan-go的源代码文件中找到的。
)

Variables

This section is empty.

Functions

func GetAddrFrom

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

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

func SHA224

func SHA224(password string) (r [28]byte)

func SHA224_hexString

func SHA224_hexString(password string) string

func SHA224_hexStringBytes

func SHA224_hexStringBytes(password string) []byte

trojan 的前56字节 是 sha224的28字节 每字节 转义成 ascii的 表示16进制的 两个字符

func WriteAddrToBuf

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

Types

type Client

type Client struct {
	proxy.ProxyCommonStruct
	// contains filtered or unexported fields
}

func (*Client) EstablishUDPChannel

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

func (*Client) Handshake

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

func (*Client) HasInnerMux

func (c *Client) HasInnerMux() (int, string)

func (*Client) Name

func (*Client) Name() string

type ClientCreator

type ClientCreator struct{}

func (ClientCreator) NewClient

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

func (ClientCreator) NewClientFromURL

func (ClientCreator) NewClientFromURL(url *url.URL) (proxy.Client, error)

type Server

type Server struct {
	proxy.ProxyCommonStruct
	// contains filtered or unexported fields
}

implements proxy.Server

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) HasInnerMux

func (*Server) HasInnerMux() (int, string)

func (*Server) Name

func (*Server) Name() string

type ServerCreator

type ServerCreator struct{}

func (ServerCreator) NewServer

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

func (ServerCreator) NewServerFromURL

func (ServerCreator) NewServerFromURL(url *url.URL) (proxy.Server, 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) CloseConnWithRaddr

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

func (UDPConn) Fullcone

func (u UDPConn) Fullcone() bool

func (UDPConn) ReadMsgFrom

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

func (*UDPConn) WriteMsgTo

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

type UserTCPConn

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

trojan比较简洁,这个 UserTCPConn 只是用于读取握手读取时读到的剩余的缓存

func (*UserTCPConn) CanSplice

func (c *UserTCPConn) CanSplice() (r bool, conn net.Conn)

func (*UserTCPConn) EverPossibleToSplice

func (c *UserTCPConn) EverPossibleToSplice() bool

func (*UserTCPConn) Read

func (uc *UserTCPConn) Read(p []byte) (int, error)

func (*UserTCPConn) ReadFrom

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

func (*UserTCPConn) Write

func (uc *UserTCPConn) Write(p []byte) (int, error)

func (*UserTCPConn) WriteBuffers

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

Jump to

Keyboard shortcuts

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