rootcap_impl.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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,
  10. systemDialer internet.SystemDialer, systemListener internet.SystemListener,
  11. ) RootEnvironment {
  12. return &rootEnvImpl{
  13. transientStorage: transientStorage,
  14. systemListener: systemListener,
  15. systemDialer: systemDialer,
  16. ctx: ctx,
  17. }
  18. }
  19. type rootEnvImpl struct {
  20. transientStorage storage.ScopedTransientStorage
  21. systemDialer internet.SystemDialer
  22. systemListener internet.SystemListener
  23. ctx context.Context
  24. }
  25. func (r *rootEnvImpl) doNotImpl() {
  26. panic("placeholder doNotImpl")
  27. }
  28. func (r *rootEnvImpl) AppEnvironment(tag string) AppEnvironment {
  29. transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
  30. if err != nil {
  31. return nil
  32. }
  33. return &appEnvImpl{
  34. transientStorage: transientStorage,
  35. systemListener: r.systemListener,
  36. systemDialer: r.systemDialer,
  37. ctx: r.ctx,
  38. }
  39. }
  40. func (r *rootEnvImpl) ProxyEnvironment(tag string) ProxyEnvironment {
  41. transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
  42. if err != nil {
  43. return nil
  44. }
  45. return &proxyEnvImpl{
  46. transientStorage: transientStorage,
  47. systemListener: r.systemListener,
  48. systemDialer: r.systemDialer,
  49. ctx: r.ctx,
  50. }
  51. }
  52. type appEnvImpl struct {
  53. transientStorage storage.ScopedTransientStorage
  54. systemDialer internet.SystemDialer
  55. systemListener internet.SystemListener
  56. ctx context.Context
  57. }
  58. func (a *appEnvImpl) RequireFeatures() interface{} {
  59. panic("implement me")
  60. }
  61. func (a *appEnvImpl) RecordLog() interface{} {
  62. panic("implement me")
  63. }
  64. func (a *appEnvImpl) Dialer() internet.SystemDialer {
  65. panic("implement me")
  66. }
  67. func (a *appEnvImpl) Listener() internet.SystemListener {
  68. panic("implement me")
  69. }
  70. func (a *appEnvImpl) OutboundDialer() tagged.DialFunc {
  71. panic("implement me")
  72. }
  73. func (a *appEnvImpl) OpenFileForReadSeek() fsifce.FileSeekerFunc {
  74. panic("implement me")
  75. }
  76. func (a *appEnvImpl) OpenFileForRead() fsifce.FileReaderFunc {
  77. panic("implement me")
  78. }
  79. func (a *appEnvImpl) OpenFileForWrite() fsifce.FileWriterFunc {
  80. panic("implement me")
  81. }
  82. func (a *appEnvImpl) PersistentStorage() storage.ScopedPersistentStorage {
  83. panic("implement me")
  84. }
  85. func (a *appEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  86. return a.transientStorage
  87. }
  88. func (a *appEnvImpl) NarrowScope(key string) (AppEnvironment, error) {
  89. transientStorage, err := a.transientStorage.NarrowScope(a.ctx, key)
  90. if err != nil {
  91. return nil, err
  92. }
  93. return &appEnvImpl{
  94. transientStorage: transientStorage,
  95. systemDialer: a.systemDialer,
  96. systemListener: a.systemListener,
  97. ctx: a.ctx,
  98. }, nil
  99. }
  100. func (a *appEnvImpl) doNotImpl() {
  101. panic("placeholder doNotImpl")
  102. }
  103. type proxyEnvImpl struct {
  104. transientStorage storage.ScopedTransientStorage
  105. systemDialer internet.SystemDialer
  106. systemListener internet.SystemListener
  107. ctx context.Context
  108. }
  109. func (p *proxyEnvImpl) RequireFeatures() interface{} {
  110. panic("implement me")
  111. }
  112. func (p *proxyEnvImpl) RecordLog() interface{} {
  113. panic("implement me")
  114. }
  115. func (p *proxyEnvImpl) OutboundDialer() tagged.DialFunc {
  116. panic("implement me")
  117. }
  118. func (p *proxyEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  119. return p.transientStorage
  120. }
  121. func (p *proxyEnvImpl) NarrowScope(key string) (ProxyEnvironment, error) {
  122. transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
  123. if err != nil {
  124. return nil, err
  125. }
  126. return &proxyEnvImpl{
  127. transientStorage: transientStorage,
  128. ctx: p.ctx,
  129. }, nil
  130. }
  131. func (p *proxyEnvImpl) NarrowScopeToTransport(key string) (TransportEnvironment, error) {
  132. transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
  133. if err != nil {
  134. return nil, err
  135. }
  136. return &transportEnvImpl{
  137. ctx: p.ctx,
  138. transientStorage: transientStorage,
  139. systemDialer: p.systemDialer,
  140. systemListener: p.systemListener,
  141. }, nil
  142. }
  143. func (p *proxyEnvImpl) doNotImpl() {
  144. panic("placeholder doNotImpl")
  145. }
  146. type transportEnvImpl struct {
  147. transientStorage storage.ScopedTransientStorage
  148. systemDialer internet.SystemDialer
  149. systemListener internet.SystemListener
  150. ctx context.Context
  151. }
  152. func (t *transportEnvImpl) RequireFeatures() interface{} {
  153. panic("implement me")
  154. }
  155. func (t *transportEnvImpl) RecordLog() interface{} {
  156. panic("implement me")
  157. }
  158. func (t *transportEnvImpl) Dialer() internet.SystemDialer {
  159. return t.systemDialer
  160. }
  161. func (t *transportEnvImpl) Listener() internet.SystemListener {
  162. return t.systemListener
  163. }
  164. func (t *transportEnvImpl) OutboundDialer() tagged.DialFunc {
  165. panic("implement me")
  166. }
  167. func (t *transportEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  168. return t.transientStorage
  169. }
  170. func (t *transportEnvImpl) NarrowScope(key string) (TransportEnvironment, error) {
  171. transientStorage, err := t.transientStorage.NarrowScope(t.ctx, key)
  172. if err != nil {
  173. return nil, err
  174. }
  175. return &transportEnvImpl{
  176. ctx: t.ctx,
  177. transientStorage: transientStorage,
  178. }, nil
  179. }
  180. func (t *transportEnvImpl) doNotImpl() {
  181. panic("implement me")
  182. }