summaryrefslogtreecommitdiffstats
path: root/apps/federation/backgroundjob/requestsharedsecret.php
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2015-11-19 11:48:21 +0100
committerBjörn Schießle <bjoern@schiessle.org>2015-11-19 18:07:33 +0100
commit6f7aa3392f4ec47d03164a9732842ec034aeae48 (patch)
tree3a277311f8eb5d00cfbea92014cb5de8e818c419 /apps/federation/backgroundjob/requestsharedsecret.php
parent2754afc0747950591b3ddca37248d363c6ab64f3 (diff)
downloadnextcloud-server-6f7aa3392f4ec47d03164a9732842ec034aeae48.tar.gz
nextcloud-server-6f7aa3392f4ec47d03164a9732842ec034aeae48.zip
make sure that both server don't try to exchange the shared secret in parallel
Diffstat (limited to 'apps/federation/backgroundjob/requestsharedsecret.php')
-rw-r--r--apps/federation/backgroundjob/requestsharedsecret.php48
1 files changed, 34 insertions, 14 deletions
diff --git a/apps/federation/backgroundjob/requestsharedsecret.php b/apps/federation/backgroundjob/requestsharedsecret.php
index b73b620b4b7..c945757818d 100644
--- a/apps/federation/backgroundjob/requestsharedsecret.php
+++ b/apps/federation/backgroundjob/requestsharedsecret.php
@@ -23,6 +23,7 @@
namespace OCA\Federation\BackgroundJob;
+use GuzzleHttp\Exception\ClientException;
use OC\BackgroundJob\QueuedJob;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
@@ -50,6 +51,12 @@ class RequestSharedSecret extends QueuedJob {
/** @var IURLGenerator */
private $urlGenerator;
+ /** @var DbHandler */
+ private $dbHandler;
+
+ /** @var TrustedServers */
+ private $trustedServers;
+
private $endPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json';
/**
@@ -59,21 +66,24 @@ class RequestSharedSecret extends QueuedJob {
* @param IURLGenerator $urlGenerator
* @param IJobList $jobList
* @param TrustedServers $trustedServers
+ * @param DbHandler $dbHandler
*/
public function __construct(
IClient $httpClient = null,
IURLGenerator $urlGenerator = null,
IJobList $jobList = null,
- TrustedServers $trustedServers = null
+ TrustedServers $trustedServers = null,
+ dbHandler $dbHandler = null
) {
$this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient();
$this->jobList = $jobList ? $jobList : \OC::$server->getJobList();
$this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator();
+ $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation'));
if ($trustedServers) {
$this->trustedServers = $trustedServers;
} else {
$this->trustedServers = new TrustedServers(
- new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')),
+ $this->dbHandler,
\OC::$server->getHTTPClientService(),
\OC::$server->getLogger(),
$this->jobList,
@@ -106,19 +116,24 @@ class RequestSharedSecret extends QueuedJob {
$source = rtrim($source, '/');
$token = $argument['token'];
- $result = $this->httpClient->post(
- $target . $this->endPoint,
- [
- 'body' => [
- 'url' => $source,
- 'token' => $token,
- ],
- 'timeout' => 3,
- 'connect_timeout' => 3,
- ]
- );
+ try {
+ $result = $this->httpClient->post(
+ $target . $this->endPoint,
+ [
+ 'body' => [
+ 'url' => $source,
+ 'token' => $token,
+ ],
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ]
+ );
- $status = $result->getStatusCode();
+ $status = $result->getStatusCode();
+
+ } catch (ClientException $e) {
+ $status = $e->getCode();
+ }
// if we received a unexpected response we try again later
if (
@@ -131,5 +146,10 @@ class RequestSharedSecret extends QueuedJob {
);
}
+ if ($status === Http::STATUS_FORBIDDEN) {
+ // clear token if remote server refuses to ask for shared secret
+ $this->dbHandler->addToken($target, '');
+ }
+
}
}