| // |
| 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 |
| 15 | package v1 |
| 16 |
| 17 | import ( |
| 18 | "maps" |
| 19 | "reflect" |
| 20 | "slices" |
| 21 |
| 22 | "github.com/fatedier/frp/pkg/config/types" |
| 23 | "github.com/fatedier/frp/pkg/msg" |
| 24 | "github.com/fatedier/frp/pkg/util/jsonx" |
| 25 | "github.com/fatedier/frp/pkg/util/util" |
| 26 | ) |
| 27 |
| 28 | type ProxyTransport struct { |
| 29 | // UseEncryption controls whether or not communication with the server will |
| 30 | // be encrypted. Encryption is done using the tokens supplied in the server |
| 31 | // and client configuration. |
| 32 | UseEncryption bool `json:"useEncryption,omitempty"` |
| 33 | // UseCompression controls whether or not communication with the server |
| 34 | // will be compressed. |
| 35 | UseCompression bool `json:"useCompression,omitempty"` |
| 36 | // BandwidthLimit limit the bandwidth |
| 37 | // 0 means no limit |
| 38 | BandwidthLimit types.BandwidthQuantity `json:"bandwidthLimit,omitempty"` |
| 39 | // BandwidthLimitMode specifies whether to limit the bandwidth on the |
| 40 | // client or server side. Valid values include "client" and "server". |
| 41 | // By default, this value is "client". |
| 42 | BandwidthLimitMode string `json:"bandwidthLimitMode,omitempty"` |
| 43 | // ProxyProtocolVersion specifies which protocol version to use. Valid |
| 44 | // values include "v1", "v2", and "". If the value is "", a protocol |
| 45 | // version will be automatically selected. By default, this value is "". |
| 46 | ProxyProtocolVersion string `json:"proxyProtocolVersion,omitempty"` |
| 47 | } |
| 48 |
| 49 | type LoadBalancerConfig struct { |
| 50 | // Group specifies which group the is a part of. The server will use |
| 51 | // this information to load balance proxies in the same group. If the value |
| 52 | // is "", this will not be in a group. |
| 53 | Group string `json:"group"` |
| 54 | // GroupKey specifies a group key, which should be the same among proxies |
| 55 | // of the same group. |
| 56 | GroupKey string `json:"groupKey,omitempty"` |
| 57 | } |
| 58 |
| 59 | type ProxyBackend struct { |
| 60 | // LocalIP specifies the IP address or host name of the backend. |
| 61 | LocalIP string `json:"localIP,omitempty"` |
| 62 | // LocalPort specifies the port of the backend. |
| 63 | LocalPort int `json:"localPort,omitempty"` |
| 64 |
| 65 | // Plugin specifies what plugin should be used for handling connections. If this value |
| 66 | // is set, the LocalIP and LocalPort values will be ignored. |
| 67 | Plugin TypedClientPluginOptions `json:"plugin,omitempty"` |
| 68 | } |
| 69 |
| 70 | // HealthCheckConfig configures health checking. This can be useful for load |
| 71 | // balancing purposes to detect and remove proxies to failing services. |
| 72 | type HealthCheckConfig struct { |
| 73 | // Type specifies what protocol to use for health checking. |
| 74 | // Valid values include "tcp", "http", and "". If this value is "", health |
| 75 | // checking will not be performed. |
| 76 | // |
| 77 | // If the type is "tcp", a connection will be attempted to the target |
| 78 | // server. If a connection cannot be established, the health check fails. |
| 79 | // |
| 80 | // If the type is "http", a GET request will be made to the endpoint |
| 81 | // specified by HealthCheckURL. If the response is not a 200, the health |
| 82 | // check fails. |
| 83 | Type string `json:"type"` // tcp | http |
| 84 | // TimeoutSeconds specifies the number of seconds to wait for a health |
| 85 | // check attempt to connect. If the timeout is reached, this counts as a |
| 86 | // health check failure. By default, this value is 3. |
| 87 | TimeoutSeconds int `json:"timeoutSeconds,omitempty"` |
| 88 | // MaxFailed specifies the number of allowed failures before the |
| 89 | // is stopped. By default, this value is 1. |
| 90 | MaxFailed int `json:"maxFailed,omitempty"` |
| 91 | // IntervalSeconds specifies the time in seconds between health |
| 92 | // checks. By default, this value is 10. |
| 93 | IntervalSeconds int `json:"intervalSeconds"` |
| 94 | // Path specifies the path to send health checks to if the |
| 95 | // health check type is "http". |
| 96 | Path string `json:"path,omitempty"` |
| 97 | // HTTPHeaders specifies the headers to send with the health request, if |
| 98 | // the health check type is "http". |
| 99 | HTTPHeaders []HTTPHeader `json:"httpHeaders,omitempty"` |
| 100 | } |
| 101 |
| 102 | func (c HealthCheckConfig) Clone() HealthCheckConfig { |
| 103 | out := c |
| 104 | out.HTTPHeaders = slices.Clone(c.HTTPHeaders) |
| 105 | return out |
| 106 | } |
| 107 |
| 108 | type DomainConfig struct { |
| 109 | CustomDomains []string `json:"customDomains,omitempty"` |
| 110 | SubDomain string `json:"subdomain,omitempty"` |
| 111 | } |
| 112 |
| 113 | func (c DomainConfig) Clone() DomainConfig { |
| 114 | out := c |
| 115 | out.CustomDomains = slices.Clone(c.CustomDomains) |
| 116 | return out |
| 117 | } |
| 118 |
| 119 | type ProxyBaseConfig struct { |
| 120 | Name string `json:"name"` |
| 121 | Type string `json:"type"` |
| 122 | // Enabled controls whether this proxy is enabled. nil or true means enabled, false means disabled. |
| 123 | // This allows individual control over each proxy, complementing the global "start" field. |
| 124 | Enabled *bool `json:"enabled,omitempty"` |
| 125 | Annotations map[string]string `json:"annotations,omitempty"` |
| 126 | Transport ProxyTransport `json:"transport,omitempty"` |
| 127 | // metadata info for each proxy |
| 128 | Metadatas map[string]string `json:"metadatas,omitempty"` |
| 129 | LoadBalancer LoadBalancerConfig `json:"loadBalancer,omitempty"` |
| 130 | HealthCheck HealthCheckConfig `json:"healthCheck,omitempty"` |
| 131 | ProxyBackend |
| 132 | } |
| 133 |
| 134 | func (c ProxyBaseConfig) Clone() ProxyBaseConfig { |
| 135 | out := c |
| 136 | out.Enabled = util.ClonePtr(c.Enabled) |
| 137 | out.Annotations = maps.Clone(c.Annotations) |
| 138 | out.Metadatas = maps.Clone(c.Metadatas) |
| 139 | out.HealthCheck = c.HealthCheck.Clone() |
| 140 | out.ProxyBackend = c.ProxyBackend.Clone() |
| 141 | return out |
| 142 | } |
| 143 |
| 144 | func (c ProxyBackend) Clone() ProxyBackend { |
| 145 | out := c |
| 146 | out.Plugin = c.Plugin.Clone() |
| 147 | return out |
| 148 | } |
| 149 |
| 150 | func (c *ProxyBaseConfig) GetBaseConfig() *ProxyBaseConfig { |
| 151 | return c |
| 152 | } |
| 153 |
| 154 | func (c *ProxyBaseConfig) Complete() { |
| 155 | c.LocalIP = util.EmptyOr(c.LocalIP, "127.0.0.1") |
| 156 | c.Transport.BandwidthLimitMode = util.EmptyOr(c.Transport.BandwidthLimitMode, types.BandwidthLimitModeClient) |
| 157 |
| 158 | if c.Plugin.ClientPluginOptions != nil { |
| 159 | c.Plugin.Complete() |
| 160 | } |
| 161 | } |
| 162 |
| 163 | func (c *ProxyBaseConfig) MarshalToMsg(m *msg.NewProxy) { |
| 164 | m.ProxyName = c.Name |
| 165 | m.ProxyType = c.Type |
| 166 | m.UseEncryption = c.Transport.UseEncryption |
| 167 | m.UseCompression = c.Transport.UseCompression |
| 168 | m.BandwidthLimit = c.Transport.BandwidthLimit.String() |
| 169 | // leave it empty for default value to reduce traffic |
| 170 | if c.Transport.BandwidthLimitMode != "client" { |
| 171 | m.BandwidthLimitMode = c.Transport.BandwidthLimitMode |
| 172 | } |
| 173 | m.Group = c.LoadBalancer.Group |
| 174 | m.GroupKey = c.LoadBalancer.GroupKey |
| 175 | m.Metas = c.Metadatas |
| 176 | m.Annotations = c.Annotations |
| 177 | } |
| 178 |
| 179 | func (c *ProxyBaseConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 180 | c.Name = m.ProxyName |
| 181 | c.Type = m.ProxyType |
| 182 | c.Transport.UseEncryption = m.UseEncryption |
| 183 | c.Transport.UseCompression = m.UseCompression |
| 184 | if m.BandwidthLimit != "" { |
| 185 | c.Transport.BandwidthLimit, _ = types.NewBandwidthQuantity(m.BandwidthLimit) |
| 186 | } |
| 187 | if m.BandwidthLimitMode != "" { |
| 188 | c.Transport.BandwidthLimitMode = m.BandwidthLimitMode |
| 189 | } |
| 190 | c.LoadBalancer.Group = m.Group |
| 191 | c.LoadBalancer.GroupKey = m.GroupKey |
| 192 | c.Metadatas = m.Metas |
| 193 | c.Annotations = m.Annotations |
| 194 | } |
| 195 |
| 196 | type TypedProxyConfig struct { |
| 197 | Type string `json:"type"` |
| 198 | ProxyConfigurer |
| 199 | } |
| 200 |
| 201 | func (c *TypedProxyConfig) UnmarshalJSON(b []byte) error { |
| 202 | configurer, err := DecodeProxyConfigurerJSON(b, DecodeOptions{}) |
| 203 | if err != nil { |
| 204 | return err |
| 205 | } |
| 206 |
| 207 | c.Type = configurer.GetBaseConfig().Type |
| 208 | c.ProxyConfigurer = configurer |
| 209 | return nil |
| 210 | } |
| 211 |
| 212 | func (c *TypedProxyConfig) MarshalJSON() ([]byte, error) { |
| 213 | return jsonx.Marshal(c.ProxyConfigurer) |
| 214 | } |
| 215 |
| 216 | type ProxyConfigurer interface { |
| 217 | Complete() |
| 218 | GetBaseConfig() *ProxyBaseConfig |
| 219 | Clone() ProxyConfigurer |
| 220 | // MarshalToMsg marshals this config into a msg.NewProxy message. This |
| 221 | // function will be called on the frpc side. |
| 222 | MarshalToMsg(*msg.NewProxy) |
| 223 | // UnmarshalFromMsg unmarshal a msg.NewProxy message into this config. |
| 224 | // This function will be called on the frps side. |
| 225 | UnmarshalFromMsg(*msg.NewProxy) |
| 226 | } |
| 227 |
| 228 | type ProxyType string |
| 229 |
| 230 | const ( |
| 231 | ProxyTypeTCP ProxyType = "tcp" |
| 232 | ProxyTypeUDP ProxyType = "udp" |
| 233 | ProxyTypeTCPMUX ProxyType = "tcpmux" |
| 234 | ProxyTypeHTTP ProxyType = "http" |
| 235 | ProxyTypeHTTPS ProxyType = "https" |
| 236 | ProxyTypeSTCP ProxyType = "stcp" |
| 237 | ProxyTypeXTCP ProxyType = "xtcp" |
| 238 | ProxyTypeSUDP ProxyType = "sudp" |
| 239 | ) |
| 240 |
| 241 | var proxyConfigTypeMap = map[ProxyType]reflect.Type{ |
| 242 | ProxyTypeTCP: reflect.TypeFor[TCPProxyConfig](), |
| 243 | ProxyTypeUDP: reflect.TypeFor[UDPProxyConfig](), |
| 244 | ProxyTypeHTTP: reflect.TypeFor[HTTPProxyConfig](), |
| 245 | ProxyTypeHTTPS: reflect.TypeFor[HTTPSProxyConfig](), |
| 246 | ProxyTypeTCPMUX: reflect.TypeFor[TCPMuxProxyConfig](), |
| 247 | ProxyTypeSTCP: reflect.TypeFor[STCPProxyConfig](), |
| 248 | ProxyTypeXTCP: reflect.TypeFor[XTCPProxyConfig](), |
| 249 | ProxyTypeSUDP: reflect.TypeFor[SUDPProxyConfig](), |
| 250 | } |
| 251 |
| 252 | func NewProxyConfigurerByType(proxyType ProxyType) ProxyConfigurer { |
| 253 | v, ok := proxyConfigTypeMap[proxyType] |
| 254 | if !ok { |
| 255 | return nil |
| 256 | } |
| 257 | pc := reflect.New(v).Interface().(ProxyConfigurer) |
| 258 | pc.GetBaseConfig().Type = string(proxyType) |
| 259 | return pc |
| 260 | } |
| 261 |
| 262 | var _ ProxyConfigurer = &TCPProxyConfig{} |
| 263 |
| 264 | type TCPProxyConfig struct { |
| 265 | ProxyBaseConfig |
| 266 |
| 267 | RemotePort int `json:"remotePort,omitempty"` |
| 268 | } |
| 269 |
| 270 | func (c *TCPProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 271 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 272 |
| 273 | m.RemotePort = c.RemotePort |
| 274 | } |
| 275 |
| 276 | func (c *TCPProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 277 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 278 |
| 279 | c.RemotePort = m.RemotePort |
| 280 | } |
| 281 |
| 282 | func (c *TCPProxyConfig) Clone() ProxyConfigurer { |
| 283 | out := *c |
| 284 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 285 | return &out |
| 286 | } |
| 287 |
| 288 | var _ ProxyConfigurer = &UDPProxyConfig{} |
| 289 |
| 290 | type UDPProxyConfig struct { |
| 291 | ProxyBaseConfig |
| 292 |
| 293 | RemotePort int `json:"remotePort,omitempty"` |
| 294 | } |
| 295 |
| 296 | func (c *UDPProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 297 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 298 |
| 299 | m.RemotePort = c.RemotePort |
| 300 | } |
| 301 |
| 302 | func (c *UDPProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 303 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 304 |
| 305 | c.RemotePort = m.RemotePort |
| 306 | } |
| 307 |
| 308 | func (c *UDPProxyConfig) Clone() ProxyConfigurer { |
| 309 | out := *c |
| 310 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 311 | return &out |
| 312 | } |
| 313 |
| 314 | var _ ProxyConfigurer = &HTTPProxyConfig{} |
| 315 |
| 316 | type HTTPProxyConfig struct { |
| 317 | ProxyBaseConfig |
| 318 | DomainConfig |
| 319 |
| 320 | Locations []string `json:"locations,omitempty"` |
| 321 | HTTPUser string `json:"httpUser,omitempty"` |
| 322 | HTTPPassword string `json:"httpPassword,omitempty"` |
| 323 | HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"` |
| 324 | RequestHeaders HeaderOperations `json:"requestHeaders,omitempty"` |
| 325 | ResponseHeaders HeaderOperations `json:"responseHeaders,omitempty"` |
| 326 | RouteByHTTPUser string `json:"routeByHTTPUser,omitempty"` |
| 327 | } |
| 328 |
| 329 | func (c *HTTPProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 330 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 331 |
| 332 | m.CustomDomains = c.CustomDomains |
| 333 | m.SubDomain = c.SubDomain |
| 334 | m.Locations = c.Locations |
| 335 | m.HostHeaderRewrite = c.HostHeaderRewrite |
| 336 | m.HTTPUser = c.HTTPUser |
| 337 | m.HTTPPwd = c.HTTPPassword |
| 338 | m.Headers = c.RequestHeaders.Set |
| 339 | m.ResponseHeaders = c.ResponseHeaders.Set |
| 340 | m.RouteByHTTPUser = c.RouteByHTTPUser |
| 341 | } |
| 342 |
| 343 | func (c *HTTPProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 344 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 345 |
| 346 | c.CustomDomains = m.CustomDomains |
| 347 | c.SubDomain = m.SubDomain |
| 348 | c.Locations = m.Locations |
| 349 | c.HostHeaderRewrite = m.HostHeaderRewrite |
| 350 | c.HTTPUser = m.HTTPUser |
| 351 | c.HTTPPassword = m.HTTPPwd |
| 352 | c.RequestHeaders.Set = m.Headers |
| 353 | c.ResponseHeaders.Set = m.ResponseHeaders |
| 354 | c.RouteByHTTPUser = m.RouteByHTTPUser |
| 355 | } |
| 356 |
| 357 | func (c *HTTPProxyConfig) Clone() ProxyConfigurer { |
| 358 | out := *c |
| 359 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 360 | out.DomainConfig = c.DomainConfig.Clone() |
| 361 | out.Locations = slices.Clone(c.Locations) |
| 362 | out.RequestHeaders = c.RequestHeaders.Clone() |
| 363 | out.ResponseHeaders = c.ResponseHeaders.Clone() |
| 364 | return &out |
| 365 | } |
| 366 |
| 367 | var _ ProxyConfigurer = &HTTPSProxyConfig{} |
| 368 |
| 369 | type HTTPSProxyConfig struct { |
| 370 | ProxyBaseConfig |
| 371 | DomainConfig |
| 372 | } |
| 373 |
| 374 | func (c *HTTPSProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 375 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 376 |
| 377 | m.CustomDomains = c.CustomDomains |
| 378 | m.SubDomain = c.SubDomain |
| 379 | } |
| 380 |
| 381 | func (c *HTTPSProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 382 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 383 |
| 384 | c.CustomDomains = m.CustomDomains |
| 385 | c.SubDomain = m.SubDomain |
| 386 | } |
| 387 |
| 388 | func (c *HTTPSProxyConfig) Clone() ProxyConfigurer { |
| 389 | out := *c |
| 390 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 391 | out.DomainConfig = c.DomainConfig.Clone() |
| 392 | return &out |
| 393 | } |
| 394 |
| 395 | type TCPMultiplexerType string |
| 396 |
| 397 | const ( |
| 398 | TCPMultiplexerHTTPConnect TCPMultiplexerType = "httpconnect" |
| 399 | ) |
| 400 |
| 401 | var _ ProxyConfigurer = &TCPMuxProxyConfig{} |
| 402 |
| 403 | type TCPMuxProxyConfig struct { |
| 404 | ProxyBaseConfig |
| 405 | DomainConfig |
| 406 |
| 407 | HTTPUser string `json:"httpUser,omitempty"` |
| 408 | HTTPPassword string `json:"httpPassword,omitempty"` |
| 409 | RouteByHTTPUser string `json:"routeByHTTPUser,omitempty"` |
| 410 | Multiplexer string `json:"multiplexer,omitempty"` |
| 411 | } |
| 412 |
| 413 | func (c *TCPMuxProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 414 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 415 |
| 416 | m.CustomDomains = c.CustomDomains |
| 417 | m.SubDomain = c.SubDomain |
| 418 | m.Multiplexer = c.Multiplexer |
| 419 | m.HTTPUser = c.HTTPUser |
| 420 | m.HTTPPwd = c.HTTPPassword |
| 421 | m.RouteByHTTPUser = c.RouteByHTTPUser |
| 422 | } |
| 423 |
| 424 | func (c *TCPMuxProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 425 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 426 |
| 427 | c.CustomDomains = m.CustomDomains |
| 428 | c.SubDomain = m.SubDomain |
| 429 | c.Multiplexer = m.Multiplexer |
| 430 | c.HTTPUser = m.HTTPUser |
| 431 | c.HTTPPassword = m.HTTPPwd |
| 432 | c.RouteByHTTPUser = m.RouteByHTTPUser |
| 433 | } |
| 434 |
| 435 | func (c *TCPMuxProxyConfig) Clone() ProxyConfigurer { |
| 436 | out := *c |
| 437 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 438 | out.DomainConfig = c.DomainConfig.Clone() |
| 439 | return &out |
| 440 | } |
| 441 |
| 442 | var _ ProxyConfigurer = &STCPProxyConfig{} |
| 443 |
| 444 | type STCPProxyConfig struct { |
| 445 | ProxyBaseConfig |
| 446 |
| 447 | Secretkey string `json:"secretKey,omitempty"` |
| 448 | AllowUsers []string `json:"allowUsers,omitempty"` |
| 449 | } |
| 450 |
| 451 | func (c *STCPProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 452 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 453 |
| 454 | m.Sk = c.Secretkey |
| 455 | m.AllowUsers = c.AllowUsers |
| 456 | } |
| 457 |
| 458 | func (c *STCPProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 459 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 460 |
| 461 | c.Secretkey = m.Sk |
| 462 | c.AllowUsers = m.AllowUsers |
| 463 | } |
| 464 |
| 465 | func (c *STCPProxyConfig) Clone() ProxyConfigurer { |
| 466 | out := *c |
| 467 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 468 | out.AllowUsers = slices.Clone(c.AllowUsers) |
| 469 | return &out |
| 470 | } |
| 471 |
| 472 | var _ ProxyConfigurer = &XTCPProxyConfig{} |
| 473 |
| 474 | type XTCPProxyConfig struct { |
| 475 | ProxyBaseConfig |
| 476 |
| 477 | Secretkey string `json:"secretKey,omitempty"` |
| 478 | AllowUsers []string `json:"allowUsers,omitempty"` |
| 479 |
| 480 | // NatTraversal configuration for NAT traversal |
| 481 | NatTraversal *NatTraversalConfig `json:"natTraversal,omitempty"` |
| 482 | } |
| 483 |
| 484 | func (c *XTCPProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 485 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 486 |
| 487 | m.Sk = c.Secretkey |
| 488 | m.AllowUsers = c.AllowUsers |
| 489 | } |
| 490 |
| 491 | func (c *XTCPProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 492 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 493 |
| 494 | c.Secretkey = m.Sk |
| 495 | c.AllowUsers = m.AllowUsers |
| 496 | } |
| 497 |
| 498 | func (c *XTCPProxyConfig) Clone() ProxyConfigurer { |
| 499 | out := *c |
| 500 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 501 | out.AllowUsers = slices.Clone(c.AllowUsers) |
| 502 | out.NatTraversal = c.NatTraversal.Clone() |
| 503 | return &out |
| 504 | } |
| 505 |
| 506 | var _ ProxyConfigurer = &SUDPProxyConfig{} |
| 507 |
| 508 | type SUDPProxyConfig struct { |
| 509 | ProxyBaseConfig |
| 510 |
| 511 | Secretkey string `json:"secretKey,omitempty"` |
| 512 | AllowUsers []string `json:"allowUsers,omitempty"` |
| 513 | } |
| 514 |
| 515 | func (c *SUDPProxyConfig) MarshalToMsg(m *msg.NewProxy) { |
| 516 | c.ProxyBaseConfig.MarshalToMsg(m) |
| 517 |
| 518 | m.Sk = c.Secretkey |
| 519 | m.AllowUsers = c.AllowUsers |
| 520 | } |
| 521 |
| 522 | func (c *SUDPProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) { |
| 523 | c.ProxyBaseConfig.UnmarshalFromMsg(m) |
| 524 |
| 525 | c.Secretkey = m.Sk |
| 526 | c.AllowUsers = m.AllowUsers |
| 527 | } |
| 528 |
| 529 | func (c *SUDPProxyConfig) Clone() ProxyConfigurer { |
| 530 | out := *c |
| 531 | out.ProxyBaseConfig = c.ProxyBaseConfig.Clone() |
| 532 | out.AllowUsers = slices.Clone(c.AllowUsers) |
| 533 | return &out |
| 534 | } |