first cut at unpacking bitfields in hubloc, fixed hubloc_error and hubloc_deleted

This commit is contained in:
friendica 2015-01-20 15:35:42 -08:00
parent 70fb47248b
commit 6f11f20992
7 changed files with 33 additions and 58 deletions

View File

@ -272,8 +272,7 @@ function channel_remove($channel_id, $local = true, $unset_session=true) {
); );
$r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s'", $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'",
intval(HUBLOC_FLAGS_DELETED),
dbesc($channel['channel_hash']) dbesc($channel['channel_hash'])
); );
@ -312,8 +311,7 @@ function channel_remove($channel_id, $local = true, $unset_session=true) {
intval($channel_id) intval($channel_id)
); );
$r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s' and hubloc_url = '%s' ", $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s' and hubloc_url = '%s' ",
intval(HUBLOC_FLAGS_DELETED),
dbesc($channel['channel_hash']), dbesc($channel['channel_hash']),
dbesc(z_root()) dbesc(z_root())
); );
@ -322,9 +320,8 @@ function channel_remove($channel_id, $local = true, $unset_session=true) {
$hublocs = 0; $hublocs = 0;
$r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d)>0", $r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($channel['channel_hash']), dbesc($channel['channel_hash'])
intval(HUBLOC_FLAGS_DELETED)
); );
if($r) if($r)
$hublocs = count($r); $hublocs = count($r);
@ -374,10 +371,8 @@ function mark_orphan_hubsxchans() {
if($dirmode == DIRECTORY_MODE_NORMAL) if($dirmode == DIRECTORY_MODE_NORMAL)
return; return;
$r = q("update hubloc set hubloc_status = (hubloc_status | %d) where not (hubloc_status & %d)>0 $r = q("update hubloc set hubloc_error = 1 where hubloc_error = 0
and hubloc_network = 'zot' and hubloc_connected < %s - interval %s", and hubloc_network = 'zot' and hubloc_connected < %s - interval %s",
intval(HUBLOC_OFFLINE),
intval(HUBLOC_OFFLINE),
db_utcnow(), db_quoteinterval('36 day') db_utcnow(), db_quoteinterval('36 day')
); );
@ -394,9 +389,7 @@ function mark_orphan_hubsxchans() {
// } // }
$r = q("select hubloc_id, hubloc_hash from hubloc where (hubloc_status & %d)>0 and not (hubloc_flags & %d)>0", $r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_error = 0 and hubloc_orphancheck = 0",
intval(HUBLOC_OFFLINE),
intval(HUBLOC_FLAGS_ORPHANCHECK)
); );
if($r) { if($r) {
@ -404,9 +397,8 @@ function mark_orphan_hubsxchans() {
// see if any other hublocs are still alive for this channel // see if any other hublocs are still alive for this channel
$x = q("select * from hubloc where hubloc_hash = '%s' and not (hubloc_status & %d)>0", $x = q("select * from hubloc where hubloc_hash = '%s' and hubloc_error = 0",
dbesc($rr['hubloc_hash']), dbesc($rr['hubloc_hash']),
intval(HUBLOC_OFFLINE)
); );
if($x) { if($x) {
@ -431,8 +423,7 @@ function mark_orphan_hubsxchans() {
// mark that we've checked this entry so we don't need to do it again // mark that we've checked this entry so we don't need to do it again
$y = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d", $y = q("update hubloc set hubloc_orphancheck = 1 where hubloc_id = %d",
intval(HUBLOC_FLAGS_ORPHANCHECK),
dbesc($rr['hubloc_id']) dbesc($rr['hubloc_id'])
); );
} }
@ -501,8 +492,7 @@ function remove_all_xchan_resources($xchan, $channel_id = 0) {
// directory servers need to keep the record around for sync purposes - mark it deleted // directory servers need to keep the record around for sync purposes - mark it deleted
$r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s'", $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'",
intval(HUBLOC_FLAGS_DELETED),
dbesc($xchan) dbesc($xchan)
); );

View File

@ -96,8 +96,7 @@ function remove_obsolete_hublocs() {
? intval(get_config('system','delivery_interval')) : 2 ); ? intval(get_config('system','delivery_interval')) : 2 );
foreach($r as $rr) { foreach($r as $rr) {
q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d", q("update hubloc set hubloc_deleted = 1 where hubloc_id = %d",
intval(HUBLOC_FLAGS_DELETED),
intval($rr['hubloc_id']) intval($rr['hubloc_id'])
); );

