grpc

package
v0.0.0-...-5e50992 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If[T any](cond bool, a, b T) T

Helper

Types

type Client

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

func StartGrpcClient

func StartGrpcClient(option *ClientOption) *Client

func (*Client) ReadMessage

func (client *Client) ReadMessage() (*proto.Message, error)

func (*Client) WriteMessage

func (client *Client) WriteMessage(message *proto.Message) error

type ClientOption

type ClientOption struct {
	Token      string // token to authenticate
	ServerAddr string // the address of server
	ServerPort uint16 // the port of server
}

type FakeGate

type FakeGate struct{}

func (*FakeGate) Add

func (fake *FakeGate) Add(net.IP) error

func (*FakeGate) Delete

func (fake *FakeGate) Delete(net.IP) error

type GateInf

type GateInf interface {
	Add(net.IP) error
	Delete(net.IP) error
}

type IPv4Hdr

type IPv4Hdr struct {
	Src net.IP // source address
	Dst net.IP // destination address
}

func ParseIpv4Hdr

func ParseIpv4Hdr(data []byte) (*IPv4Hdr, error)

type RouteTable

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

func NewRouteTable

func NewRouteTable() *RouteTable

func (*RouteTable) Add

func (*RouteTable) Delete

func (ds *RouteTable) Delete(cidr string) error

func (*RouteTable) DeleteBatch

func (ds *RouteTable) DeleteBatch(cidrs []string)

func (*RouteTable) Lookup

func (ds *RouteTable) Lookup(addr net.IP) (t proto.Stream_PersistentStreamServer, ok bool)

type Server

type Server struct {
	proto.UnimplementedStreamServer

	Token    string
	GateImpl GateInf
	// contains filtered or unexported fields
}

func StartGrpcServer

func StartGrpcServer(option *ServerOption, subnet string) *Server

func (*Server) Auth

func (server *Server) Auth(stream proto.Stream_PersistentStreamServer) (net.IP, bool)

func (*Server) BroadcastRouteWithoutMe

func (server *Server) BroadcastRouteWithoutMe(stream proto.Stream_PersistentStreamServer, msg *proto.Message)

BroadcastRouteWithoutMe 发送广播,路由信息

func (*Server) GatherRouteTo

func (server *Server) GatherRouteTo(stream proto.Stream_PersistentStreamServer)

GatherRouteTo 将所有路由信息集中发送到Stream

func (*Server) PersistentStream

func (server *Server) PersistentStream(stream proto.Stream_PersistentStreamServer) error

func (*Server) ReadMessage

func (server *Server) ReadMessage() (*proto.Message, error)

ReadMessage 从GRPCServer读取发送给Tunnel的数据

func (*Server) WriteMessage

func (server *Server) WriteMessage(msg *proto.Message) error

WriteMessage 本地隧道向GRPCServer写数据

type ServerOption

type ServerOption struct {
	Token    string // token to authenticate
	BindPort uint16
	GateImpl GateInf
}

type Socket

type Socket interface {
	ReadMessage() (*proto.Message, error)
	WriteMessage(message *proto.Message) error
}

type StreamStore

type StreamStore struct {
	sync.Map
}

type TokenAuth

type TokenAuth struct {
	T int64  // 时间戳
	S string // 签名
}

func (*TokenAuth) GetRequestMetadata

func (t *TokenAuth) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

func (*TokenAuth) ParseMap

func (t *TokenAuth) ParseMap(meta metadata.MD) *TokenAuth

ParseMap 从GRPC的meta信息中获取tokenAuth结构

func (*TokenAuth) RequireTransportSecurity

func (t *TokenAuth) RequireTransportSecurity() bool

RequireTransportSecurity 是否强制使用TLS

func (*TokenAuth) Sign

func (t *TokenAuth) Sign(token string) string

func (*TokenAuth) Verify

func (t *TokenAuth) Verify(token string) bool

Verify 服务端校验

type TunWrapper

type TunWrapper struct {
	grpc.ServerStream
	// contains filtered or unexported fields
}

TunWrapper 将Tunnel模拟GRPC Stream

func NewTunWrapper

func NewTunWrapper() *TunWrapper

func (*TunWrapper) Recv

func (tun *TunWrapper) Recv() (*proto.Message, error)

Recv 从隧道读数据,由外部APP调用

func (*TunWrapper) Send

func (tun *TunWrapper) Send(msg *proto.Message) error

Send 向隧道发送数据

Jump to

Keyboard shortcuts

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