msg.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "reflect"
  16. const (
  17. TypeLogin = 'o'
  18. TypeLoginResp = '1'
  19. TypeNewProxy = 'p'
  20. TypeNewProxyResp = '2'
  21. TypeNewWorkConn = 'w'
  22. TypeReqWorkConn = 'r'
  23. TypeStartWorkConn = 's'
  24. TypePing = 'h'
  25. TypePong = '4'
  26. )
  27. var (
  28. TypeMap map[byte]reflect.Type
  29. TypeStringMap map[reflect.Type]byte
  30. )
  31. func init() {
  32. TypeMap = make(map[byte]reflect.Type)
  33. TypeStringMap = make(map[reflect.Type]byte)
  34. TypeMap[TypeLogin] = reflect.TypeOf(Login{})
  35. TypeMap[TypeLoginResp] = reflect.TypeOf(LoginResp{})
  36. TypeMap[TypeNewProxy] = reflect.TypeOf(NewProxy{})
  37. TypeMap[TypeNewProxyResp] = reflect.TypeOf(NewProxyResp{})
  38. TypeMap[TypeNewWorkConn] = reflect.TypeOf(NewWorkConn{})
  39. TypeMap[TypeReqWorkConn] = reflect.TypeOf(ReqWorkConn{})
  40. TypeMap[TypeStartWorkConn] = reflect.TypeOf(StartWorkConn{})
  41. TypeMap[TypePing] = reflect.TypeOf(Ping{})
  42. TypeMap[TypePong] = reflect.TypeOf(Pong{})
  43. for k, v := range TypeMap {
  44. TypeStringMap[v] = k
  45. }
  46. }
  47. // Message wraps socket packages for communicating between frpc and frps.
  48. type Message interface{}
  49. // When frpc start, client send this message to login to server.
  50. type Login struct {
  51. Version string `json:"version"`
  52. Hostname string `json:"hostname"`
  53. Os string `json:"os"`
  54. Arch string `json:"arch"`
  55. User string `json:"user"`
  56. PrivilegeKey string `json:"privilege_key"`
  57. Timestamp int64 `json:"timestamp"`
  58. RunId string `json:"run_id"`
  59. // Some global configures.
  60. PoolCount int `json:"pool_count"`
  61. }
  62. type LoginResp struct {
  63. Version string `json:"version"`
  64. RunId string `json:"run_id"`
  65. Error string `json:"error"`
  66. }
  67. // When frpc login success, send this message to frps for running a new proxy.
  68. type NewProxy struct {
  69. ProxyName string `json:"proxy_name"`
  70. ProxyType string `json:"proxy_type"`
  71. UseEncryption bool `json:"use_encryption"`
  72. UseCompression bool `json:"use_compression"`
  73. // tcp and udp only
  74. RemotePort int64 `json:"remote_port"`
  75. // http and https only
  76. CustomDomains []string `json:"custom_domains"`
  77. SubDomain string `json:"subdomain"`
  78. Locations []string `json:"locations"`
  79. HostHeaderRewrite string `json:"host_header_rewrite"`
  80. HttpUser string `json:"http_user"`
  81. HttpPwd string `json:"http_pwd"`
  82. }
  83. type NewProxyResp struct {
  84. ProxyName string `json:"proxy_name"`
  85. Error string `json:"error"`
  86. }
  87. type NewWorkConn struct {
  88. RunId string `json:"run_id"`
  89. }
  90. type ReqWorkConn struct {
  91. }
  92. type StartWorkConn struct {
  93. ProxyName string `json:"proxy_name"`
  94. }
  95. type Ping struct {
  96. }
  97. type Pong struct {
  98. }