1
0

msg.go 3.4 KB

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