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:
parent
9d7e0d6f7a
commit
d1a4b0388a
22
common/environment/app.go
Normal file
22
common/environment/app.go
Normal 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()
|
||||
}
|
41
common/environment/base.go
Normal file
41
common/environment/base.go
Normal 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
|
||||
}
|
17
common/environment/connection.go
Normal file
17
common/environment/connection.go
Normal 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)
|
||||
}
|
19
common/environment/proxy.go
Normal file
19
common/environment/proxy.go
Normal 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()
|
||||
}
|
18
common/environment/transport.go
Normal file
18
common/environment/transport.go
Normal 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()
|
||||
}
|
35
features/extension/storage.go
Normal file
35
features/extension/storage.go
Normal 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)
|
||||
}
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user