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