grpcSimple

package
v1.2.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package grpcSimple implements grpc tunnel without importing google.golang.org/grpc.

Reference

https://github.com/Dreamacro/clash/blob/master/transport/gun/gun.go, which is under MIT license

在 clash的客户端实现 的 基础上 继续用 golang的 http2包 实现了 grpc 的 基本服务端,并改进了 原代码。

Advantages

grpcSimple包 比grpc包 小很多,替代grpc包的话,可以减小 4MB 左右的可执行文件大小。但是目前不支持 multiMode。

grpcSimple包 是很棒 很有用的 实现,未来可以添加 针对 grpc的ServiceName的回落。

Off Topic

我们可以通过本包的代码看到,grpc实际上是 基于包的,而不是基于流的,与ws类似。

参考 https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Config
	// contains filtered or unexported fields
}

func (*Client) DialSubConn

func (c *Client) DialSubConn(underlay any) (net.Conn, error)

func (*Client) GetCommonConn

func (c *Client) GetCommonConn(underlay net.Conn) (any, error)

func (*Client) GetPath

func (c *Client) GetPath() string

func (*Client) IsEarly

func (c *Client) IsEarly() bool

func (*Client) IsMux

func (c *Client) IsMux() bool

func (*Client) IsSuper

func (c *Client) IsSuper() bool

func (*Client) ProcessWhenFull

func (c *Client) ProcessWhenFull(underlay any)

type ClientConn

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

implements net.Conn

func (*ClientConn) Close

func (g *ClientConn) Close() error

func (*ClientConn) LocalAddr

func (c *ClientConn) LocalAddr() net.Addr

func (*ClientConn) Read

func (g *ClientConn) Read(b []byte) (n int, err error)

func (*ClientConn) RemoteAddr

func (c *ClientConn) RemoteAddr() net.Addr

func (*ClientConn) SetDeadline

func (g *ClientConn) SetDeadline(t time.Time) error

func (*ClientConn) SetReadDeadline

func (g *ClientConn) SetReadDeadline(t time.Time) error

func (*ClientConn) SetWriteDeadline

func (g *ClientConn) SetWriteDeadline(t time.Time) error

func (*ClientConn) Write

func (g *ClientConn) Write(b []byte) (n int, err error)

type Config

type Config struct {
	ServiceName string
	Host        string
}

type Creator

type Creator struct{}

func (Creator) GetDefaultAlpn

func (Creator) GetDefaultAlpn() (alpn string, mustUse bool)

func (Creator) NewClientFromConf

func (Creator) NewClientFromConf(conf *advLayer.Conf) (advLayer.Client, error)

func (Creator) NewServerFromConf

func (Creator) NewServerFromConf(conf *advLayer.Conf) (advLayer.Server, error)

func (Creator) PackageID

func (Creator) PackageID() string

type Server

type Server struct {
	Config

	http2.Server
	// contains filtered or unexported fields
}

func (*Server) GetPath

func (s *Server) GetPath() string

func (*Server) IsMux

func (*Server) IsMux() bool

func (*Server) IsSuper

func (*Server) IsSuper() bool

func (*Server) StartHandle

func (s *Server) StartHandle(underlay net.Conn, newSubConnChan chan net.Conn, fallbackConnChan chan advLayer.FallbackMeta)

func (*Server) Stop

func (s *Server) Stop()

type ServerConn

type ServerConn struct {
	io.Closer
	io.Writer
	// contains filtered or unexported fields
}

func (*ServerConn) Close

func (g *ServerConn) Close() error

func (*ServerConn) LocalAddr

func (c *ServerConn) LocalAddr() net.Addr

func (*ServerConn) Read

func (c *ServerConn) Read(b []byte) (n int, err error)

func (*ServerConn) RemoteAddr

func (c *ServerConn) RemoteAddr() net.Addr

func (*ServerConn) SetDeadline

func (g *ServerConn) SetDeadline(t time.Time) error

func (*ServerConn) SetReadDeadline

func (g *ServerConn) SetReadDeadline(t time.Time) error

func (*ServerConn) SetWriteDeadline

func (g *ServerConn) SetWriteDeadline(t time.Time) error

func (*ServerConn) Write

func (g *ServerConn) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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