msg.go 6.5 KB

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