diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2021-04-10 18:03:08 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-04-19 12:51:01 -0700 |
commit | 7fa031b648fedeaa35eb4da8003cd521cf65c4e3 (patch) | |
tree | dfca701ab741656d823ce6157393d11dad9ca267 /core/git-access.c | |
parent | e22b33795b5e0b101a744d03093278cf7991687a (diff) | |
download | subsurface-7fa031b648fedeaa35eb4da8003cd521cf65c4e3.tar.gz |
cloudstorage: try to pick between multiple cloud servers
The backend infrastructure will soon be able to support more than one
cloud server which automagically stay in sync with each other.
One critical requirement for that to work is that once a session was
started with one of the servers, the complete session happens with that
server - we must not switch from server to server while doing a git
transaction. To make sure that's the case, we aren't trying to use DNS
tricks to make this load balancing scheme work, but instead try to
determine at program start which server is the best one to use.
Right now this is super simplistic. Two servers, one in the US, one in
Europe. By default we use the European server (most of our users appear
to be in Europe), but if we can figure out that the client is actually
in the Americas, use the US server. We might improve that heuristic over
time, but as a first attempt it seems not entirely bogus.
The way this is implemented is a simple combination of two free
webservices that together appear to give us a very reliable estimate
which continent the user is located on.
api.ipify.org gives us our external IP address
ip-api.com gives us the continent that IP address is on
If any of this fails or takes too long to respond, we simply ignore it
since either server will work. One oddity is that if we decide to change
servers we only change the settings that are stored on disk, not the
runtime preferences. This goes back to the comment above that we have to
avoid changing servers in mid sync.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/git-access.c')
-rw-r--r-- | core/git-access.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/core/git-access.c b/core/git-access.c index 0936fa399..bd958b517 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -297,7 +297,8 @@ int certificate_check_cb(git_cert *cert, int valid, const char *host, void *payl UNUSED(payload); if (verbose) SSRF_INFO("git storage: certificate callback for host %s with validity %d\n", host, valid); - if (same_string(host, "cloud.subsurface-divelog.org") && cert->cert_type == GIT_CERT_X509) { + if ((same_string(host, CLOUD_HOST_GENERIC) || same_string(host, CLOUD_HOST_US) || same_string(host, CLOUD_HOST_EU)) && + cert->cert_type == GIT_CERT_X509) { // for some reason the LetsEncrypt certificate makes libgit2 throw up on some // platforms but not on others // if we are connecting to the cloud server we alrady called 'canReachCloudServer()' @@ -712,7 +713,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc return 0; } if (verbose) - SSRF_INFO("git storage: fetch remote\n"); + SSRF_INFO("git storage: fetch remote %s\n", git_remote_url(origin)); git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; opts.callbacks.transfer_progress = &transfer_progress_cb; auth_attempt = 0; @@ -775,6 +776,11 @@ static git_repository *update_local_repo(const char *localdir, const char *remot } git_reference_free(head); } + /* make sure we have the correct origin - the cloud server URL could have changed */ + if (git_remote_set_url(repo, "origin", remote)) { + SSRF_INFO("git storage: failed to update origin to '%s'", remote); + return NULL; + } if (!git_local_only) sync_with_remote(repo, remote, branch, rt); |