View File

@ -497,11 +497,8 @@ function notifier_run($argv, $argc){
where hubloc_hash in (" . implode(',',$recipients) . ") order by hubloc_connected desc limit 1"); where hubloc_hash in (" . implode(',',$recipients) . ") order by hubloc_connected desc limit 1");
} }
else { else {
$r = q("select hubloc_guid, hubloc_url, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc $r = q("select * from hubloc where hubloc_hash in (" . implode(',',$recipients) . ")
where hubloc_hash in (" . implode(',',$recipients) . ") and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0", and hubloc_error = 0 and hubloc_deleted = 0");
intval(HUBLOC_FLAGS_DELETED),
intval(HUBLOC_OFFLINE)
);
} }
if(! $r) { if(! $r) {

View File

@ -55,7 +55,7 @@ function onedirsync_run($argv, $argc){
$h = q("select * from hubloc where hubloc_addr = '%s' limit 1", $h = q("select * from hubloc where hubloc_addr = '%s' limit 1",
dbesc($r[0]['ud_addr']) dbesc($r[0]['ud_addr'])
); );
if(($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) { if(($h) && (intval($h[0]['hubloc_error'])))
$y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date < '%s' ", $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date < '%s' ",
intval(UPDATE_FLAGS_UPDATED), intval(UPDATE_FLAGS_UPDATED),
dbesc($r[0]['ud_addr']), dbesc($r[0]['ud_addr']),

View File

@ -79,9 +79,8 @@ function zot_get_hublocs($hash) {
/** Only search for active hublocs - e.g. those that haven't been marked deleted */ /** Only search for active hublocs - e.g. those that haven't been marked deleted */
$ret = q("select * from hubloc where hubloc_hash = '%s' and not ( hubloc_flags & %d )>0 order by hubloc_url ", $ret = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted != 0 order by hubloc_url ",
dbesc($hash), dbesc($hash)
intval(HUBLOC_FLAGS_DELETED)
); );
return $ret; return $ret;
} }
@ -1884,9 +1883,8 @@ function sync_locations($sender,$arr,$absolute = false) {
// Should we do this? It's basically saying that the channel knows better than // Should we do this? It's basically saying that the channel knows better than
// the directory server if the site is alive. // the directory server if the site is alive.
if($r[0]['hubloc_status'] & HUBLOC_OFFLINE) { if($r[0]['hubloc_error']) {
q("update hubloc set hubloc_status = (hubloc_status & ~%d) where hubloc_id = %d", q("update hubloc set hubloc_error = 0 where hubloc_id = %d",
intval(HUBLOC_OFFLINE),
intval($r[0]['hubloc_id']) intval($r[0]['hubloc_id'])
); );
if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) {
@ -1934,10 +1932,10 @@ function sync_locations($sender,$arr,$absolute = false) {
$changed = true; $changed = true;
} }
} }
if((($r[0]['hubloc_flags'] & HUBLOC_FLAGS_DELETED) && (! $location['deleted'])) if((intval($r[0]['hubloc_deleted']) && (! $location['deleted']))
|| ((! ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_DELETED)) && ($location['deleted']))) { || ((! (intval($r[0]['hubloc_deleted']))) && ($location['deleted']))) {
$n = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_id = %d", $n = q("update hubloc set hubloc_deleted = %d, hubloc_updated = '%s' where hubloc_id = %d",
intval(HUBLOC_FLAGS_DELETED), intval($location['deleted']),
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($r[0]['hubloc_id']) intval($r[0]['hubloc_id'])
); );
@ -1994,8 +1992,7 @@ function sync_locations($sender,$arr,$absolute = false) {
foreach($xisting as $x) { foreach($xisting as $x) {
if(! array_key_exists('updated',$x)) { if(! array_key_exists('updated',$x)) {
logger('sync_locations: deleting unreferenced hub location ' . $x['hubloc_url']); logger('sync_locations: deleting unreferenced hub location ' . $x['hubloc_url']);
$r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_id = %d", $r = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
intval(HUBLOC_FLAGS_DELETED),
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($x['hubloc_id']) intval($x['hubloc_id'])
); );
@ -2029,7 +2026,7 @@ function zot_encode_locations($channel) {
'url_sig' => $hub['hubloc_url_sig'], 'url_sig' => $hub['hubloc_url_sig'],
'callback' => $hub['hubloc_callback'], 'callback' => $hub['hubloc_callback'],
'sitekey' => $hub['hubloc_sitekey'], 'sitekey' => $hub['hubloc_sitekey'],
'deleted' => (($hub['hubloc_flags'] & HUBLOC_FLAGS_DELETED) ? true : false) 'deleted' => (intval($hub['hubloc_deleted']) ? true : false)
); );
} }
} }
@ -2917,12 +2914,9 @@ function zot_process_message_request($data) {
if($messages) { if($messages) {
$env_recips = null; $env_recips = null;
$r = q("select hubloc_guid, hubloc_url, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host $r = q("select * from hubloc where hubloc_hash = '%s' and not hubloc_error and not hubloc_deleted
from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d)>0 group by hubloc_sitekey",
and not (hubloc_status & %d)>0 group by hubloc_sitekey", dbesc($sender_hash)
dbesc($sender_hash),
intval(HUBLOC_FLAGS_DELETED),
intval(HUBLOC_OFFLINE)
); );
if(! $r) { if(! $r) {
logger('no hubs'); logger('no hubs');

View File

@ -50,8 +50,7 @@ function locs_post(&$a) {
notice( t('Primary location cannot be removed.') . EOL); notice( t('Primary location cannot be removed.') . EOL);
return; return;
} }
$r = q("update hubloc set hubloc_flags = (hubloc_flags & %d) where hubloc_id = %d and hubloc_hash = '%s'", $r = q("update hubloc set hubloc_deleted = 1 where hubloc_id = %d and hubloc_hash = '%s'",
intval(HUBLOC_FLAGS_DELETED),
intval($hubloc_id), intval($hubloc_id),
dbesc($channel['channel_hash']) dbesc($channel['channel_hash'])
); );
@ -66,7 +65,6 @@ function locs_post(&$a) {
function locs_content(&$a) { function locs_content(&$a) {
if(! local_user()) { if(! local_user()) {
notice( t('Permission denied.') . EOL); notice( t('Permission denied.') . EOL);
return; return;
@ -86,7 +84,7 @@ function locs_content(&$a) {
for($x = 0; $x < count($r); $x ++) { for($x = 0; $x < count($r); $x ++) {
$r[$x]['primary'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false); $r[$x]['primary'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false);
$r[$x]['deleted'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_DELETED) ? true : false); $r[$x]['deleted'] = (intval($r[$x]['hubloc_deleted']) ? true : false);
} }

View File

@ -666,14 +666,12 @@ function post_post(&$a) {
// a dead hub came back to life - reset any tombstones we might have // a dead hub came back to life - reset any tombstones we might have
if($hub['hubloc_status'] & HUBLOC_OFFLINE) { if(intval($hub['hubloc_error'])) {
q("update hubloc set hubloc_status = (hubloc_status & ~%d) where hubloc_id = %d", q("update hubloc set hubloc_error = 0 where hubloc_id = %d",
intval(HUBLOC_OFFLINE),
intval($hub['hubloc_id']) intval($hub['hubloc_id'])
); );
if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { if(intval($r[0]['hubloc_orphancheck'])) {
q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where hubloc_id = %d", q("update hubloc set hubloc_orhpancheck = 0 where hubloc_id = %d",
intval(HUBLOC_FLAGS_ORPHANCHECK),
intval($hub['hubloc_id']) intval($hub['hubloc_id'])
); );
} }
@ -693,8 +691,7 @@ function post_post(&$a) {
* *
*/ */
q("update hubloc set hubloc_flags = ( hubloc_flags | %d ) where hubloc_url = '%s' and hubloc_sitekey != '%s' ", q("update hubloc set hubloc_deleted = 1 where hubloc_url = '%s' and hubloc_sitekey != '%s' ",
intval(HUBLOC_FLAGS_DELETED),
dbesc($hub['hubloc_url']), dbesc($hub['hubloc_url']),
dbesc($hub['hubloc_sitekey']) dbesc($hub['hubloc_sitekey'])
); );