github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/common/environment/rootcap_impl.go (about)

     1  package environment
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/v2fly/v2ray-core/v5/common/platform/filesystem/fsifce"
     7  	"github.com/v2fly/v2ray-core/v5/features/extension/storage"
     8  	"github.com/v2fly/v2ray-core/v5/transport/internet"
     9  	"github.com/v2fly/v2ray-core/v5/transport/internet/tagged"
    10  )
    11  
    12  func NewRootEnvImpl(ctx context.Context, transientStorage storage.ScopedTransientStorage,
    13  	systemDialer internet.SystemDialer, systemListener internet.SystemListener,
    14  ) RootEnvironment {
    15  	return &rootEnvImpl{
    16  		transientStorage: transientStorage,
    17  		systemListener:   systemListener,
    18  		systemDialer:     systemDialer,
    19  		ctx:              ctx,
    20  	}
    21  }
    22  
    23  type rootEnvImpl struct {
    24  	transientStorage storage.ScopedTransientStorage
    25  	systemDialer     internet.SystemDialer
    26  	systemListener   internet.SystemListener
    27  
    28  	ctx context.Context
    29  }
    30  
    31  func (r *rootEnvImpl) doNotImpl() {
    32  	panic("placeholder doNotImpl")
    33  }
    34  
    35  func (r *rootEnvImpl) AppEnvironment(tag string) AppEnvironment {
    36  	transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
    37  	if err != nil {
    38  		return nil
    39  	}
    40  	return &appEnvImpl{
    41  		transientStorage: transientStorage,
    42  		systemListener:   r.systemListener,
    43  		systemDialer:     r.systemDialer,
    44  		ctx:              r.ctx,
    45  	}
    46  }
    47  
    48  func (r *rootEnvImpl) ProxyEnvironment(tag string) ProxyEnvironment {
    49  	transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
    50  	if err != nil {
    51  		return nil
    52  	}
    53  	return &proxyEnvImpl{
    54  		transientStorage: transientStorage,
    55  		systemListener:   r.systemListener,
    56  		systemDialer:     r.systemDialer,
    57  		ctx:              r.ctx,
    58  	}
    59  }
    60  
    61  func (r *rootEnvImpl) DropProxyEnvironment(tag string) error {
    62  	transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
    63  	if err != nil {
    64  		return err
    65  	}
    66  	return transientStorage.DropScope(r.ctx, tag)
    67  }
    68  
    69  type appEnvImpl struct {
    70  	transientStorage storage.ScopedTransientStorage
    71  	systemDialer     internet.SystemDialer
    72  	systemListener   internet.SystemListener
    73  
    74  	ctx context.Context
    75  }
    76  
    77  func (a *appEnvImpl) RequireFeatures() interface{} {
    78  	panic("implement me")
    79  }
    80  
    81  func (a *appEnvImpl) RecordLog() interface{} {
    82  	panic("implement me")
    83  }
    84  
    85  func (a *appEnvImpl) Dialer() internet.SystemDialer {
    86  	panic("implement me")
    87  }
    88  
    89  func (a *appEnvImpl) Listener() internet.SystemListener {
    90  	panic("implement me")
    91  }
    92  
    93  func (a *appEnvImpl) OutboundDialer() tagged.DialFunc {
    94  	return internet.DialTaggedOutbound
    95  }
    96  
    97  func (a *appEnvImpl) OpenFileForReadSeek() fsifce.FileSeekerFunc {
    98  	panic("implement me")
    99  }
   100  
   101  func (a *appEnvImpl) OpenFileForRead() fsifce.FileReaderFunc {
   102  	panic("implement me")
   103  }
   104  
   105  func (a *appEnvImpl) OpenFileForWrite() fsifce.FileWriterFunc {
   106  	panic("implement me")
   107  }
   108  
   109  func (a *appEnvImpl) PersistentStorage() storage.ScopedPersistentStorage {
   110  	panic("implement me")
   111  }
   112  
   113  func (a *appEnvImpl) TransientStorage() storage.ScopedTransientStorage {
   114  	return a.transientStorage
   115  }
   116  
   117  func (a *appEnvImpl) NarrowScope(key string) (AppEnvironment, error) {
   118  	transientStorage, err := a.transientStorage.NarrowScope(a.ctx, key)
   119  	if err != nil {
   120  		return nil, err
   121  	}
   122  	return &appEnvImpl{
   123  		transientStorage: transientStorage,
   124  		systemDialer:     a.systemDialer,
   125  		systemListener:   a.systemListener,
   126  		ctx:              a.ctx,
   127  	}, nil
   128  }
   129  
   130  func (a *appEnvImpl) doNotImpl() {
   131  	panic("placeholder doNotImpl")
   132  }
   133  
   134  type proxyEnvImpl struct {
   135  	transientStorage storage.ScopedTransientStorage
   136  	systemDialer     internet.SystemDialer
   137  	systemListener   internet.SystemListener
   138  
   139  	ctx context.Context
   140  }
   141  
   142  func (p *proxyEnvImpl) RequireFeatures() interface{} {
   143  	panic("implement me")
   144  }
   145  
   146  func (p *proxyEnvImpl) RecordLog() interface{} {
   147  	panic("implement me")
   148  }
   149  
   150  func (p *proxyEnvImpl) OutboundDialer() tagged.DialFunc {
   151  	panic("implement me")
   152  }
   153  
   154  func (p *proxyEnvImpl) TransientStorage() storage.ScopedTransientStorage {
   155  	return p.transientStorage
   156  }
   157  
   158  func (p *proxyEnvImpl) NarrowScope(key string) (ProxyEnvironment, error) {
   159  	transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
   160  	if err != nil {
   161  		return nil, err
   162  	}
   163  	return &proxyEnvImpl{
   164  		transientStorage: transientStorage,
   165  		ctx:              p.ctx,
   166  	}, nil
   167  }
   168  
   169  func (p *proxyEnvImpl) NarrowScopeToTransport(key string) (TransportEnvironment, error) {
   170  	transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
   171  	if err != nil {
   172  		return nil, err
   173  	}
   174  	return &transportEnvImpl{
   175  		ctx:              p.ctx,
   176  		transientStorage: transientStorage,
   177  		systemDialer:     p.systemDialer,
   178  		systemListener:   p.systemListener,
   179  	}, nil
   180  }
   181  
   182  func (p *proxyEnvImpl) doNotImpl() {
   183  	panic("placeholder doNotImpl")
   184  }
   185  
   186  type transportEnvImpl struct {
   187  	transientStorage storage.ScopedTransientStorage
   188  	systemDialer     internet.SystemDialer
   189  	systemListener   internet.SystemListener
   190  
   191  	ctx context.Context
   192  }
   193  
   194  func (t *transportEnvImpl) RequireFeatures() interface{} {
   195  	panic("implement me")
   196  }
   197  
   198  func (t *transportEnvImpl) RecordLog() interface{} {
   199  	panic("implement me")
   200  }
   201  
   202  func (t *transportEnvImpl) Dialer() internet.SystemDialer {
   203  	return t.systemDialer
   204  }
   205  
   206  func (t *transportEnvImpl) Listener() internet.SystemListener {
   207  	return t.systemListener
   208  }
   209  
   210  func (t *transportEnvImpl) OutboundDialer() tagged.DialFunc {
   211  	panic("implement me")
   212  }
   213  
   214  func (t *transportEnvImpl) TransientStorage() storage.ScopedTransientStorage {
   215  	return t.transientStorage
   216  }
   217  
   218  func (t *transportEnvImpl) NarrowScope(key string) (TransportEnvironment, error) {
   219  	transientStorage, err := t.transientStorage.NarrowScope(t.ctx, key)
   220  	if err != nil {
   221  		return nil, err
   222  	}
   223  	return &transportEnvImpl{
   224  		ctx:              t.ctx,
   225  		transientStorage: transientStorage,
   226  	}, nil
   227  }
   228  
   229  func (t *transportEnvImpl) doNotImpl() {
   230  	panic("implement me")
   231  }