]> git.mxchange.org Git - friendica.git/commitdiff
allow for multiple pubsub hubs so everything can still work when/if one goes flaky
authorMike Macgirvin <mike@macgirvin.com>
Fri, 15 Oct 2010 11:20:42 +0000 (04:20 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Fri, 15 Oct 2010 11:20:42 +0000 (04:20 -0700)
(Google's hub has been particularly unreliable recently and the symptoms are that
you just stop receiving updates, and/or updates you send are silently dropped and
never delivered). Also add more instrumentation to help debug pubsub issues.

include/items.php
include/notifier.php
include/poller.php
mod/pubsub.php

index 7958c78c3617fc6cb311b799885e98f220071e58..7647eed5cb122852e108c52cfcd1c373dc339090 100644 (file)
@@ -125,7 +125,18 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
 
        $hub = get_config('system','huburl');
 
-       $hubxml = ((strlen($hub)) ? '<link rel="hub" href="' . xmlify($hub) . '" />' . "\n" : '');
+       $hubxml = '';
+       if(strlen($hub)) {
+               $hubs = explode(',', $hub);
+               if(count($hubs)) {
+                       foreach($hubs as $h) {
+                               $h = trim($h);
+                               if(! strlen($h))
+                                       continue;
+                               $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
+                       }
+               }
+       }
 
        $salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ; 
        $salmon = ''; // remove this line when salmon handler is finished
@@ -599,10 +610,10 @@ function consume_feed($xml,$importer,$contact, &$hub) {
        $photo_url = '';
 
 
-       $foundhub = $feed->get_link(0,'hub');
+       $hubs = $feed->get_links('hub');
 
-       if(strlen($foundhub))
-               $hub = $foundhub;
+       if(count($hubs))
+               $hub = implode(',', $hubs);
 
        $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
        if($rawtags) {
@@ -834,14 +845,18 @@ function subscribe_to_hub($url,$importer,$contact) {
 
        $push_url = get_config('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
 
-       $verify_token = random_string();
+       // Use a single verify token, even if multiple hubs
+
+       $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
 
        $params= 'hub.mode=subscribe&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
 
-       $r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d LIMIT 1",
-               dbesc($verify_token),
-               intval($contact['id'])
-       );
+       if(! strlen($contact['hub-verify'])) {
+               $r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d LIMIT 1",
+                       dbesc($verify_token),
+                       intval($contact['id'])
+               );
+       }
 
        post_url($url,$params);                 
        return;
index 9866c02325d15b01d2283e48e732bf5702902452..bef46677c44a6566130147075123e6b30671670a 100644 (file)
 
        $atom = '';
 
-       $hubxml = ((strlen($hub)) ? '<link rel="hub" href="' . xmlify($hub) . '" />' . "\n" : '');
-       
+       $hubxml = '';
+       if(strlen($hub)) {
+               $hubs = explode(',', $hub);
+               if(count($hubs)) {
+                       foreach($hubs as $h) {
+                               $h = trim($h);
+                               if(! strlen($h))
+                                       continue;
+                               $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
+                       }
+               }
+       }
 
        $atom .= replace_macros($feed_template, array(
                        '$feed_id'      => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
        }
 
        if((strlen($hub)) && ($notify_hub)) {
-               $params = 'hub.mode=publish&hub.url=' . urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
-               post_url($hub,$params);
-               if($debugging) {
-                       file_put_contents('pubsub.out', "\n\n" . "Pinged hub at " . datetime_convert() . "\n" . "Hub returned " . $a->get_curl_code() . "\n\n" , FILE_APPEND);
+               $hubs = explode(',', $hub);
+               if(count($hubs)) {
+                       foreach($hubs as $h) {
+                               $h = trim($h);
+                               if(! strlen($h))
+                                       continue;
+                               $params = 'hub.mode=publish&hub.url=' . urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
+                               post_url($h,$params);
+                               if($debugging) {
+                                       file_put_contents('pubsub.out', "\n\n" . "Pinged hub " . $h . ' at ' 
+                                               . datetime_convert() . "\n" . "Hub returned " . $a->get_curl_code() . "\n\n" , FILE_APPEND);
+                               }
+                               if(count($hubs) > 1)
+                                       sleep(7);                               // try and avoid multiple hubs responding at precisely the same time
+                       }
                }
        }
 
index bf2803b637e379cc3c986f83e6ec2574a69763e9..bb82e5eda74b90d6791ddab001528d21df854a9b 100644 (file)
@@ -22,7 +22,7 @@
        $a->set_baseurl(get_config('system','url'));
 
        $contacts = q("SELECT * FROM `contact` 
-               WHERE ( `dfrn-id` != '' OR (`issued-id` != '' AND `duplex` = 1)) 
+               WHERE `network` = 'dfrn' AND ( `dfrn-id` != '' OR (`issued-id` != '' AND `duplex` = 1)) 
                AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()");
 
        if(! count($contacts))
                
 
                if((strlen($hub)) && ($contact['rel'] == REL_BUD) && ($contact['priority'] == 0)) {
-                       subscribe_to_hub($hub,$importer,$contact);
+                       $hubs = explode(',', $hub);
+                       if(count($hubs)) {
+                               foreach($hubs as $h) {
+                                       $h = trim($h);
+                                       if(! strlen($h))
+                                               continue;
+                                       subscribe_to_hub($h,$importer,$contact);
+                               }
+                       }
                }
 
 
index 7dea2afb13676cc32c5ba78c95c37059a92ac8c6..693fcbf81c485c2bf98d640c68639f6a44f89d87 100644 (file)
@@ -39,7 +39,10 @@ function pubsub_init(&$a) {
                $hub_lease = notags(trim($_GET['hub_lease_seconds']));
                $hub_verify = notags(trim($_GET['hub_verify_token']));
 
-
+               $debugging = get_config('system','debugging');
+               if($debugging) {
+                       file_put_contents('pubsub.out', 'Pubsubhubbub subscription called from ' . $_SERVER['REMOTE_ADDR'] . ' at ' . datetime_convert() . "\n" . print_r($_GET,true), FILE_APPEND);
+               }
 
                $subscribe = (($hub_mode === 'subscribe') ? 1 : 0);
 
@@ -86,8 +89,9 @@ function pubsub_post(&$a) {
        $xml = file_get_contents('php://input');
 
        $debugging = get_config('system','debugging');
+       $remote_host = 'Pubsub feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' at ' . datetime_convert() . "\n\n";
        if($debugging)
-               file_put_contents('pubsub.out',$xml,FILE_APPEND);
+               file_put_contents('pubsub.out', $remote_host . $xml, FILE_APPEND);
 
        $nick       = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
        $contact_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);