diff options
author | friendica <info@friendica.com> | 2014-02-11 14:19:20 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-02-11 14:19:20 -0800 |
commit | d02529fde1ee9d7ecf317ae30abce666e1b33eb4 (patch) | |
tree | f3801707655b40ea81fbe367753f1db5786432d6 /include | |
parent | 841f3922aab013ac1ae1b7715de95f8246fe4f25 (diff) | |
download | volse-hubzilla-d02529fde1ee9d7ecf317ae30abce666e1b33eb4.tar.gz volse-hubzilla-d02529fde1ee9d7ecf317ae30abce666e1b33eb4.tar.bz2 volse-hubzilla-d02529fde1ee9d7ecf317ae30abce666e1b33eb4.zip |
implement a forced directory update mode where we unconditionally create a directory sync packet. This is needed to ensure that monthly directory pings are propagated to other directory servers so they can each prove for themselves whether or not an account is alive or dead. We do not trust other directories to provide us information beyond "look at this entry and decide for yourself" as doing otherwise would invite rogue directory manipulations. As this scheduled update occurs on all channels across all servers, we should also pick up refresh messages from all existing channel clones and these should also propagate out to all directory servers using the same mechanism (though perhaps not at the same time).
Diffstat (limited to 'include')
-rw-r--r-- | include/dir_fns.php | 13 | ||||
-rw-r--r-- | include/directory.php | 9 | ||||
-rw-r--r-- | include/poller.php | 2 | ||||
-rw-r--r-- | include/zot.php | 15 |
4 files changed, 25 insertions, 14 deletions
diff --git a/include/dir_fns.php b/include/dir_fns.php index 74e12c078..c2e614831 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -139,12 +139,15 @@ function update_directory_entry($ud) { } +/** + * @function local_dir_update($uid,$force) + * push local channel updates to a local directory server + * + */ +function local_dir_update($uid,$force) { - -function syncdirs($uid) { - - logger('syncdirs', LOGGER_DEBUG); + logger('local_dir_update', LOGGER_DEBUG); $p = q("select channel.channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1", intval($uid) @@ -222,7 +225,7 @@ function syncdirs($uid) { } $ud_hash = random_string() . '@' . get_app()->get_hostname(); - update_modtime($hash,$ud_hash,$p[0]['channel_address'] . '@' . get_app()->get_hostname(),1); + update_modtime($hash,$ud_hash,$p[0]['channel_address'] . '@' . get_app()->get_hostname(),(($force) ? (-1) : 1)); } diff --git a/include/directory.php b/include/directory.php index 233899e88..794420b6f 100644 --- a/include/directory.php +++ b/include/directory.php @@ -13,6 +13,10 @@ function directory_run($argv, $argc){ if($argc < 2) return; + $force = false; + if(($argc > 2) && ($argv[2] === 'force')) + $force = true; + logger('directory update', LOGGER_DEBUG); $dirmode = get_config('system','directory_mode'); @@ -29,7 +33,8 @@ function directory_run($argv, $argc){ if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) { - syncdirs($argv[1]); + + local_dir_update($argv[1],$force); q("update channel set channel_dirdate = '%s' where channel_id = %d limit 1", dbesc(datetime_convert()), @@ -53,7 +58,7 @@ function directory_run($argv, $argc){ // ensure the upstream directory is updated - $packet = zot_build_packet($channel,'refresh'); + $packet = zot_build_packet($channel,(($force) ? 'force_refresh' : 'refresh')); $z = zot_zot($url,$packet); // re-queue if unsuccessful diff --git a/include/poller.php b/include/poller.php index 76c82db09..eba765278 100644 --- a/include/poller.php +++ b/include/poller.php @@ -64,7 +64,7 @@ function poller_run($argv, $argc){ $r = q("select channel_id from channel where channel_dirdate < UTC_TIMESTAMP() - INTERVAL 30 DAY"); if($r) { foreach($r as $rr) { - proc_run('php','include/directory.php',$rr['channel_id'],'ping'); + proc_run('php','include/directory.php',$rr['channel_id'],'force'); if($interval) @time_sleep_until(microtime(true) + (float) $interval); } diff --git a/include/zot.php b/include/zot.php index 109744c53..21eef073c 100644 --- a/include/zot.php +++ b/include/zot.php @@ -79,12 +79,12 @@ function zot_get_hublocs($hash) { * zot it to the other side * * @param array $channel => sender channel structure - * @param string $type => packet type: one of 'ping', 'pickup', 'purge', 'refresh', 'notify', 'auth_check' + * @param string $type => packet type: one of 'ping', 'pickup', 'purge', 'refresh', 'force_refresh', 'notify', 'auth_check' * @param array $recipients => envelope information, array ( 'guid' => string, 'guid_sig' => string ); empty for public posts * @param string $remote_key => optional public site key of target hub used to encrypt entire packet * NOTE: remote_key and encrypted packets are required for 'auth_check' packets, optional for all others * @param string $secret => random string, required for packets which require verification/callback - * e.g. 'pickup', 'purge', 'notify', 'auth_check' --- 'ping' and 'refresh' do not require verification + * e.g. 'pickup', 'purge', 'notify', 'auth_check'. Packet types 'ping', 'force_refresh', and 'refresh' do not require verification * * @returns string json encoded zot packet */ @@ -228,7 +228,7 @@ function zot_finger($webbie,$channel,$autofallback = true) { } /** - * @function: zot_refresh($them, $channel = null) + * @function: zot_refresh($them, $channel = null, $force = false) * * zot_refresh is typically invoked when somebody has changed permissions of a channel and they are notified * to fetch new permissions via a finger/discovery operation. This may result in a new connection @@ -251,7 +251,7 @@ function zot_finger($webbie,$channel,$autofallback = true) { * @returns boolean true if successful, else false */ -function zot_refresh($them,$channel = null) { +function zot_refresh($them,$channel = null, $force = false) { logger('zot_refresh: them: ' . print_r($them,true), LOGGER_DATA); if($channel) @@ -305,7 +305,7 @@ function zot_refresh($them,$channel = null) { return false; } - $x = import_xchan($j); + $x = import_xchan($j,(($force) ? (-1) : 1)); if(! $x['success']) return false; @@ -524,6 +524,9 @@ function zot_register_hub($arr) { * @param array $arr => json_decoded discovery packet * @param int $ud_flags * Determines whether to create a directory update record if any changes occur, default 1 or true + * $ud_flags = (-1) indicates a forced refresh where we unconditionally create a directory update record + * this typically occurs once a month for each channel as part of a scheduled ping to notify the directory + * that the channel still exists * * @returns array => 'success' (boolean true or false) * 'message' (optional error string only if success is false) @@ -885,7 +888,7 @@ function import_xchan($arr,$ud_flags = 1) { } } - if($changed) { + if(($changed) || ($ud_flags == (-1))) { $guid = random_string() . '@' . get_app()->get_hostname(); update_modtime($xchan_hash,$guid,$arr['address'],$ud_flags); logger('import_xchan: changed: ' . $what,LOGGER_DEBUG); |