[LockManager] Made LSLockManager session 32 chars (128 bits).
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 18 Jul 2012 20:43:36 +0000 (13:43 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 18 Jul 2012 20:43:51 +0000 (13:43 -0700)
Change-Id: I1eba3eb44ebef02c771b518c2bcbdc0d41eb8086

includes/filerepo/backend/lockmanager/LSLockManager.php
maintenance/locking/LockServerDaemon.php

index 024e11b..8942818 100644 (file)
@@ -57,14 +57,14 @@ class LSLockManager extends QuorumLockManager {
         * Construct a new instance from configuration.
         *
         * $config paramaters include:
-        *     'lockServers'  : Associative array of server names to configuration.
-        *                      Configuration is an associative array that includes:
-        *                      'host'    - IP address/hostname
-        *                      'port'    - TCP port
-        *                      'authKey' - Secret string the lock server uses
-        *     'srvsByBucket' : Array of 1-16 consecutive integer keys, starting from 0,
-        *                      each having an odd-numbered list of server names (peers) as values.
-        *     'connTimeout'  : Lock server connection attempt timeout. [optional]
+        *   - lockServers  : Associative array of server names to configuration.
+        *                    Configuration is an associative array that includes:
+        *                      - host    : IP address/hostname
+        *                      - port    : TCP port
+        *                      - authKey : Secret string the lock server uses
+        *   - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
+        *                    each having an odd-numbered list of server names (peers) as values.
+        *   - connTimeout  : Lock server connection attempt timeout. [optional]
         *
         * @param Array $config
         */
@@ -82,7 +82,7 @@ class LSLockManager extends QuorumLockManager {
                        $this->connTimeout = 3; // use some sane amount
                }
 
-               $this->session = wfRandomString( 31 );
+               $this->session = wfRandomString( 32 ); // 128 bits
        }
 
        /**
index ba778f4..689c930 100644 (file)
@@ -239,7 +239,7 @@ class LockServerDaemon {
                        list( $session, $key, $command, $type, $values ) = $m;
                        if ( sha1( $session . $command . $type . $values . $this->authKey ) !== $key ) {
                                return 'BAD_KEY';
-                       } elseif ( strlen( $session ) !== 31 ) {
+                       } elseif ( strlen( $session ) !== 32 ) {
                                return 'BAD_SESSION';
                        }
                        $values = explode( '|', $values );
@@ -272,7 +272,7 @@ class LockServerDaemon {
        /**
         * Remove a socket's corresponding session from tracking and
         * store it in the dead session tracking if it still has locks.
-        * 
+        *
         * @param $socket resource
         * @return bool
         */
@@ -309,7 +309,7 @@ class LockServerDaemon {
 
        /**
         * Get the current timestamp and memory usage
-        * 
+        *
         * @return string
         */
        protected function stat() {
@@ -479,10 +479,10 @@ class LockHolder {
 
        /**
         * @param $session string
-        * @return bool 
+        * @return bool
         */
        public function sessionHasLocks( $session ) {
-               return isset( $this->sessionIndexSh[$session] ) 
+               return isset( $this->sessionIndexSh[$session] )
                        || isset( $this->sessionIndexEx[$session] );
        }