librp

package
v0.0.0-...-6d385c8 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CLIENT = "client"
	SERVER = "server"
)
View Source
const (
	PacketHead uint8 = 0x02
	PacketTail uint8 = 0x03

	PacketCmd1   uint16 = 1000
	PacketVerify uint16 = 1001
	PackageError uint16 = 1002

	PacketVersion uint16 = 0x02
)

Variables

View Source
var (
	DEBUG          = false          // 调试模式 输出 Log.D 字符
	IsGUI          = false          // 是否为GUI
	LogGUICallback func(msg string) // 当IsGUI=true时,不再输出到日志,使用当前回调函数
)
View Source
var (
	// 封包头的结构长度
	PacketHeadLen = getPacketHeadSize() //8
)

Functions

func DecodeRequest

func DecodeRequest(data []byte, reqHost string, port int, isHttps bool) (*http.Request, error)

将字节转为request

func DecodeResponse

func DecodeResponse(data []byte) (*http.Response, error)

// 将字节转为response

func EncodeCmd

func EncodeCmd(cmd uint16, data []byte) []byte

编码数据

func EncodeRequest

func EncodeRequest(r *http.Request) ([]byte, error)

将request 的处理

func EncodeResponse

func EncodeResponse(r *http.Response) ([]byte, error)

将response转为字节

func EncodeVerify

func EncodeVerify() []byte

编码验证包

func EncodeVerifyFailed

func EncodeVerifyFailed() []byte

验证失败回写

func EncodeVerifyOK

func EncodeVerifyOK() []byte

验证成功回写

func ExtractFilePath

func ExtractFilePath(path string) string

ExtractFilePath 提取文件名路径

func IPStr

func IPStr(conn net.Conn) string

从 xxx.xxx.xxx.xxx:xxx格式中取出ip地址

func LoadConfig

func LoadConfig(fileName string, cfg *TRProxyConfig) error

func SaveConfig

func SaveConfig(fileName string, cfg *TRProxyConfig) error

func SetConfig

func SetConfig(cfg *TRProxyConfig)

设置配置文件

func ZlibCompress

func ZlibCompress(input []byte) ([]byte, error)

zlib压缩

func ZlibUnCompress

func ZlibUnCompress(input []byte) ([]byte, error)

zlib解压缩

Types

type IRPObject

type IRPObject interface {
	Start() error
	Close() error
}

type Logger

type Logger struct {
}
var Log Logger

func (Logger) D

func (l Logger) D(v ...interface{})

调试

func (Logger) E

func (l Logger) E(v ...interface{})

错误

func (Logger) EF

func (l Logger) EF(v ...interface{})

func (Logger) I

func (l Logger) I(v ...interface{})

信息

func (Logger) W

func (l Logger) W(v ...interface{})

警告

type THTTPHandler

type THTTPHandler struct {
	http.Handler
	// contains filtered or unexported fields
}

func (*THTTPHandler) ServeHTTP

func (h *THTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TPacketHead

type TPacketHead struct {
	//Head uint8
	Version uint16 // 2
	Cmd     uint16 // 2
	IsZip   uint16 // 2
	DataLen uint32 // 4

}

func DecodeHead

func DecodeHead(data []byte) *TPacketHead

DecodeHead

type TRPClient

type TRPClient struct {
	IRPObject
	// contains filtered or unexported fields
}

func NewRPClient

func NewRPClient() *TRPClient

func (*TRPClient) Close

func (c *TRPClient) Close() error

func (*TRPClient) Start

func (c *TRPClient) Start() error

type TRPServer

type TRPServer struct {
	IRPObject

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRPServer

func NewRPServer() *TRPServer

func (*TRPServer) Close

func (s *TRPServer) Close() error

func (*TRPServer) Start

func (s *TRPServer) Start() error

type TRProxyConfig

type TRProxyConfig struct {

	// 导出的字段
	TCPPort   int    `json:"tcpport"`   // Socket连接或者监听的端口
	VerifyKey string `json:"vkey"`      // 用作客户端与服务端连接时的校验
	IsHTTPS   bool   `json:"ishttps"`   // httpPort端口是否只用作HTTPS监听
	TLSCAFile string `json:"tlscafile"` // 当ishttps为true时,所需的CA根证书文件
	IsZIP     bool   `json:"iszip"`     // 是否开启zip压缩
	Server    struct {
		HTTPPort    int    `json:"httpport"`    // 当mode为server时为服务端监听端口,当为mode为client时为转发至本地客户端的端口
		TLSCertFile string `json:"tlscertfile"` // 当ishttps为true时,所需求的TLS证书文件
		TLSKeyFile  string `json:"tlskeyfile"`  // 当ishttps为true时,所需求的TLS密匙文件
	} `json:"server"`
	Client struct {
		SvrAddr     string `json:"svraddr"`     // 127.0.0.1", "当mode为client时有效,为连接服务器的地址
		HTTPPort    int    `json:"httpport"`    // 当mode为server时为服务端监听端口,当为mode为client时为转发至本地客户端的端口
		TLSCertFile string `json:"tlscertfile"` // 当ishttps为true时,所需求的TLS证书文件
		TLSKeyFile  string `json:"tlskeyfile"`  // 当ishttps为true时,所需求的TLS密匙文件
		LocalAddr   string `json:"localaddr"`   // 转发至本地的地址,默认为127.0.0.1
	} `json:"client"`
	// contains filtered or unexported fields
}

配置文件,一个json文件,可包含客户端和服务端配置

func GetConfig

func GetConfig() *TRProxyConfig

Jump to

Keyboard shortcuts

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