Skip to content

Commit

Permalink
Limit redraw interval to greater than 100ms
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Jun 1, 2021
1 parent c3cd8ae commit d3e563b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ brew install nakabonne/ali/ali
**Via APT**

```bash
wget https://github.com/nakabonne/ali/releases/download/v0.6.1/ali_0.6.1_linux_amd64.deb
apt install ./ali_0.6.1_linux_amd64.deb
wget https://github.com/nakabonne/ali/releases/download/v0.7.0/ali_0.7.0_linux_amd64.deb
apt install ./ali_0.7.0_linux_amd64.deb
```

**Via RPM**

```bash
rpm -ivh https://github.com/nakabonne/ali/releases/download/v0.6.1/ali_0.6.1_linux_amd64.rpm
rpm -ivh https://github.com/nakabonne/ali/releases/download/v0.7.0/ali_0.7.0_linux_amd64.rpm
```

**Via Pacman**
Expand Down
13 changes: 8 additions & 5 deletions gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import (
)

const (
// How often termdash redraws the screen.
DefaultRedrawInterval = 250 * time.Millisecond
DefaultQueryRange = 30 * time.Second
DefaultRedrawInterval = 250 * time.Millisecond
minRedrawInterval = 100 * time.Millisecond
rootID = "root"
chartID = "chart"
)

type Option struct {
type Options struct {
RedrawInternal time.Duration
QueryRange time.Duration
}

type runner func(ctx context.Context, t terminalapi.Terminal, c *container.Container, opts ...termdash.Option) error

func Run(targetURL string, storage storage.Reader, attacker attacker.Attacker, opts Option) error {
func Run(targetURL string, storage storage.Reader, attacker attacker.Attacker, opts Options) error {
var (
t terminalapi.Terminal
err error
Expand All @@ -51,7 +51,7 @@ func Run(targetURL string, storage storage.Reader, attacker attacker.Attacker, o
return run(t, termdash.Run, targetURL, storage, attacker, opts)
}

func run(t terminalapi.Terminal, r runner, targetURL string, storage storage.Reader, a attacker.Attacker, opts Option) error {
func run(t terminalapi.Terminal, r runner, targetURL string, storage storage.Reader, a attacker.Attacker, opts Options) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand All @@ -77,6 +77,9 @@ func run(t terminalapi.Terminal, r runner, targetURL string, storage storage.Rea
if opts.RedrawInternal == 0 {
opts.RedrawInternal = DefaultRedrawInterval
}
if opts.RedrawInternal < minRedrawInterval {
return fmt.Errorf("redrawInterval must be greater than %s", minRedrawInterval)
}

d := &drawer{
queryRange: opts.QueryRange,
Expand Down
2 changes: 1 addition & 1 deletion gui/gui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := run(&termbox.Terminal{}, tt.runner, "", &storage.FakeStorage{}, &attacker.FakeAttacker{}, Option{})
err := run(&termbox.Terminal{}, tt.runner, "", &storage.FakeStorage{}, &attacker.FakeAttacker{}, Options{})
assert.Equal(t, tt.wantErr, err != nil)
})
}
Expand Down
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func parseFlags(stdout, stderr io.Writer) (*cli, error) {
//flagSet.StringVar(&c.buckets, "buckets", "", "Histogram buckets; comma-separated list.")
flagSet.StringVar(&c.resolvers, "resolvers", "", "Custom DNS resolver addresses; comma-separated list.")
flagSet.DurationVar(&c.queryRange, "query-range", gui.DefaultQueryRange, "The results within the given time range will be drawn on the charts")
flagSet.DurationVar(&c.redrawInterval, "redraw-interval", gui.DefaultRedrawInterval, "The time interval to redraw charts")
flagSet.DurationVar(&c.redrawInterval, "redraw-interval", gui.DefaultRedrawInterval, "Specify how often it redraws the screen")
flagSet.Usage = c.usage
if err := flagSet.Parse(os.Args[1:]); err != nil {
if !errors.Is(err, flag.ErrHelp) {
Expand All @@ -133,7 +133,7 @@ func (c *cli) run(args []string) int {
c.usage()
return 1
}
opts, err := c.makeOptions()
opts, err := c.makeAttackerOptions()
if err != nil {
fmt.Fprintln(c.stderr, err.Error())
c.usage()
Expand All @@ -156,7 +156,7 @@ func (c *cli) run(args []string) int {
setDebug(nil, c.debug)

if err := gui.Run(target, s, a,
gui.Option{
gui.Options{
QueryRange: c.queryRange,
RedrawInternal: c.redrawInterval,
},
Expand All @@ -183,8 +183,8 @@ Author:
fmt.Fprintf(c.stderr, format, flagSet.FlagUsages())
}

// makeOptions gives back an options for attacker, with the CLI input.
func (c *cli) makeOptions() (*attacker.Options, error) {
// makeAttackerOptions gives back an options for attacker, with the CLI input.
func (c *cli) makeAttackerOptions() (*attacker.Options, error) {
if !validateMethod(c.method) {
return nil, fmt.Errorf("given method %q isn't an HTTP request method", c.method)
}
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestRun(t *testing.T) {
}
}

func TestMakeOptions(t *testing.T) {
func TestMakeAttackerOptions(t *testing.T) {
tests := []struct {
name string
cli *cli
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestMakeOptions(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.cli.makeOptions()
got, err := tt.cli.makeAttackerOptions()
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.wantErr, err != nil)
})
Expand Down

0 comments on commit d3e563b

Please sign in to comment.