6
6
"fmt"
7
7
"log/slog"
8
8
"net/netip"
9
- "os"
10
- "path/filepath"
11
9
12
10
"github.com/bepass-org/warp-plus/psiphon"
13
11
"github.com/bepass-org/warp-plus/warp"
@@ -39,18 +37,6 @@ func RunWarp(ctx context.Context, l *slog.Logger, opts WarpOptions) error {
39
37
return errors .New ("must provide country for psiphon" )
40
38
}
41
39
42
- // create necessary file structures
43
- if err := makeDirs (); err != nil {
44
- return err
45
- }
46
- l .Debug ("'primary' and 'secondary' directories are ready" )
47
-
48
- // Change the current working directory to 'stuff'
49
- if err := os .Chdir ("stuff" ); err != nil {
50
- return fmt .Errorf ("error changing to 'stuff' directory: %w" , err )
51
- }
52
- l .Debug ("Changed working directory to 'stuff'" )
53
-
54
40
// create identities
55
41
if err := createPrimaryAndSecondaryIdentities (l .With ("subsystem" , "warp/account" ), opts .License ); err != nil {
56
42
return err
@@ -94,7 +80,7 @@ func RunWarp(ctx context.Context, l *slog.Logger, opts WarpOptions) error {
94
80
}
95
81
96
82
func runWarp (ctx context.Context , l * slog.Logger , bind netip.AddrPort , endpoint string ) error {
97
- conf , err := wiresocks .ParseConfig ("./primary/wgcf-profile.ini" , endpoint )
83
+ conf , err := wiresocks .ParseConfig ("./stuff/ primary/wgcf-profile.ini" , endpoint )
98
84
if err != nil {
99
85
return err
100
86
}
@@ -122,7 +108,7 @@ func runWarp(ctx context.Context, l *slog.Logger, bind netip.AddrPort, endpoint
122
108
}
123
109
124
110
func runWarpWithPsiphon (ctx context.Context , l * slog.Logger , bind netip.AddrPort , endpoint string , country string ) error {
125
- conf , err := wiresocks .ParseConfig ("./primary/wgcf-profile.ini" , endpoint )
111
+ conf , err := wiresocks .ParseConfig ("./stuff/ primary/wgcf-profile.ini" , endpoint )
126
112
if err != nil {
127
113
return err
128
114
}
@@ -157,7 +143,7 @@ func runWarpWithPsiphon(ctx context.Context, l *slog.Logger, bind netip.AddrPort
157
143
158
144
func runWarpInWarp (ctx context.Context , l * slog.Logger , bind netip.AddrPort , endpoints []string ) error {
159
145
// Run outer warp
160
- conf , err := wiresocks .ParseConfig ("./primary/wgcf-profile.ini" , endpoints [0 ])
146
+ conf , err := wiresocks .ParseConfig ("./stuff/ primary/wgcf-profile.ini" , endpoints [0 ])
161
147
if err != nil {
162
148
return err
163
149
}
@@ -181,7 +167,7 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, bind netip.AddrPort, end
181
167
}
182
168
183
169
// Run inner warp
184
- conf , err = wiresocks .ParseConfig ("./secondary/wgcf-profile.ini" , addr .String ())
170
+ conf , err = wiresocks .ParseConfig ("./stuff/ secondary/wgcf-profile.ini" , addr .String ())
185
171
if err != nil {
186
172
return err
187
173
}
@@ -208,43 +194,17 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, bind netip.AddrPort, end
208
194
209
195
func createPrimaryAndSecondaryIdentities (l * slog.Logger , license string ) error {
210
196
// make primary identity
211
- warp .UpdatePath ("./primary" )
212
- if ! warp .CheckProfileExists (license ) {
213
- err := warp .LoadOrCreateIdentity (l , license )
214
- if err != nil {
215
- return err
216
- }
217
- }
218
- // make secondary
219
- warp .UpdatePath ("./secondary" )
220
- if ! warp .CheckProfileExists (license ) {
221
- err := warp .LoadOrCreateIdentity (l , license )
222
- if err != nil {
223
- return err
224
- }
225
- }
226
- return nil
227
- }
228
-
229
- func makeDirs () error {
230
- stuffDir := "stuff"
231
- primaryDir := "primary"
232
- secondaryDir := "secondary"
233
-
234
- // Check if 'stuff' directory exists, if not create it
235
- if _ , err := os .Stat (stuffDir ); os .IsNotExist (err ) {
236
- if err := os .Mkdir (stuffDir , 0o755 ); err != nil {
237
- return fmt .Errorf ("error creating 'stuff' directory: %w" , err )
238
- }
197
+ err := warp .LoadOrCreateIdentity (l , "./stuff/primary" , license )
198
+ if err != nil {
199
+ l .Error ("couldn't load primary warp identity" )
200
+ return err
239
201
}
240
202
241
- // Create 'primary' and 'secondary' directories if they don't exist
242
- for _ , dir := range []string {primaryDir , secondaryDir } {
243
- if _ , err := os .Stat (filepath .Join (stuffDir , dir )); os .IsNotExist (err ) {
244
- if err := os .Mkdir (filepath .Join (stuffDir , dir ), 0o755 ); err != nil {
245
- return fmt .Errorf ("error creating '%s' directory: %w" , dir , err )
246
- }
247
- }
203
+ // make secondary
204
+ err = warp .LoadOrCreateIdentity (l , "./stuff/secondary" , license )
205
+ if err != nil {
206
+ l .Error ("couldn't load secondary warp identity" )
207
+ return err
248
208
}
249
209
250
210
return nil
0 commit comments