aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-05-28 21:42:46 -0700
committerfriendica <info@friendica.com>2014-05-28 21:42:46 -0700
commit2a6d7b6a079a565afc0200fe160cb2402ed7c0a3 (patch)
tree5e7c28189a8f7db259bdab7b1d96f2ab3b574686
parent53ea6b05a644c75810a95e351021251f0f759e9f (diff)
downloadvolse-hubzilla-2a6d7b6a079a565afc0200fe160cb2402ed7c0a3.tar.gz
volse-hubzilla-2a6d7b6a079a565afc0200fe160cb2402ed7c0a3.tar.bz2
volse-hubzilla-2a6d7b6a079a565afc0200fe160cb2402ed7c0a3.zip
cleanup dead directory entries. This was a real b#tch, so keep your eye out for issues - which you shouldn't see until next weekend when this is scheduled to run. We're only setting flags, so if anything goes wrong we should be able to recover without too much pain.
-rwxr-xr-xboot.php1
-rw-r--r--include/Contact.php84
-rw-r--r--include/poller.php3
-rw-r--r--include/zot.php18
-rw-r--r--mod/post.php22
5 files changed, 109 insertions, 19 deletions
diff --git a/boot.php b/boot.php
index 768b703e9..5b6cea8b2 100755
--- a/boot.php
+++ b/boot.php
@@ -383,6 +383,7 @@ define ( 'NOTIFY_SYSTEM', 0x8000 );
define ( 'HUBLOC_FLAGS_PRIMARY', 0x0001);
define ( 'HUBLOC_FLAGS_UNVERIFIED', 0x0002);
+define ( 'HUBLOC_FLAGS_ORPHANCHECK', 0x0004);
define ( 'HUBLOC_FLAGS_DELETED', 0x1000);
define ( 'XCHAN_FLAGS_NORMAL', 0x0000);
diff --git a/include/Contact.php b/include/Contact.php
index 0cd4be72c..6e12652a5 100644
--- a/include/Contact.php
+++ b/include/Contact.php
@@ -141,24 +141,6 @@ function abook_toggle_flag($abook,$flag) {
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
// Included here for completeness, but this is a very dangerous operation.
// It is the caller's responsibility to confirm the requestor's intent and
// authorisation to do this.
@@ -305,6 +287,72 @@ function channel_remove($channel_id, $local = true) {
}
+/**
+ * mark any hubs "offline" that haven't been heard from in more than 30 days
+ * Allow them to redeem themselves if they come back later.
+ * Then go through all those that are newly marked and see if any other hubs
+ * are attached to the controlling xchan that are still alive.
+ * If not, they're dead (although they could come back some day).
+ */
+
+
+function mark_orphan_hubsxchans() {
+
+ $r = q("update hubloc set hubloc_status = (hubloc_status | %d) where not (hubloc_status & %d)
+ and hubloc_connected < utc_timestamp() - interval 30 day",
+ intval(HUBLOC_OFFLINE),
+ intval(HUBLOC_OFFLINE)
+ );
+
+ $r = q("select hubloc_id, hubloc_hash from hubloc where (hubloc_status & %d) and not (hubloc_flags & %d)",
+ intval(HUBLOC_OFFLINE),
+ intval(HUBLOC_FLAGS_ORPHANCHECK)
+ );
+
+ if($r) {
+ foreach($r as $rr) {
+
+ // see if any other hublocs are still alive for this channel
+
+ $x = q("select * from hubloc where hubloc_hash = '%s' and not (hubloc_status & %d)",
+ dbesc($rr['hubloc_hash']),
+ intval(HUBLOC_OFFLINE)
+ );
+ if($x) {
+
+ // yes - if the xchan was marked as an orphan, undo it
+
+ $y = q("update xchan set xchan_flags = (xchan_flags ^ %d) where (xchan_flags & %d) and xchan_hash = '%s' limit 1",
+ intval(XCHAN_FLAGS_ORPHAN),
+ intval(XCHAN_FLAGS_ORPHAN),
+ dbesc($rr['hubloc_hash'])
+ );
+
+ }
+ else {
+
+ // nope - mark the xchan as an orphan
+
+ $y = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s' limit 1",
+ intval(XCHAN_FLAGS_ORPHAN),
+ dbesc($rr['hubloc_hash'])
+ );
+ }
+
+ // mark that we've checked this entry so we don't need to do it again
+
+ $y = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_FLAGS_ORPHANCHECK),
+ dbesc($rr['hubloc_id'])
+ );
+ }
+ }
+
+}
+
+
+
+
function remove_all_xchan_resources($xchan, $channel_id = 0) {
if(intval($channel_id)) {
diff --git a/include/poller.php b/include/poller.php
index 9592c29e4..35844e666 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -118,10 +118,11 @@ function poller_run($argv, $argc){
require_once('include/hubloc.php');
prune_hub_reinstalls();
+ require_once('include/Contact.php');
+ mark_orphan_hubsxchans();
}
-
// expire any read notifications over a month old
q("delete from notify where seen = 1 and date < UTC_TIMESTAMP() - INTERVAL 30 DAY");
diff --git a/include/zot.php b/include/zot.php
index 869943a24..303f4f4a7 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -840,6 +840,24 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED) {
intval($r[0]['hubloc_id'])
);
}
+ if($r[0]['hubloc_status'] & HUBLOC_OFFLINE) {
+ q("update hubloc set hubloc_status = (hubloc_status ^ %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_OFFLINE),
+ intval($r[0]['hubloc_id'])
+ );
+ if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) {
+ q("update hubloc set hubloc_flags = (hubloc_flags ^ %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_FLAGS_ORPHANCHECK),
+ intval($r[0]['hubloc_id'])
+ );
+ }
+ q("update xchan set xchan_flags = (xchan_flags ^ %d) where (xchan_flags & %d) and xchan_hash = '%s' limit 1",
+ intval(XCHAN_FLAGS_ORPHAN),
+ intval(XCHAN_FLAGS_ORPHAN),
+ dbesc($xchan_hash)
+ );
+
+ }
// Remove pure duplicates
if(count($r) > 1) {
diff --git a/mod/post.php b/mod/post.php
index 1f817aa40..05053e798 100644
--- a/mod/post.php
+++ b/mod/post.php
@@ -646,6 +646,28 @@ function post_post(&$a) {
intval($hub['hubloc_id'])
);
+ // a dead hub came back to life - reset any tombstones we might have
+
+ if($hub['hubloc_status'] & HUBLOC_OFFLINE) {
+ q("update hubloc set hubloc_status = (hubloc_status ^ %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_OFFLINE),
+ intval($hub['hubloc_id'])
+ );
+ if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) {
+ q("update hubloc set hubloc_flags = (hubloc_flags ^ %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_FLAGS_ORPHANCHECK),
+ intval($hub['hubloc_id'])
+ );
+ }
+ q("update xchan set xchan_flags = (xchan_flags ^ %d) where (xchan_flags & %d) and xchan_hash = '%s' limit 1",
+ intval(XCHAN_FLAGS_ORPHAN),
+ intval(XCHAN_FLAGS_ORPHAN),
+ dbesc($hub['hubloc_hash'])
+ );
+ }
+
+
+
/**
* This hub has now been proven to be valid.
* Any hub with the same URL and a different sitekey cannot be valid.