v2ray-core/proxy/testing/proxy.go

35 lines
753 B
Go
Raw Normal View History

package testing
import (
"fmt"
"github.com/v2ray/v2ray-core/proxy/internal"
)
var count = 0
func randomString() string {
count++
return fmt.Sprintf("-%d", count)
}
2016-06-14 20:54:08 +00:00
func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := internal.RegisterInboundHandlerCreator(name, creator)
2016-06-27 06:53:35 +00:00
if err != internal.ErrNameExists {
return name, err
}
}
}
2016-06-14 20:54:08 +00:00
func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := internal.RegisterOutboundHandlerCreator(name, creator)
2016-06-27 06:53:35 +00:00
if err != internal.ErrNameExists {
return name, err
}
}
}