Skip to content

Commit

Permalink
fix newstrategy test in geneva_test.go, fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
garmr-ulfr committed Oct 13, 2023
1 parent 9257f73 commit 7b9fe38
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 73 deletions.
8 changes: 6 additions & 2 deletions actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
package actions

import (
"errors"
"fmt"

"github.com/google/gopacket"

"github.com/getlantern/geneva/internal"
"github.com/getlantern/geneva/internal/scanner"
"github.com/getlantern/geneva/triggers"
"github.com/google/gopacket"

// gopacket best practice says import this, too.
_ "github.com/google/gopacket/layers"
)

var ErrInvalidAction = errors.New("invalid action")

// ActionTree represents a Geneva (trigger, action) pair.
//
// Technically, Geneva uses the term "action tree" to refer to the tree of actions in the tuple
Expand Down Expand Up @@ -122,5 +126,5 @@ func ParseAction(s *scanner.Scanner) (Action, error) {
return DefaultSendAction, nil
}

return nil, fmt.Errorf("invalid action at %d", s.Pos())
return nil, fmt.Errorf("%w at %d", ErrInvalidAction, s.Pos())
}
7 changes: 6 additions & 1 deletion actions/duplicate_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"errors"
"fmt"

"github.com/google/gopacket"

"github.com/getlantern/geneva/internal"
"github.com/getlantern/geneva/internal/scanner"
"github.com/google/gopacket"
)

// DuplicateAction is a Geneva action that duplicates a packet and applies separate action trees to
Expand Down Expand Up @@ -114,6 +115,10 @@ func ParseDuplicateAction(s *scanner.Scanner) (Action, error) {
}

if action.Left, err = ParseAction(s); err != nil {
if !errors.Is(err, ErrInvalidAction) {
return nil, err
}

if c, err2 := s.Peek(); err2 == nil && c == ',' {
action.Left = &SendAction{}
} else {
Expand Down
4 changes: 4 additions & 0 deletions actions/fragment_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ func ParseFragmentAction(s *scanner.Scanner) (Action, error) {
}

if action.FirstFragmentAction, err = ParseAction(s); err != nil {
if !errors.Is(err, ErrInvalidAction) {
return nil, err
}

if c, err2 := s.Peek(); err2 == nil && c == ',' {
action.FirstFragmentAction = &SendAction{}
} else {
Expand Down
Loading

0 comments on commit 7b9fe38

Please sign in to comment.