mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
refactor environment context
This commit is contained in:
parent
6a4364f37a
commit
141cd30ee3
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
20
common/environment/envctx/env.go
Normal file
20
common/environment/envctx/env.go
Normal file
@ -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
|
||||
}
|
9
common/environment/filesystemcap/fscap.go
Normal file
9
common/environment/filesystemcap/fscap.go
Normal file
@ -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
|
||||
}
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user