proxy.go 795 B

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