Skip to content

Commit

Permalink
feat: allow defining polling interface
Browse files Browse the repository at this point in the history
  • Loading branch information
0x416e746f6e committed Sep 18, 2024
1 parent fed6fbc commit 89fc5ad
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dev/br-lft-act.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bridges:

status_addr: 10.0.0.2:8080
partner_url: http://10.0.0.3:8080/
partner_polling_interface: eth0

probe_interval: 1s
probe_location: left/active
Expand Down
1 change: 1 addition & 0 deletions .dev/br-lft-sby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bridges:

status_addr: 10.0.0.3:8080
partner_url: http://10.0.0.2:8080/
partner_polling_interface: eth0

probe_interval: 1s
probe_location: left/standby
Expand Down
2 changes: 1 addition & 1 deletion bridge/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *Server) pollPartnerBridge(ctx context.Context, _ chan<- error) {

res, err := s.http.Do(req)
if err != nil {
l.Debug("Failed to query partner bridge status",
l.Warn("Failed to query partner bridge status",
zap.Error(err),
)
s.events <- &event.PartnerPollFailure{ // emit event
Expand Down
12 changes: 12 additions & 0 deletions bridge/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/flashbots/vpnham/reconciler"
"github.com/flashbots/vpnham/transponder"
"github.com/flashbots/vpnham/types"
"github.com/flashbots/vpnham/utils"
"github.com/google/uuid"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -77,6 +78,17 @@ func NewServer(ctx context.Context, cfg *config.Bridge) (*Server, error) {
Timeout: cfg.PartnerStatusTimeout,
KeepAlive: 2 * cfg.PartnerStatusTimeout,
}
if cfg.PartnerPollingInterface != "" {
ipv4s, ipv6s, err := utils.GetInterfaceIPs(cfg.PartnerPollingInterface)
if err != nil {
return nil, err
}
if len(ipv4s) > 0 {
dialer.LocalAddr = &net.TCPAddr{IP: net.ParseIP(ipv4s[0])}
} else if len(ipv6s) > 0 {
dialer.LocalAddr = &net.TCPAddr{IP: net.ParseIP(ipv6s[0])}
}
}
transport := &http.Transport{
DialContext: dialer.DialContext,
IdleConnTimeout: 4 * cfg.PartnerStatusTimeout,
Expand Down
14 changes: 13 additions & 1 deletion config/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Bridge struct {

StatusAddr types.Address `yaml:"status_addr"`
PartnerURL string `yaml:"partner_url"`
PartnerPollingInterface string `yaml:"partner_polling_interface"`
PartnerStatusTimeout time.Duration `yaml:"partner_status_timeout"`
PartnerStatusThresholdDown int `yaml:"partner_status_threshold_down"`
PartnerStatusThresholdUp int `yaml:"partner_status_threshold_up"`
Expand All @@ -41,11 +42,12 @@ type Bridge struct {

var (
errBridgeActiveTunnelInterfacesCountIsInvalid = errors.New("bridge has invalid count of active interfaces configured (must be only 1)")
errBridgeExtraPeerCIDRIsInvalid = errors.New("bridge extra peer cidr is invalid")
errBridgeInterfaceIsInvalid = errors.New("bridge interface is invalid")
errBridgePartnerPollingInterfaceIsInvalid = errors.New("bridge polling interface is invalid")
errBridgePartnerStatusThresholdsAreInvalid = errors.New("bridge partner status thresholds are invalid")
errBridgePartnerStatusURLIsInvalid = errors.New("bridge partner status url is invalid")
errBridgePeerCIDRIsInvalid = errors.New("bridge peer cidr is invalid")
errBridgeExtraPeerCIDRIsInvalid = errors.New("bridge extra peer cidr is invalid")
errBridgeReconcileConfigurationIsInvalid = errors.New("bridge reconcile configuration is invalid")
errBridgeRoleIsInvalid = errors.New("bridge role is invalid")
errBridgeStatusAddrIsInvalid = errors.New("bridge status addr is invalid")
Expand Down Expand Up @@ -145,6 +147,16 @@ func (b *Bridge) Validate(ctx context.Context) error {
}
}

{ // partner_polling_interface
if b.PartnerPollingInterface != "" {
if _, _, err := utils.GetInterfaceIPs(b.PartnerPollingInterface); err != nil {
return fmt.Errorf("%w: %w",
errBridgePartnerPollingInterfaceIsInvalid, err,
)
}
}
}

{ // partner_status_threshold_down, partner_status_threshold_up
if _, err := monitor.New(b.PartnerStatusThresholdDown, b.PartnerStatusThresholdUp); err != nil {
return fmt.Errorf("%w: %w",
Expand Down

0 comments on commit 89fc5ad

Please sign in to comment.