diff --git a/common/environment/app.go b/common/environment/app.go index 2b786febd..b387c304f 100644 --- a/common/environment/app.go +++ b/common/environment/app.go @@ -1,7 +1,7 @@ package environment import ( - "github.com/v2fly/v2ray-core/v4/features/extension" + "github.com/v2fly/v2ray-core/v4/features/extension/storage" ) type AppEnvironmentCapabilitySet interface { @@ -10,8 +10,8 @@ type AppEnvironmentCapabilitySet interface { InstanceNetworkCapabilitySet FileSystemCapabilitySet - PersistentStorage() extension.ScopedPersistentStorage - TransientStorage() extension.ScopedTransientStorage + PersistentStorage() storage.ScopedPersistentStorage + TransientStorage() storage.ScopedTransientStorage } type AppEnvironment interface { diff --git a/common/environment/base.go b/common/environment/base.go index 804d3b257..5635a2014 100644 --- a/common/environment/base.go +++ b/common/environment/base.go @@ -1,8 +1,8 @@ package environment import ( + "github.com/v2fly/v2ray-core/v4/common/environment/filesystemcap" "github.com/v2fly/v2ray-core/v4/common/log" - "github.com/v2fly/v2ray-core/v4/common/platform/filesystem/fsifce" "github.com/v2fly/v2ray-core/v4/transport/internet" "github.com/v2fly/v2ray-core/v4/transport/internet/tagged" ) @@ -35,7 +35,5 @@ type LogCapabilitySet interface { } type FileSystemCapabilitySet interface { - OpenFileForReadSeek() fsifce.FileSeekerFunc - OpenFileForRead() fsifce.FileReaderFunc - OpenFileForWrite() fsifce.FileWriterFunc + filesystemcap.FileSystemCapabilitySet } diff --git a/common/environment/envctx/env.go b/common/environment/envctx/env.go new file mode 100644 index 000000000..c95181e80 --- /dev/null +++ b/common/environment/envctx/env.go @@ -0,0 +1,20 @@ +package envctx + +import "context" + +type environmentContextKey int + +const ( + environmentKey environmentContextKey = iota +) + +func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context { + return context.WithValue(ctx, environmentKey, environment) +} + +func EnvironmentFromContext(ctx context.Context) interface{} { + if environment, ok := ctx.Value(environmentKey).(interface{}); ok { + return environment + } + return nil +} diff --git a/common/environment/filesystemcap/fscap.go b/common/environment/filesystemcap/fscap.go new file mode 100644 index 000000000..a08dccd22 --- /dev/null +++ b/common/environment/filesystemcap/fscap.go @@ -0,0 +1,9 @@ +package filesystemcap + +import "github.com/v2fly/v2ray-core/v4/common/platform/filesystem/fsifce" + +type FileSystemCapabilitySet interface { + OpenFileForReadSeek() fsifce.FileSeekerFunc + OpenFileForRead() fsifce.FileReaderFunc + OpenFileForWrite() fsifce.FileWriterFunc +} diff --git a/common/environment/proxy.go b/common/environment/proxy.go index 483cea332..d00b2c1e8 100644 --- a/common/environment/proxy.go +++ b/common/environment/proxy.go @@ -1,12 +1,14 @@ package environment -import "github.com/v2fly/v2ray-core/v4/features/extension" +import ( + "github.com/v2fly/v2ray-core/v4/features/extension/storage" +) type ProxyEnvironmentCapabilitySet interface { BaseEnvironmentCapabilitySet InstanceNetworkCapabilitySet - TransientStorage() extension.ScopedTransientStorage + TransientStorage() storage.ScopedTransientStorage } type ProxyEnvironment interface { diff --git a/common/environment/transport.go b/common/environment/transport.go index 180d9ff47..9fa109eab 100644 --- a/common/environment/transport.go +++ b/common/environment/transport.go @@ -1,13 +1,15 @@ package environment -import "github.com/v2fly/v2ray-core/v4/features/extension" +import ( + "github.com/v2fly/v2ray-core/v4/features/extension/storage" +) type TransportEnvironmentCapacitySet interface { BaseEnvironmentCapabilitySet SystemNetworkCapabilitySet InstanceNetworkCapabilitySet - TransientStorage() extension.ScopedTransientStorage + TransientStorage() storage.ScopedTransientStorage } type TransportEnvironment interface { diff --git a/common/session/context.go b/common/session/context.go index bc9ef3a70..2e43b9205 100644 --- a/common/session/context.go +++ b/common/session/context.go @@ -15,7 +15,6 @@ const ( sockoptSessionKey trackedConnectionErrorKey handlerSessionKey - environmentKey ) // ContextWithID returns a new context with the given ID. @@ -134,14 +133,3 @@ func SubmitOutboundErrorToOriginator(ctx context.Context, err error) { func TrackedConnectionError(ctx context.Context, tracker TrackedRequestErrorFeedback) context.Context { return context.WithValue(ctx, trackedConnectionErrorKey, tracker) } - -func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context { - return context.WithValue(ctx, environmentKey, environment) -} - -func EnvironmentFromContext(ctx context.Context) interface{} { - if environment, ok := ctx.Value(environmentKey).(interface{}); ok { - return environment - } - return nil -}