trojan

package module
v0.0.0-...-0ef2e5b Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: GPL-2.0, GPL-3.0, LGPL-3.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Caddy Module of Trojan-GFW/GO

{
  "apps": {
        "http": {
            "http_port": 80,
            "https_port": 443,
            "servers": {
                "example": {
                    "listen": [":443"],
                    "routes": [{
                        "match": [{
                            "host": ["exmaple.cc"]
                        }],
                        "handle": [
                            {
                                "handler": "trojan",
                                "admin": ["/admin"],
                                "method": "CHACHA20-IETF-POLY1305",
                                "password": "passwrod",
                                "users": [{
                                    "method": "CHACHA20-IETF-POLY1305",
                                    "password": "password",
                                    "path": "/user1"
                                }]
                            }
                        ]
                    }]
                }
            }
        },
        "tls": {
        }
    }
}

Documentation

Index

Constants

View Source
const (
	AddrTypeIPv4   = 1
	AddrTypeDomain = 3
	AddrTypeIPv6   = 4
)
View Source
const (
	HexLen        = 56
	MaxBufferSize = 1024 * 32
)
View Source
const (
	Connect   = 1
	Assocaite = 3
	SMUX      = 0x7f
)
View Source
const MaxAddrLen = 1 + 1 + 255 + 2

Variables

View Source
var (
	ErrNoQuota   = fmt.Errorf("no quota")
	ErrNotTrojan = fmt.Errorf("not trojan connection")
)
View Source
var ErrInvalidAddrType = errors.New("invalid address type")

Functions

func Check

func Check(conn net.Conn, user *User) (err error)

func Copy2

func Copy2(conn net.Conn, rc net.PacketConn, timeout time.Duration, ch chan data)

func Handle

func Handle(conn net.Conn, user *User) error

func HandleConn

func HandleConn(conn net.Conn, user *User) (err error)

func HandleMux

func HandleMux(conn net.Conn, user *User) (err error)

func HandleStream

func HandleStream(conn net.Conn, user *User) (err error)

func HandleTCP

func HandleTCP(conn net.Conn, addr string) (n1 int64, n2 int64, err error)

func HandleUDP

func HandleUDP(conn net.Conn) (int64, int64, error)

func ResolveUDPAddr

func ResolveUDPAddr(addr Addr) (*net.UDPAddr, error)

Types

type Addr

type Addr []byte

func ReadAddr

func ReadAddr(conn net.Conn) (Addr, error)

func ReadAddrBuffer

func ReadAddrBuffer(conn net.Conn, addr []byte) (Addr, error)

func ResolveAddr

func ResolveAddr(addr net.Addr) (Addr, error)

func ResolveAddrBuffer

func ResolveAddrBuffer(addr net.Addr, b []byte) (Addr, error)

func (Addr) Network

func (addr Addr) Network() string

func (Addr) String

func (addr Addr) String() string

type Middleware

type Middleware struct {
	// information about trojan users
	Admin    []string `json:"admin"`
	Method   string   `json:"method,omitempty"`
	Password string   `json:"password"`
	Users    []*User  `json:"users"`

	*zap.Logger
	Upgrader *websocket.Upgrader
	Server   http.Server
	Cipher   core.Cipher
	// contains filtered or unexported fields
}

Middleware implements an HTTP handler that ...

func (Middleware) CaddyModule

func (Middleware) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*Middleware) Cleanup

func (m *Middleware) Cleanup() error

Cleanup implements caddy.CleanerUpper.

func (Middleware) HandleAdmin

func (m Middleware) HandleAdmin(w http.ResponseWriter, r *http.Request) error

Admin implements http.HandlerFunc.

func (*Middleware) Provision

func (m *Middleware) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (Middleware) ServeHTTP

func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*Middleware) Validate

func (m *Middleware) Validate() error

Validate implements caddy.Validator.

type Reader

type Reader struct{}

func (Reader) Read

func (Reader) Read(b []byte) (int, error)

type User

type User struct {
	Method   string `json:"method,omitempty"`
	Password string `json:"password"`
	Path     string `json:"path"`

	*zap.Logger
	sync.RWMutex
	core.Cipher
	Header [HexLen + 2]byte
	Conns  map[net.Conn]struct{}
	Quota  uint64
	Up     uint64
	Down   uint64
}

func (*User) Consume

func (user *User) Consume(nr, nw int64)

func (*User) Delete

func (user *User) Delete(conn net.Conn)

func (*User) Destroy

func (user *User) Destroy()

func (*User) Range

func (user *User) Range() chan net.Conn

func (*User) Store

func (user *User) Store(conn net.Conn)

type Users

type Users struct {
	*zap.Logger
	sync.RWMutex
	core.Cipher
	Map map[string]*User
}

func (*Users) Delete

func (users *Users) Delete(key string)

func (*Users) Destroy

func (users *Users) Destroy()

func (*Users) HandleAdmin

func (users *Users) HandleAdmin(w http.ResponseWriter, r *http.Request)

func (*Users) Load

func (users *Users) Load(key string) (user *User, ok bool)

func (*Users) Range

func (users *Users) Range() chan *User

func (*Users) Store

func (users *Users) Store(key string, user *User)

func (*Users) UserNum

func (users *Users) UserNum() int

type WebConn

type WebConn struct {
	*websocket.Conn
	Reader io.Reader
}

func NewWebConn

func NewWebConn(conn *websocket.Conn) *WebConn

func (*WebConn) Close

func (conn *WebConn) Close() (err error)

func (*WebConn) Read

func (conn *WebConn) Read(b []byte) (int, error)

func (*WebConn) SetDeadline

func (conn *WebConn) SetDeadline(t time.Time) error

func (*WebConn) Write

func (conn *WebConn) Write(b []byte) (int, error)

Directories

Path Synopsis
Package main is the entry point of the Caddy application.
Package main is the entry point of the Caddy application.

Jump to

Keyboard shortcuts

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