1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00

add app environment definitions

This commit is contained in:
Shelikhoo 2021-06-24 16:28:08 +01:00
parent 9d7e0d6f7a
commit d1a4b0388a
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
8 changed files with 168 additions and 2 deletions

22
common/environment/app.go Normal file
View File

@ -0,0 +1,22 @@
package environment
import (
"github.com/v2fly/v2ray-core/v4/features/extension"
)
type AppEnvironmentCapabilitySet interface {
BaseEnvironmentCapabilitySet
SystemNetworkCapabilitySet
InstanceNetworkCapabilitySet
FileSystemCapabilitySet
PersistentStorage() extension.ScopedPersistentStorage
TransientStorage() extension.ScopedTransientStorage
}
type AppEnvironment interface {
AppEnvironmentCapabilitySet
NarrowScope(key []byte) (AppEnvironment, error)
doNotImpl()
}

View File

@ -0,0 +1,41 @@
package environment
import (
"github.com/v2fly/v2ray-core/v4/common/log"
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
"github.com/v2fly/v2ray-core/v4/transport/internet"
"github.com/v2fly/v2ray-core/v4/transport/internet/tagged"
)
type BaseEnvironmentCapabilitySet interface {
FeaturesLookupCapabilitySet
LogCapabilitySet
}
type BaseEnvironment interface {
BaseEnvironmentCapabilitySet
doNotImpl()
}
type SystemNetworkCapabilitySet interface {
Dialer() internet.SystemDialer
Listener() internet.SystemListener
}
type InstanceNetworkCapabilitySet interface {
OutboundDialer() tagged.DialFunc
}
type FeaturesLookupCapabilitySet interface {
RequireFeatures(callback interface{}) error
}
type LogCapabilitySet interface {
RecordLog(msg log.Message)
}
type FileSystemCapabilitySet interface {
OpenFileForReadSeek() filesystem.FileSeekerFunc
OpenFileForRead() filesystem.FileReaderFunc
OpenFileForWrite() filesystem.FileWriterFunc
}

View File

@ -0,0 +1,17 @@
package environment
import "github.com/v2fly/v2ray-core/v4/common/log"
type ConnectionCapabilitySet interface {
ConnectionLogCapabilitySet
}
type ConnectionEnvironment interface {
ConnectionCapabilitySet
doNotImpl()
}
type ConnectionLogCapabilitySet interface {
RecordConnectionLog(msg log.Message)
}

View File

@ -0,0 +1,19 @@
package environment
import "github.com/v2fly/v2ray-core/v4/features/extension"
type ProxyEnvironmentCapabilitySet interface {
BaseEnvironmentCapabilitySet
InstanceNetworkCapabilitySet
TransientStorage() extension.ScopedTransientStorage
}
type ProxyEnvironment interface {
ProxyEnvironmentCapabilitySet
NarrowScope(key []byte) (ProxyEnvironment, error)
NarrowScopeToTransport(key []byte) (TransportEnvironment, error)
doNotImpl()
}

View File

@ -0,0 +1,18 @@
package environment
import "github.com/v2fly/v2ray-core/v4/features/extension"
type TransportEnvironmentCapacitySet interface {
BaseEnvironmentCapabilitySet
SystemNetworkCapabilitySet
InstanceNetworkCapabilitySet
TransientStorage() extension.ScopedTransientStorage
}
type TransportEnvironment interface {
TransportEnvironmentCapacitySet
NarrowScope(key []byte) (TransportEnvironment, error)
doNotImpl()
}

View File

@ -0,0 +1,35 @@
package extension
import (
"context"
"github.com/v2fly/v2ray-core/v4/features"
)
type PersistentStorageEngine interface {
features.Feature
PersistentStorageEngine()
Put(ctx context.Context, key []byte, value []byte) error
Get(ctx context.Context, key []byte) ([]byte, error)
List(ctx context.Context, keyPrefix []byte) ([][]byte, error)
}
type ScopedPersistentStorage interface {
ScopedPersistentStorageEngine()
Put(ctx context.Context, key []byte, value []byte) error
Get(ctx context.Context, key []byte) ([]byte, error)
List(ctx context.Context, keyPrefix []byte) ([][]byte, error)
ClearIfCharacteristicMismatch(ctx context.Context, characteristic []byte) error
NarrowScope(ctx context.Context, key []byte) (ScopedPersistentStorage, error)
}
type ScopedTransientStorage interface {
ScopedTransientStorage()
Put(ctx context.Context, key []byte, value interface{}) error
Get(ctx context.Context, key []byte) (interface{}, error)
List(ctx context.Context, keyPrefix []byte) ([][]byte, error)
Clear(ctx context.Context)
NarrowScope(ctx context.Context, key []byte) (ScopedPersistentStorage, error)
}

View File

@ -2,7 +2,6 @@ package cfgcommon
import (
"context"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/infra/conf/geodata"
)
@ -24,10 +23,20 @@ func (c *configureLoadingEnvironment) GetGeoLoader() geodata.Loader {
return c.geoLoader
}
type ConfigureLoadingEnvironment interface {
func (c *configureLoadingEnvironment) doNotImpl() {}
type ConfigureLoadingEnvironmentCapabilitySet interface {
GetGeoLoader() geodata.Loader
}
type ConfigureLoadingEnvironment interface {
ConfigureLoadingEnvironmentCapabilitySet
doNotImpl()
// TODO environment.BaseEnvironmentCapabilitySet
// TODO environment.FileSystemCapabilitySet
}
func NewConfigureLoadingContext(ctx context.Context) context.Context {
environment := &configureLoadingEnvironment{}
return context.WithValue(ctx, confContextKey, environment)

View File

@ -102,3 +102,8 @@ func RegisterListenerController(controller func(network, address string, fd uint
effectiveListener.controllers = append(effectiveListener.controllers, controller)
return nil
}
type SystemListener interface {
Listen(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.Listener, error)
ListenPacket(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.PacketConn, error)
}