mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
e22b33795b
commit
7fa031b648
9 changed files with 105 additions and 8 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue