proxy.go 753 B

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