]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/factories/states/peer/class_PeerStateFactory.php
New Exception added, registering of session ids added:
[hub.git] / application / hub / main / factories / states / peer / class_PeerStateFactory.php
index 22e340239ef4bb8813cde995f05bde166fba2588..1256fa6e632862cbddb398927fa3515f7075c23d 100644 (file)
@@ -42,19 +42,26 @@ class PeerStateFactory extends ObjectFactory {
         * for the peer given in $packageData 'sender' element or it changes the state if it differs
         * from current state.
         *
-        * @param       $errorCode              The last error code
-        * @param       $packageData    Raw package data
-        * @return      $stateInstance  A Stateable class instance
+        * @param       $errorCode                      The last error code
+        * @param       $packageData            Raw package data
+        * @param       $socketResource         A valid socket resource
+        * @return      $stateInstance          A Stateable class instance
         */
-       public static final function createPeerStateInstanceByErrorCode ($errorCode, array $packageData) {
+       public static final function createPeerStateInstanceByErrorCode ($errorCode, array $packageData, $socketResource) {
                // So first we need our lookup table
                $tableInstance = self::getTableInstance();
 
+               // Purge old entries
+               $tableInstance->purgeOldEntriesBySocketResource($socketResource);
+
                // Do we have an entry?
                if ($tableInstance->isSenderNewPeer($packageData)) {
                        // Is a new peer so create the state instance based on error code, first we need a config entry
                        $configEntry = 'peer_state_' . $errorCode . '_class';
 
+                       // Register the new peer with its session id
+                       $tableInstance->registerPeerByPackageData($packageData, $socketResource);
+
                        // Then get it
                        $stateInstance = ObjectFactory::createObjectByConfiguredName($configEntry);