rootcap_impl.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. func (r *rootEnvImpl) DropProxyEnvironment(tag string) error {
  53. transientStorage, err := r.transientStorage.NarrowScope(r.ctx, tag)
  54. if err != nil {
  55. return err
  56. }
  57. return transientStorage.DropScope(r.ctx, tag)
  58. }
  59. type appEnvImpl struct {
  60. transientStorage storage.ScopedTransientStorage
  61. systemDialer internet.SystemDialer
  62. systemListener internet.SystemListener
  63. ctx context.Context
  64. }
  65. func (a *appEnvImpl) RequireFeatures() interface{} {
  66. panic("implement me")
  67. }
  68. func (a *appEnvImpl) RecordLog() interface{} {
  69. panic("implement me")
  70. }
  71. func (a *appEnvImpl) Dialer() internet.SystemDialer {
  72. panic("implement me")
  73. }
  74. func (a *appEnvImpl) Listener() internet.SystemListener {
  75. panic("implement me")
  76. }
  77. func (a *appEnvImpl) OutboundDialer() tagged.DialFunc {
  78. return internet.DialTaggedOutbound
  79. }
  80. func (a *appEnvImpl) OpenFileForReadSeek() fsifce.FileSeekerFunc {
  81. panic("implement me")
  82. }
  83. func (a *appEnvImpl) OpenFileForRead() fsifce.FileReaderFunc {
  84. panic("implement me")
  85. }
  86. func (a *appEnvImpl) OpenFileForWrite() fsifce.FileWriterFunc {
  87. panic("implement me")
  88. }
  89. func (a *appEnvImpl) PersistentStorage() storage.ScopedPersistentStorage {
  90. panic("implement me")
  91. }
  92. func (a *appEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  93. return a.transientStorage
  94. }
  95. func (a *appEnvImpl) NarrowScope(key string) (AppEnvironment, error) {
  96. transientStorage, err := a.transientStorage.NarrowScope(a.ctx, key)
  97. if err != nil {
  98. return nil, err
  99. }
  100. return &appEnvImpl{
  101. transientStorage: transientStorage,
  102. systemDialer: a.systemDialer,
  103. systemListener: a.systemListener,
  104. ctx: a.ctx,
  105. }, nil
  106. }
  107. func (a *appEnvImpl) doNotImpl() {
  108. panic("placeholder doNotImpl")
  109. }
  110. type proxyEnvImpl struct {
  111. transientStorage storage.ScopedTransientStorage
  112. systemDialer internet.SystemDialer
  113. systemListener internet.SystemListener
  114. ctx context.Context
  115. }
  116. func (p *proxyEnvImpl) RequireFeatures() interface{} {
  117. panic("implement me")
  118. }
  119. func (p *proxyEnvImpl) RecordLog() interface{} {
  120. panic("implement me")
  121. }
  122. func (p *proxyEnvImpl) OutboundDialer() tagged.DialFunc {
  123. panic("implement me")
  124. }
  125. func (p *proxyEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  126. return p.transientStorage
  127. }
  128. func (p *proxyEnvImpl) NarrowScope(key string) (ProxyEnvironment, error) {
  129. transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
  130. if err != nil {
  131. return nil, err
  132. }
  133. return &proxyEnvImpl{
  134. transientStorage: transientStorage,
  135. ctx: p.ctx,
  136. }, nil
  137. }
  138. func (p *proxyEnvImpl) NarrowScopeToTransport(key string) (TransportEnvironment, error) {
  139. transientStorage, err := p.transientStorage.NarrowScope(p.ctx, key)
  140. if err != nil {
  141. return nil, err
  142. }
  143. return &transportEnvImpl{
  144. ctx: p.ctx,
  145. transientStorage: transientStorage,
  146. systemDialer: p.systemDialer,
  147. systemListener: p.systemListener,
  148. }, nil
  149. }
  150. func (p *proxyEnvImpl) doNotImpl() {
  151. panic("placeholder doNotImpl")
  152. }
  153. type transportEnvImpl struct {
  154. transientStorage storage.ScopedTransientStorage
  155. systemDialer internet.SystemDialer
  156. systemListener internet.SystemListener
  157. ctx context.Context
  158. }
  159. func (t *transportEnvImpl) RequireFeatures() interface{} {
  160. panic("implement me")
  161. }
  162. func (t *transportEnvImpl) RecordLog() interface{} {
  163. panic("implement me")
  164. }
  165. func (t *transportEnvImpl) Dialer() internet.SystemDialer {
  166. return t.systemDialer
  167. }
  168. func (t *transportEnvImpl) Listener() internet.SystemListener {
  169. return t.systemListener
  170. }
  171. func (t *transportEnvImpl) OutboundDialer() tagged.DialFunc {
  172. panic("implement me")
  173. }
  174. func (t *transportEnvImpl) TransientStorage() storage.ScopedTransientStorage {
  175. return t.transientStorage
  176. }
  177. func (t *transportEnvImpl) NarrowScope(key string) (TransportEnvironment, error) {
  178. transientStorage, err := t.transientStorage.NarrowScope(t.ctx, key)
  179. if err != nil {
  180. return nil, err
  181. }
  182. return &transportEnvImpl{
  183. ctx: t.ctx,
  184. transientStorage: transientStorage,
  185. }, nil
  186. }
  187. func (t *transportEnvImpl) doNotImpl() {
  188. panic("implement me")
  189. }