From 8d70b919551f6f6462e639f7cfffda9825344e43 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Dec 2018 18:14:32 -0800 Subject: regression: mail from dev to core not delivering --- include/zot.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index d031b4a96..9934dae07 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1232,6 +1232,7 @@ function zot_fetch($arr) { $datatosend = json_encode(crypto_encapsulate(json_encode($data),$hub['hubloc_sitekey'], $algorithm)); $import = zot_zot($url,$datatosend); + } else { $algorithm = zot_best_algorithm($hub['site_crypto']); @@ -4913,6 +4914,7 @@ function zot_reply_pickup($data) { dbesc($data['secret']), dbesc($data['callback']) ); + if(! $r) { $ret['message'] = 'nothing to pick up'; logger('mod_zot: pickup: ' . $ret['message']); -- cgit v1.2.3 From 8aa117e4ae550db2c156cec6431098700929ff5f Mon Sep 17 00:00:00 2001 From: "M. Dent" Date: Sat, 12 Jan 2019 09:22:37 +0100 Subject: FIX: memory exhaustion on zot message pickup with large message queue --- include/zot.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 9934dae07..6d9b6aeec 100644 --- a/include/zot.php +++ b/include/zot.php @@ -4924,12 +4924,13 @@ function zot_reply_pickup($data) { /* * Everything is good if we made it here, so find all messages that are going to this location - * and send them all. + * and send them all - or a reasonable number if there are a lot so we don't overflow memory. */ - $r = q("select * from outq where outq_posturl = '%s'", + $r = q("select * from outq where outq_posturl = '%s' limit 100", dbesc($data['callback']) ); + if($r) { logger('mod_zot: successful pickup message received from ' . $data['callback'] . ' ' . count($r) . ' message(s) picked up', LOGGER_DEBUG); @@ -4955,6 +4956,19 @@ function zot_reply_pickup($data) { } } + // It's possible that we have more than 100 messages waiting to be sent. + + // See if there are any more messages in the queue. + $x = q("select *,min(outq_created) as earliest from outq where outq_posturl = '%s'", + dbesc($data['callback']) + ); + + // If so, kick off a new delivery notification for the next batch + if ($x) { + logger("Send additional pickup request.", LOGGER_DEBUG); + queue_deliver($x[0],true); + } + // this is a bit of a hack because we don't have the hubloc_url here, only the callback url. // worst case is we'll end up using aes256cbc if they've got a different post endpoint @@ -4966,6 +4980,8 @@ function zot_reply_pickup($data) { $encrypted = crypto_encapsulate(json_encode($ret),$sitekey,$algorithm); json_return_and_die($encrypted); + // @FIXME: There is a possibility that the transmission will get interrupted + // and fail - in which case this packet of messages will be lost. /* pickup: end */ } -- cgit v1.2.3 From 121fa834d56ab3496c82d4d6c5fd8ba70743c26a Mon Sep 17 00:00:00 2001 From: "DM42.Net (Matt Dent)" Date: Sun, 13 Jan 2019 14:06:36 -0500 Subject: FIX: aggregated query error in MYSQL --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 6d9b6aeec..f2aa58ee7 100644 --- a/include/zot.php +++ b/include/zot.php @@ -4959,7 +4959,7 @@ function zot_reply_pickup($data) { // It's possible that we have more than 100 messages waiting to be sent. // See if there are any more messages in the queue. - $x = q("select *,min(outq_created) as earliest from outq where outq_posturl = '%s'", + $x = q("select * from outq order by outq_scheduled where outq_posturl = '%s' limit 1", dbesc($data['callback']) ); -- cgit v1.2.3 From ab074f52fece902d1057f531c5289562a7d5343f Mon Sep 17 00:00:00 2001 From: "DM42.Net (Matt Dent)" Date: Sun, 13 Jan 2019 14:10:35 -0500 Subject: outq_created not outq_scheduled --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index f2aa58ee7..7467eccde 100644 --- a/include/zot.php +++ b/include/zot.php @@ -4959,7 +4959,7 @@ function zot_reply_pickup($data) { // It's possible that we have more than 100 messages waiting to be sent. // See if there are any more messages in the queue. - $x = q("select * from outq order by outq_scheduled where outq_posturl = '%s' limit 1", + $x = q("select * from outq order by outq_created where outq_posturl = '%s' limit 1", dbesc($data['callback']) ); -- cgit v1.2.3 From b4c1ca88f32420cc1653e11811bad74d6f0231a5 Mon Sep 17 00:00:00 2001 From: "DM42.Net (Matt Dent)" Date: Sun, 13 Jan 2019 14:41:44 -0500 Subject: move order by and rewrite similar in update_queue_item() --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 7467eccde..df54f2b27 100644 --- a/include/zot.php +++ b/include/zot.php @@ -4959,7 +4959,7 @@ function zot_reply_pickup($data) { // It's possible that we have more than 100 messages waiting to be sent. // See if there are any more messages in the queue. - $x = q("select * from outq order by outq_created where outq_posturl = '%s' limit 1", + $x = q("select * from outq where outq_posturl = '%s' order by outq_created limit 1", dbesc($data['callback']) ); -- cgit v1.2.3 From 4450a01014c15a77c2e086c7d964a578b135cfba Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 16 Jan 2019 15:09:18 +0100 Subject: do not return if delivery report could not bedecrypted --- include/zot.php | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index df54f2b27..bc2187f91 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1100,6 +1100,8 @@ function zot_process_response($hub, $arr, $outq) { return; } + $dreport = true; + $x = json_decode($arr['body'], true); if(! $x) { @@ -1116,31 +1118,44 @@ function zot_process_response($hub, $arr, $outq) { } if(! (is_array($x['delivery_report']) && count($x['delivery_report']))) { logger('encrypted delivery report could not be decrypted'); - return; + $dreport = false; } } - foreach($x['delivery_report'] as $xx) { - call_hooks('dreport_process',$xx); - if(is_array($xx) && array_key_exists('message_id',$xx) && DReport::is_storable($xx)) { - q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s','%s' ) ", - dbesc($xx['message_id']), - dbesc($xx['location']), - dbesc($xx['recipient']), - dbesc($xx['name']), - dbesc($xx['status']), - dbesc(datetime_convert('UTC','UTC',$xx['date'])), - dbesc($xx['sender']) - ); + if($dreport) { + foreach($x['delivery_report'] as $xx) { + call_hooks('dreport_process',$xx); + if(is_array($xx) && array_key_exists('message_id',$xx) && DReport::is_storable($xx)) { + + // legacy zot recipients add a space and their name to the xchan. split those if true. + $legacy_recipient = strpos($xx['recipient'], ' '); + if($legacy_recipient !== false) { + $legacy_recipient_parts = explode(' ', $xx['recipient'], 2); + $xx['recipient'] = $legacy_recipient_parts[0]; + $xx['name'] = $legacy_recipient_parts[1]; + } + + q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s','%s' ) ", + dbesc($xx['message_id']), + dbesc($xx['location']), + dbesc($xx['recipient']), + dbesc($xx['name']), + dbesc($xx['status']), + dbesc(datetime_convert('UTC','UTC',$xx['date'])), + dbesc($xx['sender']) + ); + } } } } - // we have a more descriptive delivery report, so discard the per hub 'queued' report. - q("delete from dreport where dreport_queue = '%s' ", - dbesc($outq['outq_hash']) - ); + if($dreport) { + // we have a more descriptive delivery report, so discard the per hub 'queued' report. + q("delete from dreport where dreport_queue = '%s' ", + dbesc($outq['outq_hash']) + ); + } // update the timestamp for this site -- cgit v1.2.3