Skip to content

Commit

Permalink
Merge pull request #1247 from mrpalide/fix/auto-transport-logic
Browse files Browse the repository at this point in the history
Fix/auto transport logic
  • Loading branch information
ersonp authored Jun 6, 2022
2 parents 036769f + 008a90e commit 33d1ee2
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,15 @@ func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []ro
return dmsgFallback()
}
// try to establish direct connection to rPK (single hop) using SUDPH or STCPR
errSlice := make([]error, 0, 2)
trySTCPR := false
trySUDPH := false

for _, trans := range transports {
ntype := network.Type(trans)
if ntype == network.STCPR {
trySTCPR = true
continue
}

// Wait until stun client is ready
<-v.stunReady
Expand All @@ -524,18 +530,27 @@ func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []ro
v.stunClient.NATType == stun.NATSymmetricUDPFirewall) {
continue
}
trySUDPH = true
}

// trying to establish direct connection to rPK using STCPR
if trySTCPR {
err := retrier.Do(ctx, func() error {
_, err := tm.SaveTransport(ctx, rPK, ntype, transport.LabelAutomatic)
_, err := tm.SaveTransport(ctx, rPK, network.STCPR, transport.LabelAutomatic)
return err
})
if err != nil {
errSlice = append(errSlice, err)
}
return err
}
if len(errSlice) != 2 {
return nil
// trying to establish direct connection to rPK using SUDPH
if trySUDPH {
err := retrier.Do(ctx, func() error {
_, err := tm.SaveTransport(ctx, rPK, network.SUDPH, transport.LabelAutomatic)
return err
})
return err
}
return errors.New(errSlice[0].Error())

return dmsgFallback()
},
}
}
Expand Down

0 comments on commit 33d1ee2

Please sign in to comment.