zot6 delivery cleanup
This commit is contained in:
parent
85a6dd6031
commit
441cdeff3f
@ -1170,18 +1170,37 @@ function zot_fetch($arr) {
|
|||||||
|
|
||||||
$url = $arr['sender']['url'] . $arr['callback'];
|
$url = $arr['sender']['url'] . $arr['callback'];
|
||||||
|
|
||||||
|
$import = null;
|
||||||
|
$hubs = null;
|
||||||
|
|
||||||
|
$zret = zot6_check_sig();
|
||||||
|
|
||||||
|
if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid'] && $data['msg']) {
|
||||||
|
logger('zot6_delivery',LOGGER_DEBUG);
|
||||||
|
logger('zot6_data: ' . print_r($data,true),LOGGER_DATA);
|
||||||
|
|
||||||
|
$ret['collected'] = true;
|
||||||
|
|
||||||
|
$import = [ 'success' => true, 'body' => json_encode( [ 'success' => true, 'pickup' => [ [ 'notify' => $data, 'message' => json_decode($data['msg'],true) ] ] ] ) ];
|
||||||
|
$hubs = [ $zret['hubloc'] ] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! $hubs) {
|
||||||
// set $multiple param on zot_gethub() to return all matching hubs
|
// 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 allows us to recover from re-installs when a redundant (but invalid) hubloc for
|
||||||
// this identity is widely dispersed throughout the network.
|
// this identity is widely dispersed throughout the network.
|
||||||
|
|
||||||
$ret_hubs = zot_gethub($arr['sender'],true);
|
$hubs = zot_gethub($arr['sender'],true);
|
||||||
if(! $ret_hubs) {
|
}
|
||||||
|
|
||||||
|
if(! $hubs) {
|
||||||
logger('No hub: ' . print_r($arr['sender'],true));
|
logger('No hub: ' . print_r($arr['sender'],true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($ret_hubs as $ret_hub) {
|
foreach($hubs as $hub) {
|
||||||
|
|
||||||
|
if(! $import) {
|
||||||
$secret = substr(preg_replace('/[^0-9a-fA-F]/','',$arr['secret']),0,64);
|
$secret = substr(preg_replace('/[^0-9a-fA-F]/','',$arr['secret']),0,64);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -1193,15 +1212,19 @@ function zot_fetch($arr) {
|
|||||||
'secret_sig' => base64url_encode(rsa_sign($secret, get_config('system','prvkey')))
|
'secret_sig' => base64url_encode(rsa_sign($secret, get_config('system','prvkey')))
|
||||||
];
|
];
|
||||||
|
|
||||||
$algorithm = zot_best_algorithm($ret_hub['site_crypto']);
|
$algorithm = zot_best_algorithm($hub['site_crypto']);
|
||||||
$datatosend = json_encode(crypto_encapsulate(json_encode($data),$ret_hub['hubloc_sitekey'], $algorithm));
|
$datatosend = json_encode(crypto_encapsulate(json_encode($data),$hub['hubloc_sitekey'], $algorithm));
|
||||||
|
|
||||||
$fetch = zot_zot($url,$datatosend);
|
$import = zot_zot($url,$datatosend);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$algorithm = zot_best_algorithm($hub['site_crypto']);
|
||||||
|
}
|
||||||
|
|
||||||
$result = zot_import($fetch, $arr['sender']['url']);
|
$result = zot_import($import, $arr['sender']['url']);
|
||||||
|
|
||||||
if($result) {
|
if($result) {
|
||||||
$result = crypto_encapsulate(json_encode($result),$ret_hub['hubloc_sitekey'], $algorithm);
|
$result = crypto_encapsulate(json_encode($result),$hub['hubloc_sitekey'], $algorithm);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5098,29 +5121,6 @@ function zot_reply_notify($data) {
|
|||||||
|
|
||||||
logger('notify received from ' . $data['sender']['url']);
|
logger('notify received from ' . $data['sender']['url']);
|
||||||
|
|
||||||
// handle zot6 delivery
|
|
||||||
|
|
||||||
$zret = zot6_check_sig();
|
|
||||||
if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid'] && $data['msg']) {
|
|
||||||
logger('zot6_delivery',LOGGER_DEBUG);
|
|
||||||
logger('zot6_data: ' . print_r($data,true),LOGGER_DATA);
|
|
||||||
|
|
||||||
$ret['collected'] = true;
|
|
||||||
|
|
||||||
$import = [ 'success' => true, 'pickup' => [ [ 'notify' => $data, 'message' => json_decode($data['msg'],true) ] ] ];
|
|
||||||
|
|
||||||
logger('zot6_import: ' . print_r($import,true), LOGGER_DATA);
|
|
||||||
|
|
||||||
$x = zot_import([ 'success' => true, 'body' => json_encode($import) ], $data['sender']['url']);
|
|
||||||
if($x) {
|
|
||||||
$x = crypto_encapsulate(json_encode($x),$zret['hubloc']['hubloc_sitekey'],zot_best_algorithm($zret['hubloc']['site_crypto']));
|
|
||||||
$ret['delivery_report'] = $x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
// handle traditional zot delivery
|
|
||||||
|
|
||||||
$async = get_config('system','queued_fetch');
|
$async = get_config('system','queued_fetch');
|
||||||
|
|
||||||
if($async) {
|
if($async) {
|
||||||
@ -5131,7 +5131,6 @@ function zot_reply_notify($data) {
|
|||||||
$x = zot_fetch($data);
|
$x = zot_fetch($data);
|
||||||
$ret['delivery_report'] = $x;
|
$ret['delivery_report'] = $x;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
json_return_and_die($ret);
|
json_return_and_die($ret);
|
||||||
|
Reference in New Issue
Block a user