starting to get into the hairy parts of zot - identity, location, and permission synchronisation. After this, messaging should be a piece of cake.

This commit is contained in:
friendica 2012-11-10 20:08:07 -08:00
parent ff40eabb7a
commit dd00fcc7bb
4 changed files with 111 additions and 16 deletions

View File

@ -59,9 +59,9 @@ function zot_verify(&$item,$identity) {
function zot_notify($channel,$url) {
function zot_notify($channel,$url,$type = 'notify') {
$x = z_post_url($url, array(
'type' => 'notify',
'type' => $type,
'guid' => $channel['channel_guid'],
'guid_sig' => base64url_encode($guid,$channel['prvkey']),
'hub' => z_root(),
@ -125,6 +125,86 @@ function zot_finger($webbie,$channel) {
}
function zot_refresh($them,$channel) {
if($them['hubloc_url'])
$url = $them['hubloc_url'];
else {
$r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_flags & %d limit 1",
dbesc($them['xchan_hash']),
intval(HUBLOC_FLAGS_PRIMARY)
);
if($r)
$url = $r[0]['hubloc_url'];
}
if(! $url)
return;
if($them['xchan_hash'])
$guid_hash = $them['xchan_hash'];
if(! $guid_hash)
return;
$rhs = '/.well-known/zot-guid';
$postvars = array(
'guid_hash' => $guid_hash,
'target' => $channel['channel_guid'],
'target_sig' => $channel['channel_guid_sig'],
'key' => $channel['channel_pubkey']
);
$result = z_post_url($url . $rhs,$postvars);
if($result['success']) {
$j = json_decode($result['body']);
$x = import_xchan_from_json($j);
if(! $x['success'])
return $x;
$xchan_hash = $x['hash'];
$their_perms = 0;
$global_perms = get_perms();
if($j->permissions->data) {
$permissions = aes_unencapsulate(array(
'data' => $j->permissions->data,
'key' => $j->permissions->key,
'iv' => $j->permissions->iv),
$channel['channel_prvkey']);
if($permissions)
$permissions = json_decode($permissions);
logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA);
}
else
$permissions = $j->permissions;
foreach($permissions as $k => $v) {
if($v) {
$their_perms = $their_perms | intval($global_perms[$k][1]);
}
}
$r = q("update abook set their_perms = %d where abook_xchan = '%s' and abook_channel = %d limit 1",
intval($their_perms),
dbesc($channel['channel_hash']),
intval($channel['channel_id'])
);
if(! $r)
logger('abook update failed');
return true;
}
return false;
}
function zot_gethub($arr) {

View File

@ -13,8 +13,6 @@ function post_post(&$a) {
$msgtype = ((x($_REQUEST,'type')) ? $_REQUEST['type'] : '');
if($msgtype === 'notify') {
$hub = zot_gethub($_REQUEST);
if(! $hub) {
$result = zot_register_hub($_REQUEST);
@ -26,6 +24,23 @@ function post_post(&$a) {
// check which hub is primary and take action if mismatched
if($msgtype === 'refresh') {
// Need to pass the recipient in the message
// look up recipient
// format args
// $r = zot_refresh($them,$channel);
return;
}
if($msgtype === 'notify') {
// add to receive queue
// qreceive_add($_REQUEST);

View File

@ -7,7 +7,7 @@ function zfinger_init(&$a) {
$ret = array('success' => false);
$zguid = ((x($_REQUEST,'guid')) ? $_REQUEST['guid'] : '');
$zhash = ((x($_REQUEST,'guid_hash')) ? $_REQUEST['guid_hash'] : '');
$zaddr = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : '');
$ztarget = ((x($_REQUEST,'target')) ? $_REQUEST['target'] : '');
$zsig = ((x($_REQUEST,'target_sig')) ? $_REQUEST['target_sig'] : '');
@ -25,8 +25,8 @@ function zfinger_init(&$a) {
if(strlen($zguid)) {
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
where channel_guid = '%s' limit 1",
dbesc($zguid)
where channel_hash = '%s' limit 1",
dbesc($zhash)
);
}
elseif(strlen($zaddr)) {

View File

@ -1 +1 @@
2012-11-09.133
2012-11-10.134