Documentation ¶
Overview ¶
Package grpcSimple implements grpc tunnel without importing google.golang.org/grpc.
Reference ¶
https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md
https://github.com/Dreamacro/clash/blob/master/transport/gun/gun.go, which is under MIT license
我们可以通过 grpc的文档 以及clash的 gun.go的代码看到,grpc实际上是 基于包的,而不是基于流的,与ws类似。
本包 在 clash的客户端实现 的 基础上 继续用 golang的 http2包 实现了 grpc 的 基本服务端,并改进了 原代码。
Advantages ¶
grpcSimple包 比grpc包 小很多,替代grpc包的话,可以减小 4MB 左右的可执行文件大小。但是目前不支持 multiMode。
grpcSimple包 是很棒 很有用的 实现,而且支持 grpc的 path 的回落。
grpc虽然是定义 serviceName的,但是实际上和其他http请求一样,是用的一个path,
path就是 /serviceName/Tun 之所以叫Tun,只不过是为了兼容xray/v2ray,技术上叫啥都行
Fallback ¶
grpcSimple can fallback to h2c.
about h2c
https://pkg.go.dev/golang.org/x/net/http2/h2c#example-NewHandler
https://github.com/thrawn01/h2c-golang-example
test h2c fallback:
curl -k -v --http2-prior-knowledge https://localhost:4434/sfd curl -k -v --http2-prior-knowledge -X POST -F 'asdf=1234' https://localhost:4434/sfd
test http1.1 fallback:
curl -v --http1.1 -k https://localhost:4434/sfd
Index ¶
- type Client
- type ClientConn
- type Config
- type Creator
- func (Creator) CanHandleHeaders() bool
- func (Creator) GetDefaultAlpn() (alpn string, mustUse bool)
- func (Creator) IsMux() bool
- func (Creator) IsSuper() bool
- func (Creator) NewClientFromConf(conf *advLayer.Conf) (advLayer.Client, error)
- func (Creator) NewServerFromConf(conf *advLayer.Conf) (advLayer.Server, error)
- func (Creator) PackageID() string
- func (Creator) ProtocolName() string
- type Server
- type ServerConn
- func (sc *ServerConn) Close() error
- func (*ServerConn) HasOwnDefaultRejectBehavior() bool
- func (c *ServerConn) LocalAddr() net.Addr
- func (c *ServerConn) Read(b []byte) (n int, err error)
- func (sc *ServerConn) Reject()
- func (c *ServerConn) RemoteAddr() net.Addr
- func (sc *ServerConn) Write(b []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
implements net.Conn
func (*ClientConn) Close ¶
func (c *ClientConn) Close() error
func (*ClientConn) HasOwnDefaultRejectBehavior ¶ added in v1.2.4
func (*ClientConn) HasOwnDefaultRejectBehavior() bool
implements netLayer.RejectConn, return true
func (*ClientConn) RemoteAddr ¶
type Creator ¶
type Creator struct{}
func (Creator) CanHandleHeaders ¶ added in v1.2.0
func (Creator) GetDefaultAlpn ¶
func (Creator) NewClientFromConf ¶
func (Creator) NewServerFromConf ¶
func (Creator) ProtocolName ¶ added in v1.2.0
type Server ¶
type Server struct { Creator Config http2.Server netLayer.ConnList Headers *httpLayer.HeaderPreset // contains filtered or unexported fields }
implements advLayer.MuxServer
func (*Server) StartHandle ¶
func (s *Server) StartHandle(underlay net.Conn, newSubConnFunc func(net.Conn), fallbackFunc func(httpLayer.FallbackMeta))
阻塞
type ServerConn ¶
type ServerConn struct { io.Closer Writer http.ResponseWriter // contains filtered or unexported fields }
func (*ServerConn) Close ¶
func (sc *ServerConn) Close() error
func (*ServerConn) HasOwnDefaultRejectBehavior ¶ added in v1.2.4
func (*ServerConn) HasOwnDefaultRejectBehavior() bool
implements netLayer.RejectConn, return true
func (*ServerConn) Reject ¶ added in v1.2.4
func (sc *ServerConn) Reject()
implements netLayer.RejectConn, 模仿nginx响应,参考 httpLayer.SetNginx400Response