]> git.mjollnir.org Git - moodle.git/commitdiff
Mnet: Bugfix: Prevent infinite loop when 2 community hubs peer for the first time
authordonal72 <donal72>
Mon, 15 Jan 2007 08:31:58 +0000 (08:31 +0000)
committerdonal72 <donal72>
Mon, 15 Jan 2007 08:31:58 +0000 (08:31 +0000)
mnet/lib.php
mnet/peer.php
mnet/xmlrpc/server.php

index c5571a65b9af017ce86038300b935231b66a2a63..55f5d3329172a7a6fdefa441025fae939b51d4d1 100644 (file)
@@ -46,7 +46,7 @@ function mnet_get_hostname_from_uri($uri = null) {
  * @return string           A PEM formatted SSL Certificate.
  */
 function mnet_get_public_key($uri) {
-    global $CFG;
+    global $CFG, $MNET;
     // The key may be cached in the mnet_set_public_key function...
     // check this first
     $key = mnet_set_public_key($uri);
@@ -54,7 +54,7 @@ function mnet_get_public_key($uri) {
         return $key;
     }
 
-    $rq = xmlrpc_encode_request('system/keyswap', $CFG->wwwroot);
+    $rq = xmlrpc_encode_request('system/keyswap', array($CFG->wwwroot, $MNET->public_key));
     $ch = curl_init($uri.'/mnet/xmlrpc/server.php');
 
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
index 898c12c6597f2fdb4fb6bfc9dc6c640da2b1cd3f..4ee56545aeb1d8b24365a9a997648d50517ded78 100644 (file)
@@ -25,7 +25,7 @@ class mnet_peer {
         return true;
     }
 
-    function bootstrap($wwwroot) {
+    function bootstrap($wwwroot, $pubkey = null) {
 
         if (substr($wwwroot, 0, -1) == '/') {
             $wwwroot = substr($wwwroot, 0, -1);
@@ -59,7 +59,11 @@ class mnet_peer {
             $this->wwwroot              = $wwwroot;
             $this->ip_address           = $ip_address;
             $this->deleted              = 0;
-            $this->public_key           = clean_param(mnet_get_public_key($this->wwwroot), PARAM_PEM);
+            if(empty($pubkey)) {
+                $this->public_key           = clean_param(mnet_get_public_key($this->wwwroot), PARAM_PEM);
+            } else {
+                $this->public_key           = clean_param($pubkey, PARAM_PEM);
+            }
             $this->public_key_expires   = $this->check_common_name($this->public_key);
             $this->last_connect_time    = 0;
             $this->last_log_id          = 0;
index 09a8d427653f528b4419a95b37481667ddaf0ef2..04c6ffb37b3c71a65c9cd300e961e2350ebf913a 100644 (file)
@@ -670,17 +670,29 @@ function mnet_server_invoke_method($includefile, $methodname, $method, $payload,
     }
 }
 
+/**
+ * Accepts a public key from a new remote host and returns the public key for
+ * this host. If 'register all hosts' is turned on, it will bootstrap a record
+ * for the remote host in the mnet_host table (if it's not already there)
+ * 
+ * @param  string  $function      XML-RPC requires this but we don't... discard!
+ * @param  array   $params        Array of parameters
+ *                                $params[0] is the remote wwwroot
+ *                                $params[1] is the remote public key
+ * @return string                 The XML-RPC response
+ */
 function mnet_keyswap($function, $params) {
     global $CFG, $MNET;
     $return = array();
 
     if (!empty($CFG->mnet_register_allhosts)) {
         $mnet_peer = new mnet_peer();
-        $keyok = $mnet_peer->bootstrap($params[0]);
+        $keyok = $mnet_peer->bootstrap($params[0], $params[1]);
         if ($keyok) {
             $mnet_peer->commit();
         }
     }
     return $MNET->public_key;
 }
+
 ?>