1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-07-26 11:44:22 -04:00
v2fly/common/environment/rootcap_impl.go

253 lines
6.2 KiB
Go
Raw Normal View History

2022-02-10 22:50:39 +00:00
package environment
import (
"context"
2022-04-29 21:36:26 +01:00
2022-02-10 22:50:39 +00:00
"github.com/v2fly/v2ray-core/v5/common/platform/filesystem/fsifce"
"github.com/v2fly/v2ray-core/v5/features/extension/storage"
"github.com/v2fly/v2ray-core/v5/transport/internet"
"github.com/v2fly/v2ray-core/v5/transport/internet/tagged"
)
func NewRootEnvImpl(ctx context.Context, transientStorage storage.ScopedTransientStorage,
systemDialer internet.SystemDialer, systemListener internet.SystemListener,
filesystem FileSystemCapabilitySet, persistStorage storage.ScopedPersistentStorage,
) RootEnvironment {
return &rootEnvImpl{
transientStorage: transientStorage,
systemListener: systemListener,
systemDialer: systemDialer,
filesystem: filesystem,
persistStorage: persistStorage,
ctx: ctx,
}
2022-02-10 22:50:39 +00:00
}
type rootEnvImpl struct {
persistStorage storage.ScopedPersistentStorage
2022-02-10 22:50:39 +00:00
transientStorage storage.ScopedTransientStorage
systemDialer internet.SystemDialer
systemListener internet.SystemListener
filesystem FileSystemCapabilitySet
2022-02-10 22:50:39 +00:00
ctx context.Context
}
func (r *rootEnvImpl) doNotImpl() {
panic("placeholder doNotImpl")
}
func (r *rootEnvImpl) AppEnvironment(tag string) AppEnvironment {
transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
if err != nil {
return nil
}
persistStorage, err := r.persistStorage.NarrowScope(r.ctx, []byte(tag))
if err != nil {
return nil
}
2022-02-10 22:50:39 +00:00
return &appEnvImpl{
transientStorage: transientStorage,
persistStorage: persistStorage,
systemListener: r.systemListener,
systemDialer: r.systemDialer,
filesystem: r.filesystem,
2022-02-10 22:50:39 +00:00
ctx: r.ctx,
}
}
func (r *rootEnvImpl) ProxyEnvironment(tag string) ProxyEnvironment {
transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
if err != nil {
return nil
}
return &proxyEnvImpl{
transientStorage: transientStorage,
systemListener: r.systemListener,
systemDialer: r.systemDialer,
2022-02-10 22:50:39 +00:00
ctx: r.ctx,
}
}
2023-11-21 23:03:20 +00:00
func (r *rootEnvImpl) DropProxyEnvironment(tag string) error {
transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
if err != nil {
return err
}
return transientStorage.DropScope(r.ctx, tag)
}
2022-02-10 22:50:39 +00:00
type appEnvImpl struct {
persistStorage storage.ScopedPersistentStorage
2022-02-10 22:50:39 +00:00
transientStorage storage.ScopedTransientStorage
systemDialer internet.SystemDialer
systemListener internet.SystemListener
filesystem FileSystemCapabilitySet
2022-02-10 22:50:39 +00:00
ctx context.Context
}
func (a *appEnvImpl) RequireFeatures() interface{} {
panic("implement me")
}
func (a *appEnvImpl) RecordLog() interface{} {
panic("implement me")
}
func (a *appEnvImpl) Dialer() internet.SystemDialer {
panic("implement me")
}
func (a *appEnvImpl) Listener() internet.SystemListener {
panic("implement me")
}
func (a *appEnvImpl) OutboundDialer() tagged.DialFunc {
2023-11-21 23:03:20 +00:00
return internet.DialTaggedOutbound
2022-02-10 22:50:39 +00:00
}
func (a *appEnvImpl) OpenFileForReadSeek() fsifce.FileSeekerFunc {
return a.filesystem.OpenFileForReadSeek()
2022-02-10 22:50:39 +00:00
}
func (a *appEnvImpl) OpenFileForRead() fsifce.FileReaderFunc {
return a.filesystem.OpenFileForRead()
2022-02-10 22:50:39 +00:00
}
func (a *appEnvImpl) OpenFileForWrite() fsifce.FileWriterFunc {
return a.filesystem.OpenFileForWrite()
}
func (a *appEnvImpl) ReadDir() fsifce.FileReadDirFunc {
return a.filesystem.ReadDir()
}
func (a *appEnvImpl) RemoveFile() fsifce.FileRemoveFunc {
return a.filesystem.RemoveFile()
2022-02-10 22:50:39 +00:00
}
func (a *appEnvImpl) PersistentStorage() storage.ScopedPersistentStorage {
return a.persistStorage
2022-02-10 22:50:39 +00:00
}
func (a *appEnvImpl) TransientStorage() storage.ScopedTransientStorage {
return a.transientStorage
}
func (a *appEnvImpl) NarrowScope(key string) (AppEnvironment, error) {
transientStorage, err := a.transientStorage.NarrowScope(a.ctx, key)
if err != nil {
return nil, err
}
return &appEnvImpl{
transientStorage: transientStorage,
systemDialer: a.systemDialer,
systemListener: a.systemListener,
2022-02-10 22:50:39 +00:00
ctx: a.ctx,
}, nil
}
func (a *appEnvImpl) doNotImpl() {
panic("placeholder doNotImpl")
}
type proxyEnvImpl struct {
transientStorage storage.ScopedTransientStorage
systemDialer internet.SystemDialer
systemListener internet.SystemListener
2022-02-10 22:50:39 +00:00
ctx context.Context
}
func (p *proxyEnvImpl) RequireFeatures() interface{} {
panic("implement me")
}
func (p *proxyEnvImpl) RecordLog() interface{} {
panic("implement me")
}
func (p *proxyEnvImpl) OutboundDialer() tagged.DialFunc {
panic("implement me")
}
func (p *proxyEnvImpl) TransientStorage() storage.ScopedTransientStorage {
return p.transientStorage
}
func (p *proxyEnvImpl) NarrowScope(key string) (ProxyEnvironment, error) {
transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
if err != nil {
return nil, err
}
return &proxyEnvImpl{
transientStorage: transientStorage,
ctx: p.ctx,
}, nil
}
func (p *proxyEnvImpl) NarrowScopeToTransport(key string) (TransportEnvironment, error) {
transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
if err != nil {
return nil, err
}
return &transportEnvImpl{
ctx: p.ctx,
transientStorage: transientStorage,
2023-05-30 00:20:34 +01:00
systemDialer: p.systemDialer,
systemListener: p.systemListener,
2022-02-10 22:50:39 +00:00
}, nil
}
func (p *proxyEnvImpl) doNotImpl() {
panic("placeholder doNotImpl")
}
type transportEnvImpl struct {
transientStorage storage.ScopedTransientStorage
systemDialer internet.SystemDialer
systemListener internet.SystemListener
2022-02-10 22:50:39 +00:00
ctx context.Context
}
func (t *transportEnvImpl) RequireFeatures() interface{} {
panic("implement me")
}
func (t *transportEnvImpl) RecordLog() interface{} {
panic("implement me")
}
func (t *transportEnvImpl) Dialer() internet.SystemDialer {
2023-05-30 00:20:34 +01:00
return t.systemDialer
2022-02-10 22:50:39 +00:00
}
func (t *transportEnvImpl) Listener() internet.SystemListener {
2023-05-30 00:20:34 +01:00
return t.systemListener
2022-02-10 22:50:39 +00:00
}
func (t *transportEnvImpl) OutboundDialer() tagged.DialFunc {
Add TLSMirror looks like TLS censorship resistant transport protocol as a developer preview transport (#3437) * Add tlsmirror server processing routine * Add tlsmirror server processing routine: generated * Add tlsmirror server handshake capture * it runs version~ * add draining copy for handshake * refactor out base tls mirror connection * tls mirror server side base * add random field extraction * add tls like encryption * add tls like encryption (generated) * add server side implementation for tlsmirror * apply coding style: tlsmirror * fix typo in mirrortls mirror crypto * add client initial implementation for tls mirror * add traffic generator implementation for tlsmirror * add client processing of traffic generator originated traffic * add embedded traffic generator support to mirrortls client * override security setting of traffic generator if appropriate * override security setting of traffic generator if appropriate * apply request wait time for traffic generator * add unsafe keyword required for linkname * fix outbound manager registration for traffic ingress at tlsmirror client * initial works at sticking packets together * fix traffic generator's traffic goto logic * fix get client and server random * fix applying primary key * fix log error handling for handshake random retrieval * fix nonce generation and key derivation logic * fix: add readPipe channel to client and server connection handlers * fix: use detached context for persistent mirror TLS dialer * fix: ensure proper closure of connections on context cancellation * fix: proper detection of traffic generator originated connection wait for connection ready before sending payload * fix coding style
2025-07-03 11:33:16 +01:00
return tagged.Dialer
2022-02-10 22:50:39 +00:00
}
func (t *transportEnvImpl) TransientStorage() storage.ScopedTransientStorage {
return t.transientStorage
}
func (t *transportEnvImpl) NarrowScope(key string) (TransportEnvironment, error) {
transientStorage, err := t.transientStorage.NarrowScope(t.ctx, key)
if err != nil {
return nil, err
}
return &transportEnvImpl{
ctx: t.ctx,
transientStorage: transientStorage,
}, nil
}
func (t *transportEnvImpl) doNotImpl() {
panic("implement me")
}