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 14, 2023
1 parent 9257f73 commit 0e4adba
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 79 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
8 changes: 6 additions & 2 deletions actions/fragment_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ func FragmentIPPacket(packet gopacket.Packet, fragSize int) ([]gopacket.Packet,
}

func updateChecksums(packet gopacket.Packet) {
if ipv4 := packet.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ipv4 != nil {
if ipv4, _ := packet.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ipv4 != nil {
common.UpdateIPv4Checksum(ipv4)
}

if tcp := packet.Layer(layers.LayerTypeTCP).(*layers.TCP); tcp != nil {
if tcp, _ := packet.Layer(layers.LayerTypeTCP).(*layers.TCP); tcp != nil {
common.UpdateTCPChecksum(tcp)
}
}
Expand Down 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 0e4adba

Please sign in to comment.