trojan

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseHeader

func ParseHeader(reader io.Reader) (dst net.Destination, err error)

ParseHeader parses the trojan protocol header

Types

type Client

type Client struct {
	ClientSettings
}

Client is an inbound handler for trojan protocol

func NewClient

func NewClient(settings ClientSettings) *Client

NewClient create a new trojan client.

func (*Client) HandleFlow

func (c *Client) HandleFlow(ctx context.Context, dst net.Destination, rw buf.ReaderWriter) error

func (Client) HandlePacketConn

func (c Client) HandlePacketConn(ctx context.Context, dst net.Destination, pc udp.PacketReaderWriter) error

func (*Client) ListenPacket

func (c *Client) ListenPacket(ctx context.Context, dst net.Destination) (udp.UdpConn, error)

func (*Client) ProxyDial

func (c *Client) ProxyDial(ctx context.Context, dst net.Destination,
	initialData buf.MultiBuffer) (i.FlowConn, error)

type ClientSettings

type ClientSettings struct {
	Address    net.Address
	PortPicker i.PortSelector
	Account    *MemoryAccount
	Dialer     i.Dialer
	Vision     bool
}

type ConnWriter

type ConnWriter struct {
	io.Writer
	Target  net.Destination
	Account *MemoryAccount
	// contains filtered or unexported fields
}

ConnWriter is TCP Connection Writer Wrapper for trojan protocol

func (*ConnWriter) CloseWrite

func (c *ConnWriter) CloseWrite() error

func (*ConnWriter) OkayToUnwrapWriter

func (c *ConnWriter) OkayToUnwrapWriter() int

func (*ConnWriter) UnwrapWriter

func (c *ConnWriter) UnwrapWriter() any

func (*ConnWriter) Write

func (c *ConnWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

func (*ConnWriter) WriteHeader

func (c *ConnWriter) WriteHeader() error

func (*ConnWriter) WriteMultiBuffer

func (c *ConnWriter) WriteMultiBuffer(mb buf.MultiBuffer) error

WriteMultiBuffer implements buf.Writer

type MemoryAccount

type MemoryAccount struct {
	Uid      string
	Password []byte
	Key      []byte
}

MemoryAccount is an account type converted from Account.

func NewMemoryAccount

func NewMemoryAccount(u string, password string) *MemoryAccount

type PacketPayload

type PacketPayload struct {
	Target net.Destination
	Buffer buf.MultiBuffer
}

PacketPayload combines udp payload and destination

type PacketReader

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

PacketReader is UDP Connection Reader Wrapper for trojan protocol

func (*PacketReader) Read

func (r *PacketReader) Read(p []byte) (n int, err error)

func (*PacketReader) ReadMultiBuffer

func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error)

ReadMultiBuffer implements buf.Reader

func (*PacketReader) ReadPacket

func (r *PacketReader) ReadPacket() (*udp.Packet, error)

ReadMultiBufferWithMetadata reads udp packet with destination

type PacketWriter

type PacketWriter struct {
	Dest net.Destination
	// contains filtered or unexported fields
}

PacketWriter UDP Connection Writer Wrapper for trojan protocol

func (*PacketWriter) CloseWrite

func (w *PacketWriter) CloseWrite() error

func (*PacketWriter) Write

func (w *PacketWriter) Write(p []byte) (n int, err error)

func (*PacketWriter) WriteMultiBuffer

func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error

WriteMultiBuffer implements buf.Writer

func (*PacketWriter) WritePacket

func (w *PacketWriter) WritePacket(p *udp.Packet) error

WritePacket writes udp packet with destination specified

func (*PacketWriter) WriteTo

func (w *PacketWriter) WriteTo(payload []byte, addr gonet.Addr) (int, error)

type Validator

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

Validator stores valid trojan users.

func (*Validator) Add

func (v *Validator) Add(u *MemoryAccount)

Add a trojan user, Email must be empty or unique.

func (*Validator) Del

func (v *Validator) Del(uid string) error

Del a trojan user with a non-empty Email.

func (*Validator) Get

func (v *Validator) Get(hash string) *MemoryAccount

Get a trojan user with hashed key, nil if user doesn't exist.

Jump to

Keyboard shortcuts

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