1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-01 08:16:00 -04:00
v2fly/testing/scenarios/common.go
2016-12-16 21:39:00 +01:00

42 lines
622 B
Go

package scenarios
import (
"github.com/golang/protobuf/proto"
"sync/atomic"
"time"
"v2ray.com/core"
v2net "v2ray.com/core/common/net"
)
var (
port uint32 = 50000
)
func pickPort() v2net.Port {
return v2net.Port(atomic.AddUint32(&port, 1))
}
func InitializeServerConfig(config *core.Config) error {
err := BuildV2Ray()
if err != nil {
return err
}
configBytes, err := proto.Marshal(config)
if err != nil {
return err
}
proc := RunV2RayProtobuf(configBytes)
err = proc.Start()
if err != nil {
return err
}
time.Sleep(time.Second)
runningServers = append(runningServers, proc)
return nil
}