msg.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. TypeNatHoleSid = '5'
  34. )
  35. var (
  36. 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. TypeNatHoleSid: NatHoleSid{},
  54. }
  55. )
  56. // When frpc start, client send this message to login to server.
  57. type Login struct {
  58. Version string `json:"version"`
  59. Hostname string `json:"hostname"`
  60. Os string `json:"os"`
  61. Arch string `json:"arch"`
  62. User string `json:"user"`
  63. PrivilegeKey string `json:"privilege_key"`
  64. Timestamp int64 `json:"timestamp"`
  65. RunId string `json:"run_id"`
  66. // Some global configures.
  67. PoolCount int `json:"pool_count"`
  68. }
  69. type LoginResp struct {
  70. Version string `json:"version"`
  71. RunId string `json:"run_id"`
  72. ServerUdpPort int `json:"server_udp_port"`
  73. Error string `json:"error"`
  74. }
  75. // When frpc login success, send this message to frps for running a new proxy.
  76. type NewProxy struct {
  77. ProxyName string `json:"proxy_name"`
  78. ProxyType string `json:"proxy_type"`
  79. UseEncryption bool `json:"use_encryption"`
  80. UseCompression bool `json:"use_compression"`
  81. Group string `json:"group"`
  82. GroupKey string `json:"group_key"`
  83. // tcp and udp only
  84. RemotePort int `json:"remote_port"`
  85. // http and https only
  86. CustomDomains []string `json:"custom_domains"`
  87. SubDomain string `json:"subdomain"`
  88. Locations []string `json:"locations"`
  89. HttpUser string `json:"http_user"`
  90. HttpPwd string `json:"http_pwd"`
  91. HostHeaderRewrite string `json:"host_header_rewrite"`
  92. Headers map[string]string `json:"headers"`
  93. // stcp
  94. Sk string `json:"sk"`
  95. }
  96. type NewProxyResp struct {
  97. ProxyName string `json:"proxy_name"`
  98. RemoteAddr string `json:"remote_addr"`
  99. Error string `json:"error"`
  100. }
  101. type CloseProxy struct {
  102. ProxyName string `json:"proxy_name"`
  103. }
  104. type NewWorkConn struct {
  105. RunId string `json:"run_id"`
  106. }
  107. type ReqWorkConn struct {
  108. }
  109. type StartWorkConn struct {
  110. ProxyName string `json:"proxy_name"`
  111. }
  112. type NewVisitorConn struct {
  113. ProxyName string `json:"proxy_name"`
  114. SignKey string `json:"sign_key"`
  115. Timestamp int64 `json:"timestamp"`
  116. UseEncryption bool `json:"use_encryption"`
  117. UseCompression bool `json:"use_compression"`
  118. }
  119. type NewVisitorConnResp struct {
  120. ProxyName string `json:"proxy_name"`
  121. Error string `json:"error"`
  122. }
  123. type Ping struct {
  124. }
  125. type Pong struct {
  126. }
  127. type UdpPacket struct {
  128. Content string `json:"c"`
  129. LocalAddr *net.UDPAddr `json:"l"`
  130. RemoteAddr *net.UDPAddr `json:"r"`
  131. }
  132. type NatHoleVisitor struct {
  133. ProxyName string `json:"proxy_name"`
  134. SignKey string `json:"sign_key"`
  135. Timestamp int64 `json:"timestamp"`
  136. }
  137. type NatHoleClient struct {
  138. ProxyName string `json:"proxy_name"`
  139. Sid string `json:"sid"`
  140. }
  141. type NatHoleResp struct {
  142. Sid string `json:"sid"`
  143. VisitorAddr string `json:"visitor_addr"`
  144. ClientAddr string `json:"client_addr"`
  145. Error string `json:"error"`
  146. }
  147. type NatHoleSid struct {
  148. Sid string `json:"sid"`
  149. }