Skip to content

Commit

Permalink
feat: parse timeout and deadline from string
Browse files Browse the repository at this point in the history
  • Loading branch information
juev committed Dec 29, 2023
1 parent 5d71b91 commit b7d5135
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func main() {
flag.IntVarP(&poolSize, "num_relays", "n", 100, `The number of concurrent relays tested.`)
flag.IntVarP(&goal, "working_relay_num_goal", "g", 5, `Test until at least this number of working relays are found`)
flag.IntVarP(&timeout, "timeout", "t", 1, `Socket connection timeout`)
flag.StringVarP(&timeoutStr, "timeout", "t", "200ms", `Socket connection timeout`)
flag.StringVarP(&outfile, "outfile", "o", "", `Output reachable relays to file`)
flag.BoolVar(&torrc, "torrc", false, `Output reachable relays in torrc format (with "Bridge" prefix)`)
flag.StringArrayVarP(&urls, "url", "u", []string{}, `Preferred alternative URL for onionoo relay list. Could be used multiple times.`)
Expand All @@ -22,25 +22,33 @@ func main() {
flag.BoolVarP(&ipv6, "ipv6", "6", false, `Use ipv6 only nodes`)
flag.BoolVarP(&jsonRelays, "json", "j", false, `Get available relays in json format`)
flag.BoolVarP(&silent, "silent", "s", false, `Silent mode`)
flag.IntVarP(&deadline, "deadline", "d", 1, `The deadline of program execution (in minutes)`)
flag.StringVarP(&deadlineStr, "deadline", "d", "1m", `The deadline of program execution`)
flag.Usage = usage
flag.Parse()

if timeout < 1 {
timeout = 1
timeout, err := time.ParseDuration(timeoutStr)
if err != nil {
color.Errorf("cannot parse timeout duration: %s\n", err)
os.Exit(1)
}

deadline, err := time.ParseDuration(deadlineStr)
if err != nil {
color.Errorf("cannot parse deadline duration: %s\n", err)
os.Exit(1)
}

sc := scanner.New(
poolSize,
goal,
time.Duration(timeout)*time.Second,
timeout,
outfile,
urls,
port,
ipv4,
ipv6,
silent,
time.Duration(deadline)*time.Minute,
deadline,
)

var prefix string
Expand Down
4 changes: 2 additions & 2 deletions cmd/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var (
// Test until at least this number of working relays are found. default=5
goal int
// Socket connection timeout. default=1s
timeout int
timeoutStr string
// Output reachable relays to file. default=sys.stdout
outfile string
// Output reachable relays in torrc format (with "Bridge" prefix)
Expand All @@ -23,5 +23,5 @@ var (
// Silent mode
silent bool
// Deadline
deadline int
deadlineStr string
)

0 comments on commit b7d5135

Please sign in to comment.