trojan

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: 12 Imported by: 0

Documentation

Overview

Package trojan implements trojan protocol for proxy.Client and proxy.Server.

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

Index

Constants

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

Variables

This section is empty.

Functions

func GetAddrFrom

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

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

func InitUsers added in v1.2.2

func InitUsers(uc []utils.UserConf) (us []utils.User)

func PassBytesToStr added in v1.2.2

func PassBytesToStr(bs []byte) string

28字节数据转56字节字符串

func PassStrToBytes added in v1.2.2

func PassStrToBytes(str string) []byte

56字节数据转28字节字符串

func SHA224

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

即trojan 的 任意长度密码 的 定长二进制表示。

func SHA224_hexString

func SHA224_hexString(password string) string

func SHA224_hexStringBytes

func SHA224_hexStringBytes(password string) []byte

trojan协议 的前56字节 是 sha224的28字节 每字节 转义成 base 16, with lower-case letters for a-f 的 两个字符。 实际上trojan协议文档写的不严谨,它只说了用hex,没说用大写还是小写。我看它代码实现用的是小写。

func WriteAddrToBuf

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

Types

type Client

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

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) GetUser added in v1.2.2

func (c *Client) GetUser() utils.User

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{ 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(url *url.URL, dc *proxy.DialConf, format int) (*proxy.DialConf, error)

type Server

type Server struct {
	proxy.Base

	*utils.MultiUserMap
}

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

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

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(url *url.URL, lc *proxy.ListenConf, format int) (*proxy.ListenConf, error)

type UDPConn

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

func NewUDPConn

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

func (*UDPConn) CloseConnWithRaddr

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

func (*UDPConn) Fullcone

func (u *UDPConn) Fullcone() bool

func (*UDPConn) ReadMsg added in v1.2.5

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

func (*UDPConn) WriteMsg added in v1.2.5

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

type User added in v1.2.2

type User struct {
	// contains filtered or unexported fields
}

func NewUserByPlainTextPassword added in v1.2.2

func NewUserByPlainTextPassword(plainPass string) User

func (User) AuthBytes added in v1.2.3

func (u User) AuthBytes() []byte

28字节纯二进制

func (User) AuthStr added in v1.2.3

func (u User) AuthStr() string

56字节hex

func (User) IdentityBytes added in v1.2.3

func (u User) IdentityBytes() []byte

明文密码

func (User) IdentityStr added in v1.2.3

func (u User) IdentityStr() string

明文密码

type UserTCPConn

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

trojan比较简洁,这个 UserTCPConn 只是用于读取握手读取时读到的剩余的缓存。 实现 net.Conn, io.ReaderFrom, utils.User, utils.MultiWriter, netLayer.Splicer, netLayer.ConnWrapper

func (*UserTCPConn) CanSpliceRead added in v1.2.5

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

func (*UserTCPConn) CanSpliceWrite added in v1.2.5

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

func (*UserTCPConn) EverPossibleToSpliceRead added in v1.2.5

func (c *UserTCPConn) EverPossibleToSpliceRead() bool

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

func (*UserTCPConn) EverPossibleToSpliceWrite added in v1.2.5

func (c *UserTCPConn) EverPossibleToSpliceWrite() bool

func (*UserTCPConn) Read

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

func (*UserTCPConn) ReadFrom

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

func (*UserTCPConn) Upstream added in v1.2.5

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

func (*UserTCPConn) Write

func (c *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