1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-02 17:27:50 -04:00
v2fly/proxy/testing/proxy.go

35 lines
797 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)
}
func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundConnectionHandlerCreator) (string, error) {
for {
name := prefix + randomString()
2016-01-02 17:08:36 -05:00
err := internal.RegisterInboundConnectionHandlerFactory(name, creator)
if err != internal.ErrorNameExists {
return name, err
}
}
}
func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundConnectionHandlerCreator) (string, error) {
for {
name := prefix + randomString()
2016-01-02 17:08:36 -05:00
err := internal.RegisterOutboundConnectionHandlerFactory(name, creator)
if err != internal.ErrorNameExists {
return name, err
}
}
}