woow

package module
v0.0.0-...-6f5f5d2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2020 License: MIT Imports: 17 Imported by: 0

README

说明

高并发的代理服务,采用go语言开发,同时支持http/https/socks5。且只需要监听一个端口,可以自动识别并正确代理。 取名woow看起来像一头猪。

使用

1.编译

go get gopkg.in/natefinch/lumberjack.v2
go get github.com/woodada/ioutil
go get github.com/woodada/woow
cd github.com/woodada/woow/cmd/woow
go build -ldflags "-w -s" -o woow

2.查看版本号

proxy -version or proxy --version or proxy --v or proxy -v

3.生成ssl证书自签发

proxy --gencert or proxy -gencert

4.查看配置

proxy --config or proxy -config or proxy --c or proxy -c

导出默认配置
proxy --config > xxx.ini

默认配置如下

# woow config file

[server]
# 代理服务监听地址
listen_addr=:12345

# 日志路径 路径为空默认不打印日志
log_path=/tmp/woow.log

# 连接建立后第一批读超时时间 单位秒
pre_read_timeout = 3

# 是否启用https_proxy 可以改为真实有效的签发证书
ssl_enabled=true
ssl_key="./gencert.key"
ssl_cert="./gencert.cert"

[admin]
# 内置管理页面监听地址
listen_addr=127.0.0.1:54321

[tunnel]
# 空闲时间 单位秒 
timeout= 600

# 鉴权配置 无任何账号配置即可免Auth代理
# 已知在Mac下即使配置了代理的账号密码,但是实际浏览器请求也是不带鉴权的。将[accounts]下配置为空,即可关闭代理服务的鉴权。
[accounts]
woo=123456
lucy=123456

5.运行

proxy xxx.ini

6.测试

curl -k -v -x 'http://woo:123456@127.0.0.1:12345' https://www.baidu.com
curl -k -v -x 'socks5://woo:123456@127.0.0.1:12345' https://www.baidu.com
curl -k  --proxy-insecure -v -x 'https://woo:123456@127.0.0.1:12345' https://www.baidu.com

只需要一个端口,同时支持http socks5 https 三种代理; 使用https代理时加上--proxy-insecure选项,这是因为这是自己签发的证书。

7.管理页面

http://127.0.0.1:54321//debug/pprof/
http://127.0.0.1:54321/status

开发

采用模块开发,在代码中Run一个Server即可,Server间独立,可以启动多个。

type Config struct {
    Logger         smartnet.Logger // 日志对象 默认不打印日志
    Accounts       *AccountStore   // 账号存储 线程安全 可运行用增删改账号信息
    SSLEnabled     bool            // 启用https代理
    SSLKey         string          // key 
    SSLCert        string          // cert
    PreReadTimeout time.Duration   // 第一批字节读取超时时间
    TunnelTimeout  time.Duration   // 隧道空闲断开时间
    KeepAlive      time.Duration   // TCP keep alive
    ListenAddress  string          // 服务监听地址
}

s := woow.NewServer(cfg)
s.Run()

Documentation

Index

Constants

View Source
const (
	// client to server
	SOCKS5_IPV4             = 0x01
	SOCKS5_DOMAIN_NAME      = 0x03
	SOCKS5_IPV6             = 0x04
	SOCKS5_CONNECT_METHOD   = 0x01
	SOCKS5_BIND_METHOD      = 0x02
	SOCKS5_ASSOCIATE_METHOD = 0x03
	// The maximum packet size of any udp Associate packet, based on ethernet's max size,
	// minus the IP and UDP headers. IPv4 has a 20 byte header, UDP adds an
	// additional 4 bytes.  This is a total overhead of 24 bytes.  Ethernet's
	// max packet size is 1500 bytes,  1500 - 24 = 1476.
	SOCKS5_MAX_UDP_PACKET_SIZE = 1476
	// server to client
	SOCKS5_NO_NEED_AUTH      = 0x00
	SOCKS5_USER_PASS_AUTH    = 0x02
	SOCKS5_USER_AUTH_VERSION = 0x01
	SOCKS5_AUTH_SUCCESS      = 0x00
	SOCKS5_AUTH_FAILURE      = 0x01

	SOCKS5_VERSION                    = 0x05
	SOCKS5_CONNECT_SUCC               = 0x00
	SOCKS5_NETWORK_UNREACHABLE        = 0x03
	SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED = 0x08 // Address type not supported

)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountStore

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

线程安全的账号/密码

func NewAccountStore

func NewAccountStore(accts map[string]string) *AccountStore

func (*AccountStore) Compare

func (this *AccountStore) Compare(username, passwd string) int

0-成功 1-用户不存在 2-密码错误

func (AccountStore) Lock

func (this AccountStore) Lock()

func (*AccountStore) Size

func (this *AccountStore) Size() int

func (AccountStore) Unlock

func (this AccountStore) Unlock()

func (*AccountStore) Upsert

func (this *AccountStore) Upsert(username, passwd string)

type Config

type Config struct {
	Logger         smartnet.Logger
	Accounts       *AccountStore
	SSLEnabled     bool
	SSLKey         string
	SSLCert        string
	PreReadTimeout time.Duration
	TunnelTimeout  time.Duration
	KeepAlive      time.Duration
	ListenAddress  string
}

type ProxyFunc

type ProxyFunc func(conn net.Conn, callback smartnet.StopCallBackFunc)

callback写法有点丑 但能有效减少协程数 FIXME 用hub+channel方式 避免跨线程调用风险

type Server

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

func NewServer

func NewServer(c Config) *Server

func (*Server) Connections

func (this *Server) Connections() int64

func (*Server) Run

func (this *Server) Run() error

func (*Server) Runables

func (this *Server) Runables() int64

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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