stcp.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 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 proxy
  15. import (
  16. "golang.org/x/time/rate"
  17. "github.com/fatedier/frp/pkg/config"
  18. )
  19. type STCPProxy struct {
  20. *BaseProxy
  21. cfg *config.STCPProxyConf
  22. }
  23. func (pxy *STCPProxy) Run() (remoteAddr string, err error) {
  24. xl := pxy.xl
  25. allowUsers := pxy.cfg.AllowUsers
  26. // if allowUsers is empty, only allow same user from proxy
  27. if len(allowUsers) == 0 {
  28. allowUsers = []string{pxy.GetUserInfo().User}
  29. }
  30. listener, errRet := pxy.rc.VisitorManager.Listen(pxy.GetName(), pxy.cfg.Sk, allowUsers)
  31. if errRet != nil {
  32. err = errRet
  33. return
  34. }
  35. pxy.listeners = append(pxy.listeners, listener)
  36. xl.Info("stcp proxy custom listen success")
  37. pxy.startListenHandler(pxy, HandleUserTCPConnection)
  38. return
  39. }
  40. func (pxy *STCPProxy) GetConf() config.ProxyConf {
  41. return pxy.cfg
  42. }
  43. func (pxy *STCPProxy) GetLimiter() *rate.Limiter {
  44. return pxy.limiter
  45. }
  46. func (pxy *STCPProxy) Close() {
  47. pxy.BaseProxy.Close()
  48. pxy.rc.VisitorManager.CloseListener(pxy.GetName())
  49. }