mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-10-10 11:10:20 +08:00

创建新子包netLayer, 将 proxy.Addr改为 netLayer.Addr 修订文档 RoutePolicy等分流机制也放到 netLayer 引入github.com/oschwald/maxminddb-golang 依赖,支持使用 GeoLite2-Country.mmdb 来进行ip分流 另外注意它默认的版本对于 golang.org/x/sys 包的依赖太老了,会导致go1.18中编译不通过,我在 go.mod 文件中新增了下面代码,就能通过编译了 ``` require ( golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 // indirect ) ``` verysimple的可执行文件的相同目录下,必须有该mmdb文件才能够开启ip分流功能 新配置方式:配置文件新加一行 "route":{ "mycountry":"CN" } mycountry指定的国家的ip会被直连发送,其他地址ip会被发送到代理. 新配置方式,回落,直接在 local 项的 url 的 query部分添加 fallback=:80, 或者 fallback=127.0.0.1:80 即可 回落到指定端口. 将tls_test重新挪动到tlsLayer包中 在main.go中添加了 logLevel变量,并且把关于配置文件的部分挪动到 config.go 出了上面的分流和回落以外,还新增支持了 #xxx 的尾缀,用于配置该url的tag. tag在未来会被用于精准分流 Makefile中新增了 PACK 参数用于编译出 打包版的发行包;可选 tag=embed_geoip 参数用于将mmdb.tgz文件内置到可执行程序里 同时,我开始直接使用go1.18编译本项目,期待性能提升,因为这是新发布的版本,看了介绍据说对 mac m1有20%的提升.
49 lines
845 B
Go
49 lines
845 B
Go
package tlsLayer
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
|
|
"github.com/hahahrfool/v2ray_simple/common"
|
|
)
|
|
|
|
type Server struct {
|
|
addr string
|
|
tlsConfig *tls.Config
|
|
}
|
|
|
|
func NewServer(hostAndPort, host, certFile, keyFile string, isInsecure bool) (*Server, error) {
|
|
|
|
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s := &Server{
|
|
addr: hostAndPort,
|
|
tlsConfig: &tls.Config{
|
|
InsecureSkipVerify: isInsecure,
|
|
ServerName: host,
|
|
Certificates: []tls.Certificate{cert},
|
|
},
|
|
}
|
|
|
|
return s, nil
|
|
}
|
|
|
|
func (s *Server) Handshake(underlay net.Conn) (tlsConn *Conn, err error) {
|
|
rawTlsConn := tls.Server(underlay, s.tlsConfig)
|
|
err = rawTlsConn.Handshake()
|
|
if err != nil {
|
|
err = common.NewErr("tlsLayer: tls握手失败", err)
|
|
|
|
return
|
|
}
|
|
|
|
tlsConn = &Conn{
|
|
Conn: rawTlsConn,
|
|
}
|
|
|
|
return
|
|
|
|
}
|