msg.go 5.0 KB

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