Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config file #44

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func RunWarp(ctx context.Context, l *slog.Logger, opts WarpOptions) error {
endpoints := []string{opts.Endpoint, opts.Endpoint}

if opts.Scan != nil {
res, err := wiresocks.RunScan(ctx, *opts.Scan)
res, err := wiresocks.RunScan(ctx, l, *opts.Scan)
if err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions example_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"verbose": false,
"bind": "127.0.0.1:8086",
"endpoint": "",
"key": "",
"gool": false,
"cfon": false,
"country": "DE",
"scan": true,
"rtt": "1000ms"
}
2 changes: 1 addition & 1 deletion ipscanner/internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewScannerEngine(opts *statute.ScannerOptions) *Engine {
ipQueue: queue,
ping: p.DoPing,
generator: iterator.NewIterator(opts),
log: opts.Logger.With(slog.String("subsystem", "engine")),
log: opts.Logger.With(slog.String("subsystem", "scanner/engine")),
}
}

Expand Down
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/peterbourgon/ff/v4"
"github.com/peterbourgon/ff/v4/ffhelp"
"github.com/peterbourgon/ff/v4/ffjson"
)

var psiphonCountries = []string{
Expand Down Expand Up @@ -66,12 +67,17 @@ func main() {
gool = fs.BoolLong("gool", "enable gool mode (warp in warp)")
psiphon = fs.BoolLong("cfon", "enable psiphon mode (must provide country as well)")
country = fs.StringEnumLong("country", fmt.Sprintf("psiphon country code (valid values: %s)", psiphonCountries), psiphonCountries...)
scan = fs.BoolLong("scan", "enable warp scanning (experimental)")
scan = fs.BoolLong("scan", "enable warp scanning")
rtt = fs.DurationLong("rtt", 1000*time.Millisecond, "scanner rtt limit")
_ = fs.String('c', "config", "", "path to config file")
)

// Config file and envvars can be added through ff later
err := ff.Parse(fs, os.Args[1:])
err := ff.Parse(
fs,
os.Args[1:],
ff.WithConfigFileFlag("config"),
ff.WithConfigFileParser(ffjson.Parse),
)
switch {
case errors.Is(err, ff.ErrHelp):
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs))
Expand Down
4 changes: 3 additions & 1 deletion wiresocks/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"time"

"github.com/bepass-org/warp-plus/ipscanner"
Expand All @@ -17,7 +18,7 @@ type ScanOptions struct {
MaxRTT time.Duration
}

func RunScan(ctx context.Context, opts ScanOptions) (result []ipscanner.IPInfo, err error) {
func RunScan(ctx context.Context, l *slog.Logger, opts ScanOptions) (result []ipscanner.IPInfo, err error) {
cfg, err := ini.Load("./primary/wgcf-profile.ini")
if err != nil {
return nil, fmt.Errorf("failed to read file: %w", err)
Expand All @@ -31,6 +32,7 @@ func RunScan(ctx context.Context, opts ScanOptions) (result []ipscanner.IPInfo,

// new scanner
scanner := ipscanner.NewScanner(
ipscanner.WithLogger(l.With(slog.String("subsystem", "scanner"))),
ipscanner.WithWarpPing(),
ipscanner.WithWarpPrivateKey(privateKey),
ipscanner.WithWarpPeerPublicKey(publicKey),
Expand Down
Loading