aboutsummaryrefslogtreecommitdiffstats
path: root/include/zot.php
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-09-11 14:30:07 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-09-11 14:30:07 -0700
commite062c4e6b54c6162d118f8657eb6f81c971f0dd8 (patch)
tree8771146852414a797b56a51e5a8f59736ab438a1 /include/zot.php
parent05e0ed51736a2a49e36b535ef5d669e4172cf786 (diff)
downloadvolse-hubzilla-e062c4e6b54c6162d118f8657eb6f81c971f0dd8.tar.gz
volse-hubzilla-e062c4e6b54c6162d118f8657eb6f81c971f0dd8.tar.bz2
volse-hubzilla-e062c4e6b54c6162d118f8657eb6f81c971f0dd8.zip
another tactic to deal with orphan hublocs from re-installs, or at least allow the descendant channel to survive
Diffstat (limited to 'include/zot.php')
-rw-r--r--include/zot.php52
1 files changed, 34 insertions, 18 deletions
diff --git a/include/zot.php b/include/zot.php
index a81c13707..82199ab1c 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -543,7 +543,7 @@ function zot_refresh($them, $channel = null, $force = false) {
* @returns array|null null if site is blacklisted or not found, otherwise an
* array with an hubloc record
*/
-function zot_gethub($arr) {
+function zot_gethub($arr,$multiple = false) {
if($arr['guid'] && $arr['guid_sig'] && $arr['url'] && $arr['url_sig']) {
@@ -562,18 +562,20 @@ function zot_gethub($arr) {
return null;
}
+ $limit = (($multiple) ? '' : ' limit 1 ');
+
$r = q("select * from hubloc
where hubloc_guid = '%s' and hubloc_guid_sig = '%s'
and hubloc_url = '%s' and hubloc_url_sig = '%s'
- limit 1",
+ $limit",
dbesc($arr['guid']),
dbesc($arr['guid_sig']),
dbesc($arr['url']),
dbesc($arr['url_sig'])
);
- if($r && count($r)) {
+ if($r) {
logger('zot_gethub: found', LOGGER_DEBUG);
- return $r[0];
+ return (($multiple) ? $r : $r[0]);
}
}
logger('zot_gethub: not found: ' . print_r($arr,true), LOGGER_DEBUG);
@@ -1017,27 +1019,38 @@ function zot_fetch($arr) {
$url = $arr['sender']['url'] . $arr['callback'];
- $ret_hub = zot_gethub($arr['sender']);
- if(! $ret_hub) {
+ // set $multiple param on zot_gethub() to return all matching hubs
+ // This allows us to recover from re-installs when a redundant (but invalid) hubloc for
+ // this identity is widely dispersed throughout the network.
+
+ $ret_hubs = zot_gethub($arr['sender'],true);
+ if(! $ret_hubs) {
logger('zot_fetch: no hub: ' . print_r($arr['sender'],true));
return;
}
- $data = array(
- 'type' => 'pickup',
- 'url' => z_root(),
- 'callback_sig' => base64url_encode(rsa_sign(z_root() . '/post',get_config('system','prvkey'))),
- 'callback' => z_root() . '/post',
- 'secret' => $arr['secret'],
- 'secret_sig' => base64url_encode(rsa_sign($arr['secret'],get_config('system','prvkey')))
- );
+ foreach($ret_hubs as $ret_hub) {
+ $data = array(
+ 'type' => 'pickup',
+ 'url' => z_root(),
+ 'callback_sig' => base64url_encode(rsa_sign(z_root() . '/post',get_config('system','prvkey'))),
+ 'callback' => z_root() . '/post',
+ 'secret' => $arr['secret'],
+ 'secret_sig' => base64url_encode(rsa_sign($arr['secret'],get_config('system','prvkey')))
+ );
- $datatosend = json_encode(crypto_encapsulate(json_encode($data),$ret_hub['hubloc_sitekey']));
+ $datatosend = json_encode(crypto_encapsulate(json_encode($data),$ret_hub['hubloc_sitekey']));
- $fetch = zot_zot($url,$datatosend);
- $result = zot_import($fetch, $arr['sender']['url']);
+ $fetch = zot_zot($url,$datatosend);
+
+ $result = zot_import($fetch, $arr['sender']['url']);
+
+ if($result)
+ return $result;
+ }
+
+ return;
- return $result;
}
/**
@@ -1076,6 +1089,9 @@ function zot_import($arr, $sender_url) {
$data = json_decode(crypto_unencapsulate($data,get_config('system','prvkey')),true);
}
+ if(! $data['success'])
+ return false;
+
$incoming = $data['pickup'];
$return = array();