mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 23:06:30 -05:00
42 lines
622 B
Go
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
|
|
}
|