msg.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 (
  16. "net"
  17. )
  18. const (
  19. TypeLogin = 'o'
  20. TypeLoginResp = '1'
  21. TypeNewProxy = 'p'
  22. TypeNewProxyResp = '2'
  23. TypeCloseProxy = 'c'
  24. TypeNewWorkConn = 'w'
  25. TypeReqWorkConn = 'r'
  26. TypeStartWorkConn = 's'
  27. TypeNewVisitorConn = 'v'
  28. TypeNewVisitorConnResp = '3'
  29. TypePing = 'h'
  30. TypePong = '4'
  31. TypeUDPPacket = 'u'
  32. TypeNatHoleVisitor = 'i'
  33. TypeNatHoleClient = 'n'
  34. TypeNatHoleResp = 'm'
  35. TypeNatHoleClientDetectOK = 'd'
  36. TypeNatHoleSid = '5'
  37. TypeNatHoleBinding = 'b'
  38. TypeNatHoleBindingResp = '6'
  39. )
  40. var msgTypeMap = map[byte]interface{}{
  41. TypeLogin: Login{},
  42. TypeLoginResp: LoginResp{},
  43. TypeNewProxy: NewProxy{},
  44. TypeNewProxyResp: NewProxyResp{},
  45. TypeCloseProxy: CloseProxy{},
  46. TypeNewWorkConn: NewWorkConn{},
  47. TypeReqWorkConn: ReqWorkConn{},
  48. TypeStartWorkConn: StartWorkConn{},
  49. TypeNewVisitorConn: NewVisitorConn{},
  50. TypeNewVisitorConnResp: NewVisitorConnResp{},
  51. TypePing: Ping{},
  52. TypePong: Pong{},
  53. TypeUDPPacket: UDPPacket{},
  54. TypeNatHoleVisitor: NatHoleVisitor{},
  55. TypeNatHoleClient: NatHoleClient{},
  56. TypeNatHoleResp: NatHoleResp{},
  57. TypeNatHoleClientDetectOK: NatHoleClientDetectOK{},
  58. TypeNatHoleSid: NatHoleSid{},
  59. TypeNatHoleBinding: NatHoleBinding{},
  60. TypeNatHoleBindingResp: NatHoleBindingResp{},
  61. }
  62. // When frpc start, client send this message to login to server.
  63. type Login struct {
  64. Version string `json:"version,omitempty"`
  65. Hostname string `json:"hostname,omitempty"`
  66. Os string `json:"os,omitempty"`
  67. Arch string `json:"arch,omitempty"`
  68. User string `json:"user,omitempty"`
  69. PrivilegeKey string `json:"privilege_key,omitempty"`
  70. Timestamp int64 `json:"timestamp,omitempty"`
  71. RunID string `json:"run_id,omitempty"`
  72. Metas map[string]string `json:"metas,omitempty"`
  73. // Some global configures.
  74. PoolCount int `json:"pool_count,omitempty"`
  75. }
  76. type LoginResp struct {
  77. Version string `json:"version,omitempty"`
  78. RunID string `json:"run_id,omitempty"`
  79. ServerUDPPort int `json:"server_udp_port,omitempty"`
  80. Error string `json:"error,omitempty"`
  81. }
  82. // When frpc login success, send this message to frps for running a new proxy.
  83. type NewProxy struct {
  84. ProxyName string `json:"proxy_name,omitempty"`
  85. ProxyType string `json:"proxy_type,omitempty"`
  86. UseEncryption bool `json:"use_encryption,omitempty"`
  87. UseCompression bool `json:"use_compression,omitempty"`
  88. BandwidthLimit string `json:"bandwidth_limit,omitempty"`
  89. BandwidthLimitMode string `json:"bandwidth_limit_mode,omitempty"`
  90. Group string `json:"group,omitempty"`
  91. GroupKey string `json:"group_key,omitempty"`
  92. Metas map[string]string `json:"metas,omitempty"`
  93. // tcp and udp only
  94. RemotePort int `json:"remote_port,omitempty"`
  95. // http and https only
  96. CustomDomains []string `json:"custom_domains,omitempty"`
  97. SubDomain string `json:"subdomain,omitempty"`
  98. Locations []string `json:"locations,omitempty"`
  99. HTTPUser string `json:"http_user,omitempty"`
  100. HTTPPwd string `json:"http_pwd,omitempty"`
  101. HostHeaderRewrite string `json:"host_header_rewrite,omitempty"`
  102. Headers map[string]string `json:"headers,omitempty"`
  103. RouteByHTTPUser string `json:"route_by_http_user,omitempty"`
  104. // stcp
  105. Sk string `json:"sk,omitempty"`
  106. // tcpmux
  107. Multiplexer string `json:"multiplexer,omitempty"`
  108. }
  109. type NewProxyResp struct {
  110. ProxyName string `json:"proxy_name,omitempty"`
  111. RemoteAddr string `json:"remote_addr,omitempty"`
  112. Error string `json:"error,omitempty"`
  113. }
  114. type CloseProxy struct {
  115. ProxyName string `json:"proxy_name,omitempty"`
  116. }
  117. type NewWorkConn struct {
  118. RunID string `json:"run_id,omitempty"`
  119. PrivilegeKey string `json:"privilege_key,omitempty"`
  120. Timestamp int64 `json:"timestamp,omitempty"`
  121. }
  122. type ReqWorkConn struct{}
  123. type StartWorkConn struct {
  124. ProxyName string `json:"proxy_name,omitempty"`
  125. SrcAddr string `json:"src_addr,omitempty"`
  126. DstAddr string `json:"dst_addr,omitempty"`
  127. SrcPort uint16 `json:"src_port,omitempty"`
  128. DstPort uint16 `json:"dst_port,omitempty"`
  129. Error string `json:"error,omitempty"`
  130. }
  131. type NewVisitorConn struct {
  132. ProxyName string `json:"proxy_name,omitempty"`
  133. SignKey string `json:"sign_key,omitempty"`
  134. Timestamp int64 `json:"timestamp,omitempty"`
  135. UseEncryption bool `json:"use_encryption,omitempty"`
  136. UseCompression bool `json:"use_compression,omitempty"`
  137. }
  138. type NewVisitorConnResp struct {
  139. ProxyName string `json:"proxy_name,omitempty"`
  140. Error string `json:"error,omitempty"`
  141. }
  142. type Ping struct {
  143. PrivilegeKey string `json:"privilege_key,omitempty"`
  144. Timestamp int64 `json:"timestamp,omitempty"`
  145. }
  146. type Pong struct {
  147. Error string `json:"error,omitempty"`
  148. }
  149. type UDPPacket struct {
  150. Content string `json:"c,omitempty"`
  151. LocalAddr *net.UDPAddr `json:"l,omitempty"`
  152. RemoteAddr *net.UDPAddr `json:"r,omitempty"`
  153. }
  154. type NatHoleVisitor struct {
  155. ProxyName string `json:"proxy_name,omitempty"`
  156. SignKey string `json:"sign_key,omitempty"`
  157. Timestamp int64 `json:"timestamp,omitempty"`
  158. }
  159. type NatHoleClient struct {
  160. ProxyName string `json:"proxy_name,omitempty"`
  161. Sid string `json:"sid,omitempty"`
  162. }
  163. type NatHoleResp struct {
  164. Sid string `json:"sid,omitempty"`
  165. VisitorAddr string `json:"visitor_addr,omitempty"`
  166. ClientAddr string `json:"client_addr,omitempty"`
  167. Error string `json:"error,omitempty"`
  168. }
  169. type NatHoleClientDetectOK struct{}
  170. type NatHoleSid struct {
  171. Sid string `json:"sid,omitempty"`
  172. }
  173. type NatHoleBinding struct {
  174. TransactionID string `json:"transaction_id,omitempty"`
  175. }
  176. type NatHoleBindingResp struct {
  177. TransactionID string `json:"transaction_id,omitempty"`
  178. Address string `json:"address,omitempty"`
  179. Error string `json:"error,omitempty"`
  180. }