mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
refactor environment context
This commit is contained in:
parent
6a4364f37a
commit
141cd30ee3
@ -1,7 +1,7 @@
|
|||||||
package environment
|
package environment
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2fly/v2ray-core/v4/features/extension"
|
"github.com/v2fly/v2ray-core/v4/features/extension/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppEnvironmentCapabilitySet interface {
|
type AppEnvironmentCapabilitySet interface {
|
||||||
@ -10,8 +10,8 @@ type AppEnvironmentCapabilitySet interface {
|
|||||||
InstanceNetworkCapabilitySet
|
InstanceNetworkCapabilitySet
|
||||||
FileSystemCapabilitySet
|
FileSystemCapabilitySet
|
||||||
|
|
||||||
PersistentStorage() extension.ScopedPersistentStorage
|
PersistentStorage() storage.ScopedPersistentStorage
|
||||||
TransientStorage() extension.ScopedTransientStorage
|
TransientStorage() storage.ScopedTransientStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppEnvironment interface {
|
type AppEnvironment interface {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package environment
|
package environment
|
||||||
|
|
||||||
import (
|
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/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"
|
||||||
"github.com/v2fly/v2ray-core/v4/transport/internet/tagged"
|
"github.com/v2fly/v2ray-core/v4/transport/internet/tagged"
|
||||||
)
|
)
|
||||||
@ -35,7 +35,5 @@ type LogCapabilitySet interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FileSystemCapabilitySet interface {
|
type FileSystemCapabilitySet interface {
|
||||||
OpenFileForReadSeek() fsifce.FileSeekerFunc
|
filesystemcap.FileSystemCapabilitySet
|
||||||
OpenFileForRead() fsifce.FileReaderFunc
|
|
||||||
OpenFileForWrite() fsifce.FileWriterFunc
|
|
||||||
}
|
}
|
||||||
|
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
|
package environment
|
||||||
|
|
||||||
import "github.com/v2fly/v2ray-core/v4/features/extension"
|
import (
|
||||||
|
"github.com/v2fly/v2ray-core/v4/features/extension/storage"
|
||||||
|
)
|
||||||
|
|
||||||
type ProxyEnvironmentCapabilitySet interface {
|
type ProxyEnvironmentCapabilitySet interface {
|
||||||
BaseEnvironmentCapabilitySet
|
BaseEnvironmentCapabilitySet
|
||||||
InstanceNetworkCapabilitySet
|
InstanceNetworkCapabilitySet
|
||||||
|
|
||||||
TransientStorage() extension.ScopedTransientStorage
|
TransientStorage() storage.ScopedTransientStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProxyEnvironment interface {
|
type ProxyEnvironment interface {
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package environment
|
package environment
|
||||||
|
|
||||||
import "github.com/v2fly/v2ray-core/v4/features/extension"
|
import (
|
||||||
|
"github.com/v2fly/v2ray-core/v4/features/extension/storage"
|
||||||
|
)
|
||||||
|
|
||||||
type TransportEnvironmentCapacitySet interface {
|
type TransportEnvironmentCapacitySet interface {
|
||||||
BaseEnvironmentCapabilitySet
|
BaseEnvironmentCapabilitySet
|
||||||
SystemNetworkCapabilitySet
|
SystemNetworkCapabilitySet
|
||||||
InstanceNetworkCapabilitySet
|
InstanceNetworkCapabilitySet
|
||||||
|
|
||||||
TransientStorage() extension.ScopedTransientStorage
|
TransientStorage() storage.ScopedTransientStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransportEnvironment interface {
|
type TransportEnvironment interface {
|
||||||
|
@ -15,7 +15,6 @@ const (
|
|||||||
sockoptSessionKey
|
sockoptSessionKey
|
||||||
trackedConnectionErrorKey
|
trackedConnectionErrorKey
|
||||||
handlerSessionKey
|
handlerSessionKey
|
||||||
environmentKey
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContextWithID returns a new context with the given ID.
|
// 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 {
|
func TrackedConnectionError(ctx context.Context, tracker TrackedRequestErrorFeedback) context.Context {
|
||||||
return context.WithValue(ctx, trackedConnectionErrorKey, tracker)
|
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