| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package conn
- import (
- "fmt"
- "net"
- )
- // 消息类型
- type MsgType byte
- const (
- MsgPing MsgType = iota
- MsgRequest
- MsgResponse
- MsgAuth
- MsgProxyConnect
- MsgProxyResult
- )
- func (t MsgType) String() string {
- switch t {
- case MsgPing:
- return "Ping"
- case MsgRequest:
- return "Request"
- case MsgResponse:
- return "Response"
- case MsgAuth:
- return "auth"
- case MsgProxyConnect:
- return "ProxyConnect"
- case MsgProxyResult:
- return "ProxyResult"
- default:
- return fmt.Sprintf("Unknown (%d)", t)
- }
- }
- // 网络数据包结构
- // type MsgData struct {
- // Type MsgType
- // Id uint16
- // Cmd string
- // State uint8
- // Data []byte
- // }
- // 连接接口,代表一个原始的连接
- type Connect interface {
- ReadAuthInfo() (proto string, version uint8, channel string, auth []byte, err error)
- ReadMessage(deadline int) (msgType MsgType, id uint16, cmd string, state uint8, data []byte, err error)
- ReadRawPackage(deadline int) (buf []byte, recycle bool, err error)
- WriteRawPackage(raw []byte, recycle bool) (err error)
- WriteAuthInfo(channel string, auth []byte) (err error)
- WriteRequest(id uint16, cmd string, data []byte) error
- WriteResponse(id uint16, state uint8, data []byte) error
- WritePing(id uint16) error
- RemoteIP() net.IP
- LocalIP() net.IP
- Close() error
- }
- // 服务请求连接
- type ServerConnectFunc func(conn Connect)
|