From 1108eaaed0cf451668dcaf04bd532a3615724dbc Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 29 Mar 2014 21:53:50 -0700 Subject: source routing stuff --- include/items.php | 34 ++++++++++++++++++++++++++++++++++ include/zot.php | 3 +++ 2 files changed, 37 insertions(+) diff --git a/include/items.php b/include/items.php index dcf9f5bc2..71e89e1e2 100755 --- a/include/items.php +++ b/include/items.php @@ -81,6 +81,18 @@ function collect_recipients($item,&$private) { $recipients = check_list_permissions($item['uid'],$recipients,'view_stream'); + $routes = q("select * from route where iid = %d", + intval($item['id']) + ); + + if($routes) { + $route = explode(',',$routes[0]['route']); + if(count($route)) { + $route = array_unique($route); + $recipients = array_diff($recipients,$route); + } + } + // add ourself just in case we have nomadic clones that need to get a copy. $recipients[] = $item['author_xchan']; @@ -141,6 +153,28 @@ function can_comment_on_post($observer_xchan,$item) { } +function add_source_route($iid,$hash) { + if((! $iid) || (! $route)) + return; + $r = q("select * from route where iid = %d limit 1", + intval($iid) + ); + if($r && $r[0]['route']) { + q("update route set route = '%s' where iid = %d limit 1", + dbesc(',' . $hash), + intval($iid) + ); + } + else { + q("insert into route ( iid, route ) values ( %d, '%s') ", + intval($iid), + dbesc($route) + ); + } +} + + + /** * @function red_zrl_callback * preg_match function when fixing 'naked' links in mod item.php diff --git a/include/zot.php b/include/zot.php index b23c18bdb..48240d5aa 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1452,6 +1452,7 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false) { } $xyz = event_store($ev); + add_source_route($xyz,$sender['hash']); $result = array($d['hash'],'event processed',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); continue; @@ -1476,6 +1477,8 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false) { $arr['uid'] = $channel['channel_id']; $item_result = item_store($arr); $item_id = $item_result['item_id']; + add_source_route($item_id,$sender['hash']); + $result[] = array($d['hash'],(($item_id) ? 'posted' : 'storage failed:' . $item_result['message']),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); } -- cgit v1.2.3 From ced6d826334c3d4979c296bb292fbc393cc6a034 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 31 Mar 2014 16:25:05 -0700 Subject: finish up the source route storage so we can prevent messages from flowing upstream in complicated delivery chains --- boot.php | 2 +- include/items.php | 27 ++++++++++----------------- install/database.sql | 23 ++++++++++++----------- install/update.php | 9 ++++++++- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/boot.php b/boot.php index 737e11001..f274b264e 100755 --- a/boot.php +++ b/boot.php @@ -47,7 +47,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'ZOT_REVISION', 1 ); -define ( 'DB_UPDATE_VERSION', 1104 ); +define ( 'DB_UPDATE_VERSION', 1105 ); define ( 'EOL', '
' . "\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/include/items.php b/include/items.php index 71e89e1e2..b60c0c2f1 100755 --- a/include/items.php +++ b/include/items.php @@ -81,12 +81,8 @@ function collect_recipients($item,&$private) { $recipients = check_list_permissions($item['uid'],$recipients,'view_stream'); - $routes = q("select * from route where iid = %d", - intval($item['id']) - ); - - if($routes) { - $route = explode(',',$routes[0]['route']); + if($item['route']) { + $route = explode(',',$item['route']); if(count($route)) { $route = array_unique($route); $recipients = array_diff($recipients,$route); @@ -156,21 +152,16 @@ function can_comment_on_post($observer_xchan,$item) { function add_source_route($iid,$hash) { if((! $iid) || (! $route)) return; - $r = q("select * from route where iid = %d limit 1", + $r = q("select route from item where id = %d limit 1", intval($iid) ); - if($r && $r[0]['route']) { - q("update route set route = '%s' where iid = %d limit 1", - dbesc(',' . $hash), + if($r) { + $new_route = (($r[0]['route']) ? $r[0]['route'] . ',' : '') . $hash; + q("update item set route = '%s' where id = %d limit 1", + (dbesc($new_route)), intval($iid) ); } - else { - q("insert into route ( iid, route ) values ( %d, '%s') ", - intval($iid), - dbesc($route) - ); - } } @@ -670,6 +661,7 @@ function get_item_elements($x) { $arr['app'] = (($x['app']) ? htmlspecialchars($x['app'], ENT_COMPAT,'UTF-8',false) : ''); + $arr['route'] = (($x['route']) ? htmlspecialchars($x['route'], ENT_COMPAT,'UTF-8',false) : ''); $arr['mid'] = (($x['message_id']) ? htmlspecialchars($x['message_id'], ENT_COMPAT,'UTF-8',false) : ''); $arr['parent_mid'] = (($x['message_top']) ? htmlspecialchars($x['message_top'], ENT_COMPAT,'UTF-8',false) : ''); $arr['thr_parent'] = (($x['message_parent']) ? htmlspecialchars($x['message_parent'], ENT_COMPAT,'UTF-8',false) : ''); @@ -681,7 +673,7 @@ function get_item_elements($x) { $arr['mimetype'] = (($x['mimetype']) ? htmlspecialchars($x['mimetype'], ENT_COMPAT,'UTF-8',false) : ''); $arr['obj_type'] = (($x['object_type']) ? htmlspecialchars($x['object_type'], ENT_COMPAT,'UTF-8',false) : ''); $arr['tgt_type'] = (($x['target_type']) ? htmlspecialchars($x['target_type'], ENT_COMPAT,'UTF-8',false) : ''); - $arr['comment_policy'] = (($x['comment_scope']) ? htmlspecialchars($x['comment_scope'], ENT_COMPAT,'UTF-8',false) : 'contacts'); + $arr['comment_policy'] = (($x['comment_scope']) ? htmlspecialchars($x['comment_scope'], ENT_COMPAT,'UTF-8',false) : 'contacts'); $arr['sig'] = (($x['signature']) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : ''); @@ -870,6 +862,7 @@ function encode_item($item) { $x['location'] = $item['location']; $x['longlat'] = $item['coord']; $x['signature'] = $item['sig']; + $x['route'] = $item['route']; $x['owner'] = encode_item_xchan($item['owner']); $x['author'] = encode_item_xchan($item['author']); diff --git a/install/database.sql b/install/database.sql index cbfca822c..329db698e 100644 --- a/install/database.sql +++ b/install/database.sql @@ -470,31 +470,32 @@ CREATE TABLE IF NOT EXISTS `item` ( `author_xchan` char(255) NOT NULL DEFAULT '', `source_xchan` char(255) NOT NULL DEFAULT '', `mimetype` char(255) NOT NULL DEFAULT '', - `title` text NOT NULL, - `body` mediumtext NOT NULL, + `title` text NOT NULL DEFAULT '', + `body` mediumtext NOT NULL DEFAULT '', `app` char(255) NOT NULL DEFAULT '', `lang` char(64) NOT NULL DEFAULT '', `revision` int(10) unsigned NOT NULL DEFAULT '0', `verb` char(255) NOT NULL DEFAULT '', `obj_type` char(255) NOT NULL DEFAULT '', - `object` text NOT NULL, + `object` text NOT NULL DEFAULT '', `tgt_type` char(255) NOT NULL DEFAULT '', - `target` text NOT NULL, + `target` text NOT NULL DEFAULT '', `layout_mid` char(255) NOT NULL DEFAULT '', - `postopts` text NOT NULL, + `postopts` text NOT NULL DEFAULT '', + `route` text NOT NULL DEFAULT '', `llink` char(255) NOT NULL DEFAULT '', `plink` char(255) NOT NULL DEFAULT '', `resource_id` char(255) NOT NULL DEFAULT '', `resource_type` char(16) NOT NULL DEFAULT '', - `attach` mediumtext NOT NULL, - `sig` text NOT NULL, + `attach` mediumtext NOT NULL DEFAULT '', + `sig` text NOT NULL DEFAULT '', `location` char(255) NOT NULL DEFAULT '', `coord` char(255) NOT NULL DEFAULT '', `comment_policy` char(255) NOT NULL DEFAULT '', - `allow_cid` mediumtext NOT NULL, - `allow_gid` mediumtext NOT NULL, - `deny_cid` mediumtext NOT NULL, - `deny_gid` mediumtext NOT NULL, + `allow_cid` mediumtext NOT NULL DEFAULT '', + `allow_gid` mediumtext NOT NULL DEFAULT '', + `deny_cid` mediumtext NOT NULL DEFAULT '', + `deny_gid` mediumtext NOT NULL DEFAULT '', `item_restrict` int(11) NOT NULL DEFAULT '0', `item_flags` int(11) NOT NULL DEFAULT '0', `item_private` tinyint(4) NOT NULL DEFAULT '0', diff --git a/install/update.php b/install/update.php index 06a60db79..55e404e4e 100644 --- a/install/update.php +++ b/install/update.php @@ -1,6 +1,6 @@ Date: Mon, 31 Mar 2014 16:29:46 -0700 Subject: doco --- include/items.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/items.php b/include/items.php index b60c0c2f1..3c7732b28 100755 --- a/include/items.php +++ b/include/items.php @@ -81,6 +81,11 @@ function collect_recipients($item,&$private) { $recipients = check_list_permissions($item['uid'],$recipients,'view_stream'); + // remove any upstream recipients from our list. + // If it is ourself we'll add it back in a second. + // This should prevent complex delivery chains from getting overly complex by not + // sending to anybody who is on our list of those who sent it to us. + if($item['route']) { $route = explode(',',$item['route']); if(count($route)) { -- cgit v1.2.3