id of v2ray instance

This commit is contained in:
Darien Raymond 2018-01-17 19:09:32 +01:00
parent 630a76d06a
commit fbfbbb8841
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"v2ray.com/core/common"
"v2ray.com/core/common/uuid"
)
// Server is an instance of V2Ray. At any time, there must be at most one Server instance running.
@ -28,13 +29,16 @@ type Instance struct {
ohm syncOutboundHandlerManager
features []Feature
id uuid.UUID
}
// New returns a new V2Ray instance based on given configuration.
// The instance is not started at this point.
// To make sure V2Ray instance works properly, the config must contain one Dispatcher, one InboundHandlerManager and one OutboundHandlerManager. Other features are optional.
func New(config *Config) (*Instance, error) {
var server = new(Instance)
var server = &Instance{
id: *(uuid.New()),
}
if err := config.Transport.Apply(); err != nil {
return nil, err
@ -83,6 +87,11 @@ func New(config *Config) (*Instance, error) {
return server, nil
}
// ID returns an unique ID for this V2Ray instance.
func (s *Instance) ID() uuid.UUID {
return s.id
}
// Close shutdown the V2Ray instance.
func (s *Instance) Close() {
for _, f := range s.features {