feat: improve login flow

This commit is contained in:
James Houlahan
2020-04-02 16:41:49 +02:00
parent 941e09079c
commit 6e38a65bd8
41 changed files with 595 additions and 362 deletions

View File

@ -72,8 +72,9 @@ func newProxyProvider(providers []string, query string) (p *proxyProvider) { //
return
}
// findProxy returns a new proxy domain which is not equal to the current RootURL.
// findProxy returns a new working proxy domain. This includes the standard API.
// It returns an error if the process takes longer than ProxySearchTime.
// TODO: Perhaps the name can be better -- we might also return the standard API.
func (p *proxyProvider) findProxy() (proxy string, err error) {
if time.Now().Before(p.lastLookup.Add(proxyLookupWait)) {
return "", errors.New("not looking for a proxy, too soon")
@ -88,6 +89,12 @@ func (p *proxyProvider) findProxy() (proxy string, err error) {
logrus.WithError(err).Warn("Failed to refresh proxy cache, cache may be out of date")
}
// We want to switch back to the RootURL if possible.
if p.canReach(RootURL) {
proxyResult <- RootURL
return
}
for _, proxy := range p.proxyCache {
if p.canReach(proxy) {
proxyResult <- proxy
@ -114,6 +121,7 @@ func (p *proxyProvider) findProxy() (proxy string, err error) {
}
// refreshProxyCache loads the latest proxies from the known providers.
// It includes the standard API.
func (p *proxyProvider) refreshProxyCache() error {
logrus.Info("Refreshing proxy cache")
@ -121,9 +129,6 @@ func (p *proxyProvider) refreshProxyCache() error {
if proxies, err := p.dohLookup(p.query, provider); err == nil {
p.proxyCache = proxies
// We also want to allow bridge to switch back to the standard API at any time.
p.proxyCache = append(p.proxyCache, RootURL)
logrus.WithField("proxies", proxies).Info("Available proxies")
return nil