proxy.go 822 B

1234567891011121314151617181920212223242526272829303132333435
  1. package testing
  2. import (
  3. "fmt"
  4. "github.com/v2ray/v2ray-core/proxy"
  5. "github.com/v2ray/v2ray-core/proxy/internal"
  6. )
  7. var count = 0
  8. func randomString() string {
  9. count++
  10. return fmt.Sprintf("-%d", count)
  11. }
  12. func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundConnectionHandlerCreator) (string, error) {
  13. for {
  14. name := prefix + randomString()
  15. err := proxy.RegisterInboundConnectionHandlerFactory(name, creator)
  16. if err != proxy.ErrorNameExists {
  17. return name, err
  18. }
  19. }
  20. }
  21. func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundConnectionHandlerCreator) (string, error) {
  22. for {
  23. name := prefix + randomString()
  24. err := proxy.RegisterOutboundConnectionHandlerFactory(name, creator)
  25. if err != proxy.ErrorNameExists {
  26. return name, err
  27. }
  28. }
  29. }