mirror of
https://github.com/fatedier/frp.git
synced 2025-07-20 12:50:04 +07:00
refactor the code related to xtcp (#3449)
This commit is contained in:
142
pkg/msg/msg.go
142
pkg/msg/msg.go
@ -16,54 +16,53 @@ package msg
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
TypeLogin = 'o'
|
||||
TypeLoginResp = '1'
|
||||
TypeNewProxy = 'p'
|
||||
TypeNewProxyResp = '2'
|
||||
TypeCloseProxy = 'c'
|
||||
TypeNewWorkConn = 'w'
|
||||
TypeReqWorkConn = 'r'
|
||||
TypeStartWorkConn = 's'
|
||||
TypeNewVisitorConn = 'v'
|
||||
TypeNewVisitorConnResp = '3'
|
||||
TypePing = 'h'
|
||||
TypePong = '4'
|
||||
TypeUDPPacket = 'u'
|
||||
TypeNatHoleVisitor = 'i'
|
||||
TypeNatHoleClient = 'n'
|
||||
TypeNatHoleResp = 'm'
|
||||
TypeNatHoleClientDetectOK = 'd'
|
||||
TypeNatHoleSid = '5'
|
||||
TypeNatHoleBinding = 'b'
|
||||
TypeNatHoleBindingResp = '6'
|
||||
TypeLogin = 'o'
|
||||
TypeLoginResp = '1'
|
||||
TypeNewProxy = 'p'
|
||||
TypeNewProxyResp = '2'
|
||||
TypeCloseProxy = 'c'
|
||||
TypeNewWorkConn = 'w'
|
||||
TypeReqWorkConn = 'r'
|
||||
TypeStartWorkConn = 's'
|
||||
TypeNewVisitorConn = 'v'
|
||||
TypeNewVisitorConnResp = '3'
|
||||
TypePing = 'h'
|
||||
TypePong = '4'
|
||||
TypeUDPPacket = 'u'
|
||||
TypeNatHoleVisitor = 'i'
|
||||
TypeNatHoleClient = 'n'
|
||||
TypeNatHoleResp = 'm'
|
||||
TypeNatHoleSid = '5'
|
||||
TypeNatHoleReport = '6'
|
||||
)
|
||||
|
||||
var msgTypeMap = map[byte]interface{}{
|
||||
TypeLogin: Login{},
|
||||
TypeLoginResp: LoginResp{},
|
||||
TypeNewProxy: NewProxy{},
|
||||
TypeNewProxyResp: NewProxyResp{},
|
||||
TypeCloseProxy: CloseProxy{},
|
||||
TypeNewWorkConn: NewWorkConn{},
|
||||
TypeReqWorkConn: ReqWorkConn{},
|
||||
TypeStartWorkConn: StartWorkConn{},
|
||||
TypeNewVisitorConn: NewVisitorConn{},
|
||||
TypeNewVisitorConnResp: NewVisitorConnResp{},
|
||||
TypePing: Ping{},
|
||||
TypePong: Pong{},
|
||||
TypeUDPPacket: UDPPacket{},
|
||||
TypeNatHoleVisitor: NatHoleVisitor{},
|
||||
TypeNatHoleClient: NatHoleClient{},
|
||||
TypeNatHoleResp: NatHoleResp{},
|
||||
TypeNatHoleClientDetectOK: NatHoleClientDetectOK{},
|
||||
TypeNatHoleSid: NatHoleSid{},
|
||||
TypeNatHoleBinding: NatHoleBinding{},
|
||||
TypeNatHoleBindingResp: NatHoleBindingResp{},
|
||||
TypeLogin: Login{},
|
||||
TypeLoginResp: LoginResp{},
|
||||
TypeNewProxy: NewProxy{},
|
||||
TypeNewProxyResp: NewProxyResp{},
|
||||
TypeCloseProxy: CloseProxy{},
|
||||
TypeNewWorkConn: NewWorkConn{},
|
||||
TypeReqWorkConn: ReqWorkConn{},
|
||||
TypeStartWorkConn: StartWorkConn{},
|
||||
TypeNewVisitorConn: NewVisitorConn{},
|
||||
TypeNewVisitorConnResp: NewVisitorConnResp{},
|
||||
TypePing: Ping{},
|
||||
TypePong: Pong{},
|
||||
TypeUDPPacket: UDPPacket{},
|
||||
TypeNatHoleVisitor: NatHoleVisitor{},
|
||||
TypeNatHoleClient: NatHoleClient{},
|
||||
TypeNatHoleResp: NatHoleResp{},
|
||||
TypeNatHoleSid: NatHoleSid{},
|
||||
TypeNatHoleReport: NatHoleReport{},
|
||||
}
|
||||
|
||||
var TypeNameNatHoleResp = reflect.TypeOf(&NatHoleResp{}).Elem().Name()
|
||||
|
||||
// When frpc start, client send this message to login to server.
|
||||
type Login struct {
|
||||
Version string `json:"version,omitempty"`
|
||||
@ -175,35 +174,58 @@ type UDPPacket struct {
|
||||
}
|
||||
|
||||
type NatHoleVisitor struct {
|
||||
ProxyName string `json:"proxy_name,omitempty"`
|
||||
SignKey string `json:"sign_key,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
TransactionID string `json:"transaction_id,omitempty"`
|
||||
ProxyName string `json:"proxy_name,omitempty"`
|
||||
PreCheck bool `json:"pre_check,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
SignKey string `json:"sign_key,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
MappedAddrs []string `json:"mapped_addrs,omitempty"`
|
||||
AssistedAddrs []string `json:"assisted_addrs,omitempty"`
|
||||
}
|
||||
|
||||
type NatHoleClient struct {
|
||||
ProxyName string `json:"proxy_name,omitempty"`
|
||||
Sid string `json:"sid,omitempty"`
|
||||
TransactionID string `json:"transaction_id,omitempty"`
|
||||
ProxyName string `json:"proxy_name,omitempty"`
|
||||
Sid string `json:"sid,omitempty"`
|
||||
MappedAddrs []string `json:"mapped_addrs,omitempty"`
|
||||
AssistedAddrs []string `json:"assisted_addrs,omitempty"`
|
||||
}
|
||||
|
||||
type PortsRange struct {
|
||||
From int `json:"from,omitempty"`
|
||||
To int `json:"to,omitempty"`
|
||||
}
|
||||
|
||||
type NatHoleDetectBehavior struct {
|
||||
Role string `json:"role,omitempty"` // sender or receiver
|
||||
Mode int `json:"mode,omitempty"` // 0, 1, 2...
|
||||
TTL int `json:"ttl,omitempty"`
|
||||
SendDelayMs int `json:"send_delay_ms,omitempty"`
|
||||
ReadTimeoutMs int `json:"read_timeout,omitempty"`
|
||||
CandidatePorts []PortsRange `json:"candidate_ports,omitempty"`
|
||||
SendRandomPorts int `json:"send_random_ports,omitempty"`
|
||||
ListenRandomPorts int `json:"listen_random_ports,omitempty"`
|
||||
}
|
||||
|
||||
type NatHoleResp struct {
|
||||
Sid string `json:"sid,omitempty"`
|
||||
VisitorAddr string `json:"visitor_addr,omitempty"`
|
||||
ClientAddr string `json:"client_addr,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
TransactionID string `json:"transaction_id,omitempty"`
|
||||
Sid string `json:"sid,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
CandidateAddrs []string `json:"candidate_addrs,omitempty"`
|
||||
AssistedAddrs []string `json:"assisted_addrs,omitempty"`
|
||||
DetectBehavior NatHoleDetectBehavior `json:"detect_behavior,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type NatHoleClientDetectOK struct{}
|
||||
|
||||
type NatHoleSid struct {
|
||||
Sid string `json:"sid,omitempty"`
|
||||
TransactionID string `json:"transaction_id,omitempty"`
|
||||
Sid string `json:"sid,omitempty"`
|
||||
Response bool `json:"response,omitempty"`
|
||||
Nonce string `json:"nonce,omitempty"`
|
||||
}
|
||||
|
||||
type NatHoleBinding struct {
|
||||
TransactionID string `json:"transaction_id,omitempty"`
|
||||
}
|
||||
|
||||
type NatHoleBindingResp struct {
|
||||
TransactionID string `json:"transaction_id,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
type NatHoleReport struct {
|
||||
Sid string `json:"sid,omitempty"`
|
||||
Success bool `json:"success,omitempty"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user