msg.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // Copyright 2016 fatedier, fatedier@gmail.com
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package msg
  15. import "net"
  16. const (
  17. TypeLogin = 'o'
  18. TypeLoginResp = '1'
  19. TypeNewProxy = 'p'
  20. TypeNewProxyResp = '2'
  21. TypeCloseProxy = 'c'
  22. TypeNewWorkConn = 'w'
  23. TypeReqWorkConn = 'r'
  24. TypeStartWorkConn = 's'
  25. TypeNewVisitorConn = 'v'
  26. TypeNewVisitorConnResp = '3'
  27. TypePing = 'h'
  28. TypePong = '4'
  29. TypeUDPPacket = 'u'
  30. TypeNatHoleVisitor = 'i'
  31. TypeNatHoleClient = 'n'
  32. TypeNatHoleResp = 'm'
  33. TypeNatHoleClientDetectOK = 'd'
  34. TypeNatHoleSid = '5'
  35. )
  36. var msgTypeMap = map[byte]interface{}{
  37. TypeLogin: Login{},
  38. TypeLoginResp: LoginResp{},
  39. TypeNewProxy: NewProxy{},
  40. TypeNewProxyResp: NewProxyResp{},
  41. TypeCloseProxy: CloseProxy{},
  42. TypeNewWorkConn: NewWorkConn{},
  43. TypeReqWorkConn: ReqWorkConn{},
  44. TypeStartWorkConn: StartWorkConn{},
  45. TypeNewVisitorConn: NewVisitorConn{},
  46. TypeNewVisitorConnResp: NewVisitorConnResp{},
  47. TypePing: Ping{},
  48. TypePong: Pong{},
  49. TypeUDPPacket: UDPPacket{},
  50. TypeNatHoleVisitor: NatHoleVisitor{},
  51. TypeNatHoleClient: NatHoleClient{},
  52. TypeNatHoleResp: NatHoleResp{},
  53. TypeNatHoleClientDetectOK: NatHoleClientDetectOK{},
  54. TypeNatHoleSid: NatHoleSid{},
  55. }
  56. // When frpc start, client send this message to login to server.
  57. type Login struct {
  58. Version string `json:"version,omitempty"`
  59. Hostname string `json:"hostname,omitempty"`
  60. Os string `json:"os,omitempty"`
  61. Arch string `json:"arch,omitempty"`
  62. User string `json:"user,omitempty"`
  63. PrivilegeKey string `json:"privilege_key,omitempty"`
  64. Timestamp int64 `json:"timestamp,omitempty"`
  65. RunID string `json:"run_id,omitempty"`
  66. Metas map[string]string `json:"metas,omitempty"`
  67. // Some global configures.
  68. PoolCount int `json:"pool_count,omitempty"`
  69. }
  70. type LoginResp struct {
  71. Version string `json:"version,omitempty"`
  72. RunID string `json:"run_id,omitempty"`
  73. ServerUDPPort int `json:"server_udp_port,omitempty"`
  74. Error string `json:"error,omitempty"`
  75. }
  76. // When frpc login success, send this message to frps for running a new proxy.
  77. type NewProxy struct {
  78. ProxyName string `json:"proxy_name,omitempty"`
  79. ProxyType string `json:"proxy_type,omitempty"`
  80. UseEncryption bool `json:"use_encryption,omitempty"`
  81. UseCompression bool `json:"use_compression,omitempty"`
  82. Group string `json:"group,omitempty"`
  83. GroupKey string `json:"group_key,omitempty"`
  84. Metas map[string]string `json:"metas,omitempty"`
  85. // tcp and udp only
  86. RemotePort int `json:"remote_port,omitempty"`
  87. // http and https only
  88. CustomDomains []string `json:"custom_domains,omitempty"`
  89. SubDomain string `json:"subdomain,omitempty"`
  90. Locations []string `json:"locations,omitempty"`
  91. HTTPUser string `json:"http_user,omitempty"`
  92. HTTPPwd string `json:"http_pwd,omitempty"`
  93. HostHeaderRewrite string `json:"host_header_rewrite,omitempty"`
  94. Headers map[string]string `json:"headers,omitempty"`
  95. RouteByHTTPUser string `json:"route_by_http_user,omitempty"`
  96. // stcp
  97. Sk string `json:"sk,omitempty"`
  98. // tcpmux
  99. Multiplexer string `json:"multiplexer,omitempty"`
  100. }
  101. type NewProxyResp struct {
  102. ProxyName string `json:"proxy_name,omitempty"`
  103. RemoteAddr string `json:"remote_addr,omitempty"`
  104. Error string `json:"error,omitempty"`
  105. }
  106. type CloseProxy struct {
  107. ProxyName string `json:"proxy_name,omitempty"`
  108. }
  109. type NewWorkConn struct {
  110. RunID string `json:"run_id,omitempty"`
  111. PrivilegeKey string `json:"privilege_key,omitempty"`
  112. Timestamp int64 `json:"timestamp,omitempty"`
  113. }
  114. type ReqWorkConn struct{}
  115. type StartWorkConn struct {
  116. ProxyName string `json:"proxy_name,omitempty"`
  117. SrcAddr string `json:"src_addr,omitempty"`
  118. DstAddr string `json:"dst_addr,omitempty"`
  119. SrcPort uint16 `json:"src_port,omitempty"`
  120. DstPort uint16 `json:"dst_port,omitempty"`
  121. Error string `json:"error,omitempty"`
  122. }
  123. type NewVisitorConn struct {
  124. ProxyName string `json:"proxy_name,omitempty"`
  125. SignKey string `json:"sign_key,omitempty"`
  126. Timestamp int64 `json:"timestamp,omitempty"`
  127. UseEncryption bool `json:"use_encryption,omitempty"`
  128. UseCompression bool `json:"use_compression,omitempty"`
  129. }
  130. type NewVisitorConnResp struct {
  131. ProxyName string `json:"proxy_name,omitempty"`
  132. Error string `json:"error,omitempty"`
  133. }
  134. type Ping struct {
  135. PrivilegeKey string `json:"privilege_key,omitempty"`
  136. Timestamp int64 `json:"timestamp,omitempty"`
  137. }
  138. type Pong struct {
  139. Error string `json:"error,omitempty"`
  140. }
  141. type UDPPacket struct {
  142. Content string `json:"c,omitempty"`
  143. LocalAddr *net.UDPAddr `json:"l,omitempty"`
  144. RemoteAddr *net.UDPAddr `json:"r,omitempty"`
  145. }
  146. type NatHoleVisitor struct {
  147. ProxyName string `json:"proxy_name,omitempty"`
  148. SignKey string `json:"sign_key,omitempty"`
  149. Timestamp int64 `json:"timestamp,omitempty"`
  150. }
  151. type NatHoleClient struct {
  152. ProxyName string `json:"proxy_name,omitempty"`
  153. Sid string `json:"sid,omitempty"`
  154. }
  155. type NatHoleResp struct {
  156. Sid string `json:"sid,omitempty"`
  157. VisitorAddr string `json:"visitor_addr,omitempty"`
  158. ClientAddr string `json:"client_addr,omitempty"`
  159. Error string `json:"error,omitempty"`
  160. }
  161. type NatHoleClientDetectOK struct{}
  162. type NatHoleSid struct {
  163. Sid string `json:"sid,omitempty"`
  164. }