aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorwinter2025-01-02 21:43:06 +0000
committerwinter2025-01-02 21:43:06 +0000
commit765bf9729cc31b7ff552922c6363373f218c1f24 (patch)
tree209ee655ee747f54acc75981963edbd0cd350a84
parentfea439b57f9ba225e2d3169d7615c0bd2aecabe4 (diff)
try to auth and subscribe both ways at any opportunity
experimental and untested and might turn out to be a horrible idea! but it will at least mean there's a trigger for subscription now
-rw-r--r--Digitigrade/Model/Instance.php7
-rw-r--r--routes/subscribe.php9
2 files changed, 15 insertions, 1 deletions
diff --git a/Digitigrade/Model/Instance.php b/Digitigrade/Model/Instance.php
index 168a1de..4242638 100644
--- a/Digitigrade/Model/Instance.php
+++ b/Digitigrade/Model/Instance.php
@@ -34,7 +34,7 @@ class Instance extends FetchableModel {
$auth = InstanceAuth::findWhere('instance_id = ?', [$this->id]);
if ($auth == null) {
$auth = new InstanceAuth();
- $auth->setOwnerId($this->id);
+ //$auth->setOwnerId($this->id);
}
$this->auth = $auth;
}
@@ -108,6 +108,11 @@ class Instance extends FetchableModel {
// try to refresh it 1 hour before it expires, to leave some leeway
$refreshAt = (new \DateTimeImmutable($data->expires))->sub(new \DateInterval('PT1H'));
(new RefreshOutboundAuthToken($this->domain, $refreshAt))->submit();
+
+ // for now i think it makes sense to subscribe as soon as possible to all authed instances for maximum federation
+ // this is probably a bad idea in the long run but i'll cross that bridge when it comes to it
+ // see also the route for /subscribe
+ $this->subscribe();
}
public function refreshOutboundAuthToken() {
diff --git a/routes/subscribe.php b/routes/subscribe.php
index e081309..9795aa1 100644
--- a/routes/subscribe.php
+++ b/routes/subscribe.php
@@ -12,6 +12,15 @@ Router::getInstance()->mount('/subscribe', function (array $args) {
$instance->auth->outboundPushEnabled = true;
$instance->save();
http_response_code(204); // "No Content"
+
+ // similar to in Instance->requestOutboundAuthToken, i'm gonna start auth in the other direction at this point
+ // my intention is that with these two pieces of code, any two digitigrade instances will complete full 2-way
+ // auth and subscribe "handshakes" when either one tries to auth with the other
+ // with a small network i don't think this will be a problem but as it grows this could cause a lot of extra
+ // overhead potentially?
+ // also worth noting this is run immediately rather than scheduled as a job. might be best to change that.
+ if ($instance->auth->outboundToken == null)
+ $instance->beginOutboundAuth();
});
Router::getInstance()->mount('/unsubscribe', function (array $args) {