Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/auto transport logic #1247

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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