aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/deliver.php4
-rw-r--r--include/zot.php52
2 files changed, 36 insertions, 20 deletions
diff --git a/include/deliver.php b/include/deliver.php
index 5ab44a620..26739fb06 100644
--- a/include/deliver.php
+++ b/include/deliver.php
@@ -92,12 +92,12 @@ function deliver_run($argv, $argc) {
$m = json_decode($r[0]['outq_msg'],true);
if(array_key_exists('message_list',$m)) {
foreach($m['message_list'] as $mm) {
- $msg = array('body' => json_encode(array('pickup' => array(array('notify' => $notify,'message' => $mm)))));
+ $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $mm)))));
zot_import($msg,z_root());
}
}
else {
- $msg = array('body' => json_encode(array('pickup' => array(array('notify' => $notify,'message' => $m)))));
+ $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $m)))));
zot_import($msg,z_root());
}
$r = q("delete from outq where outq_hash = '%s'",
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();