diff options
Diffstat (limited to 'include/hubloc.php')
-rw-r--r-- | include/hubloc.php | 104 |
1 files changed, 63 insertions, 41 deletions
diff --git a/include/hubloc.php b/include/hubloc.php index e17be028c..599252522 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -1,6 +1,17 @@ -<?php /** @file */ - - +<?php +/** + * @file include/hubloc.php + * @brief Hubloc related functions. + */ + +/** + * @brief Create an array for hubloc table and insert record. + * + * Creates an assoziative array which will be inserted into the hubloc table. + * + * @param array $arr An assoziative array with hubloc values + * @return boolean|PDOStatement + */ function hubloc_store_lowlevel($arr) { $store = [ @@ -25,8 +36,7 @@ function hubloc_store_lowlevel($arr) { 'hubloc_deleted' => ((array_key_exists('hubloc_deleted',$arr)) ? $arr['hubloc_deleted'] : 0) ]; - return create_table_from_array('hubloc',$store); - + return create_table_from_array('hubloc', $store); } @@ -45,9 +55,8 @@ function prune_hub_reinstalls() { // see if this url has more than one sitekey, indicating it has been re-installed. if(count($x) > 1) { - - $d1 = datetime_convert('UTC','UTC',$x[0]['c']); - $d2 = datetime_convert('UTC','UTC','now - 3 days'); + $d1 = datetime_convert('UTC', 'UTC', $x[0]['c']); + $d2 = datetime_convert('UTC', 'UTC', 'now - 3 days'); // allow some slop period, say 3 days - just in case this is a glitch or transient occurrence // Then remove any hublocs pointing to the oldest entry. @@ -63,18 +72,22 @@ function prune_hub_reinstalls() { } } -function remove_obsolete_hublocs() { - - logger('remove_obsolete_hublocs',LOGGER_DEBUG); - // Get rid of any hublocs which are ours but aren't valid anymore - - // e.g. they point to a different and perhaps transient URL that we aren't using. +/** + * @brief Remove obsolete hublocs. + * + * Get rid of any hublocs which are ours but aren't valid anymore - + * e.g. they point to a different and perhaps transient URL that we aren't using. + * + * I need to stress that this shouldn't happen. fix_system_urls() fixes hublocs + * when it discovers the URL has changed. So it's unclear how we could end up + * with URLs pointing to the old site name. But it happens. This may be an artifact + * of an old bug or maybe a regression in some newer code. In any event, they + * mess up communications and we have to take action if we find any. + */ +function remove_obsolete_hublocs() { - // I need to stress that this shouldn't happen. fix_system_urls() fixes hublocs - // when it discovers the URL has changed. So it's unclear how we could end up - // with URLs pointing to the old site name. But it happens. This may be an artifact - // of an old bug or maybe a regression in some newer code. In any event, they - // mess up communications and we have to take action if we find any. + logger('remove_obsolete_hublocs', LOGGER_DEBUG); // First make sure we have any hublocs (at all) with this URL and sitekey. // We don't want to perform this operation while somebody is in the process @@ -82,27 +95,25 @@ function remove_obsolete_hublocs() { $r = q("select hubloc_id from hubloc where hubloc_url = '%s' and hubloc_sitekey = '%s'", dbesc(z_root()), - dbesc(get_config('system','pubkey')) + dbesc(get_config('system', 'pubkey')) ); if((! $r) || (! count($r))) return; - $channels = array(); - // Good. We have at least one *valid* hubloc. // Do we have any invalid ones? $r = q("select hubloc_id from hubloc where hubloc_sitekey = '%s' and hubloc_url != '%s'", - dbesc(get_config('system','pubkey')), + dbesc(get_config('system', 'pubkey')), dbesc(z_root()) ); $p = q("select hubloc_id from hubloc where hubloc_sitekey != '%s' and hubloc_url = '%s'", - dbesc(get_config('system','pubkey')), + dbesc(get_config('system', 'pubkey')), dbesc(z_root()) ); if(is_array($r) && is_array($p)) - $r = array_merge($r,$p); + $r = array_merge($r, $p); if(! $r) return; @@ -111,8 +122,8 @@ function remove_obsolete_hublocs() { logger('remove_obsolete_hublocs: removing ' . count($r) . ' hublocs.'); - $interval = ((get_config('system','delivery_interval') !== false) - ? intval(get_config('system','delivery_interval')) : 2 ); + $interval = ((get_config('system', 'delivery_interval') !== false) + ? intval(get_config('system', 'delivery_interval')) : 2 ); foreach($r as $rr) { q("update hubloc set hubloc_deleted = 1 where hubloc_id = %d", @@ -120,10 +131,10 @@ function remove_obsolete_hublocs() { ); $x = q("select channel_id from channel where channel_hash = '%s' limit 1", - dbesc($rr['hubloc_hash']) + dbesc($rr['hubloc_hash']) ); if($x) { - Zotlabs\Daemon\Master::Summon(array('Notifier','location',$x[0]['channel_id'])); + Zotlabs\Daemon\Master::Summon(array('Notifier', 'location', $x[0]['channel_id'])); if($interval) @time_sleep_until(microtime(true) + (float) $interval); } @@ -131,8 +142,15 @@ function remove_obsolete_hublocs() { } -// This actually changes other structures to match the given (presumably current) hubloc primary selection - +/** + * @brief Change primary hubloc. + * + * This actually changes other structures to match the given (presumably current) + * hubloc primary selection. + * + * @param array $hubloc + * @return boolean + */ function hubloc_change_primary($hubloc) { if(! is_array($hubloc)) { @@ -170,7 +188,7 @@ function hubloc_change_primary($hubloc) { dbesc($hubloc['hubloc_hash']) ); if(! $r) { - logger('xchan not found'); + logger('xchan not found'); return false; } if($r[0]['xchan_addr'] === $hubloc['hubloc_addr']) { @@ -179,7 +197,7 @@ function hubloc_change_primary($hubloc) { } $url = $hubloc['hubloc_url']; - $lwebbie = substr($hubloc['hubloc_addr'],0,strpos($hubloc['hubloc_addr'],'@')); + $lwebbie = substr($hubloc['hubloc_addr'], 0, strpos($hubloc['hubloc_addr'], '@')); $r = q("update xchan set xchan_addr = '%s', xchan_url = '%s', xchan_follow = '%s', xchan_connurl = '%s' where xchan_hash = '%s'", dbesc($hubloc['hubloc_addr']), @@ -191,14 +209,19 @@ function hubloc_change_primary($hubloc) { if(! $r) logger('xchan_update failed.'); - logger('primary hubloc changed.' . print_r($hubloc,true),LOGGER_DEBUG); + logger('primary hubloc changed.' . print_r($hubloc, true), LOGGER_DEBUG); return true; - } -// We use the post url to distinguish between http and https hublocs. -// The https might be alive, and the http dead. +/** + * @brief Mark a hubloc as down. + * + * We use the post url to distinguish between http and https hublocs. + * The https might be alive, and the http dead. + * + * @param string $posturl Hubloc callback url which to disable + */ function hubloc_mark_as_down($posturl) { $r = q("update hubloc set hubloc_status = ( hubloc_status | %d ) where hubloc_callback = '%s'", intval(HUBLOC_OFFLINE), @@ -208,22 +231,21 @@ function hubloc_mark_as_down($posturl) { - function ping_site($url) { $ret = array('success' => false); $sys = get_sys_channel(); - $m = zot_build_packet($sys,'ping'); - $r = zot_zot($url . '/post',$m); + $m = zot_build_packet($sys, 'ping'); + $r = zot_zot($url . '/post', $m); if(! $r['success']) { $ret['message'] = 'no answer from ' . $url; return $ret; } - $packet_result = json_decode($r['body'],true); + $packet_result = json_decode($r['body'], true); if(! $packet_result['success']) { - $ret['message'] = 'packet failure from ' . $url; + $ret['message'] = 'packet failure from ' . $url; return $ret; } |