rootcap_impl.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. package environment
  2. import (
  3. "context"
  4. "github.com/v2fly/v2ray-core/v5/common/platform/filesystem/fsifce"
  5. "github.com/v2fly/v2ray-core/v5/features/extension/storage"
  6. "github.com/v2fly/v2ray-core/v5/transport/internet"
  7. "github.com/v2fly/v2ray-core/v5/transport/internet/tagged"
  8. )
  9. func NewRootEnvImpl(ctx context.Context, transientStorage storage.ScopedTransientStorage) RootEnvironment {
  10. return &rootEnvImpl{transientStorage: transientStorage, ctx: ctx}
  11. }
  12. type rootEnvImpl struct {
  13. transientStorage storage.ScopedTransientStorage
  14. ctx context.Context
  15. }
  16. func (r *rootEnvImpl) doNotImpl() {
  17. panic("placeholder doNotImpl")
  18. }
  19. func (r *rootEnvImpl) AppEnvironment(tag string) AppEnvironment {
  20. transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
  21. if err != nil {
  22. return nil
  23. }
  24. return &appEnvImpl{
  25. transientStorage: transientStorage,
  26. ctx: r.ctx,
  27. }
  28. }
  29. func (r *rootEnvImpl) ProxyEnvironment(tag string) ProxyEnvironment {
  30. transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
  31. if err != nil {
  32. return nil
  33. }
  34. return &proxyEnvImpl{
  35. transientStorage: transientStorage,
  36. ctx: r.ctx,
  37. }
  38. }
  39. type appEnvImpl struct {
  40. transientStorage storage.ScopedTransientStorage
  41. ctx context.Context
  42. }
  43. func (a *appEnvImpl) RequireFeatures() interface{} {
  44. panic("implement me")
  45. }
  46. func (a *appEnvImpl) RecordLog() interface{} {
  47. panic("implement me")
  48. }
  49. func (a *appEnvImpl) Dialer() internet.SystemDialer {
  50. panic("implement me")
  51. }
  52. func (a *appEnvImpl) Listener() internet.SystemListener {
  53. panic("implement me")
  54. }
  55. func (a *appEnvImpl) OutboundDialer() tagged.DialFunc {
  56. panic("implement me")
  57. }
  58. func (a *appEnvImpl) OpenFileForReadSeek() fsifce.FileSeekerFunc {
  59. panic("implement me")
  60. }
  61. func (a *appEnvImpl) OpenFileForRead() fsifce.FileReaderFunc {
  62. panic("implement me")
  63. }
  64. func (a *appEnvImpl) OpenFileForWrite() fsifce.FileWriterFunc {
  65. panic("implement me")
  66. }
  67. func (a *appEnvImpl) PersistentStorage() storage.ScopedPersistentStorage {
  68. panic("implement me")
  69. }
  70. func (a *appEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  71. return a.transientStorage
  72. }
  73. func (a *appEnvImpl) NarrowScope(key string) (AppEnvironment, error) {
  74. transientStorage, err := a.transientStorage.NarrowScope(a.ctx, key)
  75. if err != nil {
  76. return nil, err
  77. }
  78. return &appEnvImpl{
  79. transientStorage: transientStorage,
  80. ctx: a.ctx,
  81. }, nil
  82. }
  83. func (a *appEnvImpl) doNotImpl() {
  84. panic("placeholder doNotImpl")
  85. }
  86. type proxyEnvImpl struct {
  87. transientStorage storage.ScopedTransientStorage
  88. ctx context.Context
  89. }
  90. func (p *proxyEnvImpl) RequireFeatures() interface{} {
  91. panic("implement me")
  92. }
  93. func (p *proxyEnvImpl) RecordLog() interface{} {
  94. panic("implement me")
  95. }
  96. func (p *proxyEnvImpl) OutboundDialer() tagged.DialFunc {
  97. panic("implement me")
  98. }
  99. func (p *proxyEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  100. return p.transientStorage
  101. }
  102. func (p *proxyEnvImpl) NarrowScope(key string) (ProxyEnvironment, error) {
  103. transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
  104. if err != nil {
  105. return nil, err
  106. }
  107. return &proxyEnvImpl{
  108. transientStorage: transientStorage,
  109. ctx: p.ctx,
  110. }, nil
  111. }
  112. func (p *proxyEnvImpl) NarrowScopeToTransport(key string) (TransportEnvironment, error) {
  113. transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
  114. if err != nil {
  115. return nil, err
  116. }
  117. return &transportEnvImpl{
  118. ctx: p.ctx,
  119. transientStorage: transientStorage,
  120. }, nil
  121. }
  122. func (p *proxyEnvImpl) doNotImpl() {
  123. panic("placeholder doNotImpl")
  124. }
  125. type transportEnvImpl struct {
  126. transientStorage storage.ScopedTransientStorage
  127. ctx context.Context
  128. }
  129. func (t *transportEnvImpl) RequireFeatures() interface{} {
  130. panic("implement me")
  131. }
  132. func (t *transportEnvImpl) RecordLog() interface{} {
  133. panic("implement me")
  134. }
  135. func (t *transportEnvImpl) Dialer() internet.SystemDialer {
  136. panic("implement me")
  137. }
  138. func (t *transportEnvImpl) Listener() internet.SystemListener {
  139. panic("implement me")
  140. }
  141. func (t *transportEnvImpl) OutboundDialer() tagged.DialFunc {
  142. panic("implement me")
  143. }
  144. func (t *transportEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  145. return t.transientStorage
  146. }
  147. func (t *transportEnvImpl) NarrowScope(key string) (TransportEnvironment, error) {
  148. transientStorage, err := t.transientStorage.NarrowScope(t.ctx, key)
  149. if err != nil {
  150. return nil, err
  151. }
  152. return &transportEnvImpl{
  153. ctx: t.ctx,
  154. transientStorage: transientStorage,
  155. }, nil
  156. }
  157. func (t *transportEnvImpl) doNotImpl() {
  158. panic("implement me")
  159. }