// CFG: NODE-RAW-DATA-INPUT-STREAM-CLASS
$cfg->setConfigEntry('node_raw_data_input_stream_class', 'RawDataInputStream');
+// CFG: DEBUG-OUTPUT-TIMINGS
+$cfg->setConfigEntry('debug_output_timings', 'Y');
+
///////////////////////////////////////////////////////////////////////////////
// Peer states
///////////////////////////////////////////////////////////////////////////////
function purgeOldEntriesBySocketResource ($socketResource);
/**
- * Checks wether a given peer state (in helper instance) has changed from
- * stored one in database.
+ * Checks wether a given peer state (in helper instance) is same as stored
+ * in database compared with the one from $helperInstance.
*
* @param $helperInstance An instance of a ConnectionHelper class
* @param $packageData Valid package data array
- * @return $isPeerStateChanged Wether the peer's state has changed
+ * @return $isSamePeerState Wether the peer's state is the same
*/
- function ifPeerStateHasChanged (ConnectionHelper $helperInstance, array $packageData);
+ function isSamePeerState (ConnectionHelper $helperInstance, array $packageData);
}
// [EOF]
// Return the instance
return $wrapperInstance;
}
-
- /**
- * Getter for index key
- *
- * @return $indexKey Index key
- */
- public final function getIndexKey () {
- return $this->getDatabaseInstance()->getIndexKey();
- }
}
// [EOF]
return $wrapperInstance;
}
- /**
- * Getter for index key
- *
- * @return $indexKey Index key
- */
- public final function getIndexKey () {
- return $this->getDatabaseInstance()->getIndexKey();
- }
-
/**
* 'Registers' a new node id along with data provided in the node instance.
* This may sound confusing but avoids double code very nicely...
return $wrapperInstance;
}
- /**
- * Getter for index key
- *
- * @return $indexKey Index key
- */
- public final function getIndexKey () {
- return $this->getDatabaseInstance()->getIndexKey();
- }
-
/**
* Resolves a session id into an ip:port combination
*
}
/**
- * Checks wether a given peer state (in helper instance) has changed from
- * stored one in database.
+ * Checks wether a given peer state (in helper instance) is same as stored
+ * in database compared with the one from $helperInstance.
*
* @param $helperInstance An instance of a ConnectionHelper class
* @param $packageData Valid package data array
- * @return $isPeerStateChanged Wether the peer's state has changed
+ * @return $isSamePeerState Wether the peer's state is the same
*/
- public function ifPeerStateHasChanged (ConnectionHelper $helperInstance, array $packageData) {
+ public function isSamePeerState (ConnectionHelper $helperInstance, array $packageData) {
// Debug message
- /* NOISY-DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it it has changed ...');
+ /* NOISY-DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...');
- // By default the peer's state has not changed
- $isPeerStateChanged = false;
+ // Now get the search instance from given package data
+ $searchInstance = $this->getSenderSearchInstanceFromPackageData($packageData);
+
+ // With this search instance query the database for the peer and get a result instance
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Do we have an entry? This should always the case
+ assert($resultInstance->next());
+
+ // Yes, so get the current (=first) entry from it
+ $rowData = $resultInstance->current();
+
+ // Now just compare it with given state from helper instance
+ $isSamePeerState = ($rowData[self::DB_COLUMN_PEER_STATE] == $helperInstance->getPrintableState());
+
+ // Debug message
+ /* NOISY-DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: previous state=' . $rowData[self::DB_COLUMN_PEER_STATE] . ', current state=' . $helperInstance->getPrintableState() . ',isSamePeerState=' . intval($isSamePeerState));
// Return it
- return $isPeerStateChanged;
+ return $isSamePeerState;
}
}
// And register it with the lookup table
$tableInstance->registerPeerState($stateInstance, $packageData);
- } elseif ($tableInstance->ifPeerStateHasChanged($helperInstance, $packageData)) {
+ } elseif ($tableInstance->isSamePeerState($helperInstance, $packageData)) {
+ // Debug output
+ /* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...');
+
+ /*
+ * The peer's state has noot changed, still we have to return a
+ * state instance, so generate it here.
+ */
+ $stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance);
+ } else {
// Debug output
/* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Updating peer state ...');
// The peer's state has changed, update database now
$tableInstance->registerPeerState($stateInstance, $packageData);
- } else {
- // Debug output
- /* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...');
-
- /*
- * The peer's state has noot changed, still we have to return a
- * state instance, so generate it here.
- */
- $stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance);
}
// Debug message
} catch (ClassNotFoundException $e) {
// This exception means, the cruncher mode is invalid.
// @TODO Can we rewrite this to app_die() ?
- $this->debugBackTrace(__METHOD__ . ': cruncher mode ' . $cruncherMode . ' is invalid.' . "\n");
+ $this->debugBackTrace(__METHOD__ . ': cruncher mode ' . $cruncherMode . ' is invalid.');
}
// Set the cruncher instance in registry
} catch (ClassNotFoundException $e) {
// This exception means, the node mode is invalid.
// @TODO Can we rewrite this to app_die() ?
- $this->debugBackTrace(__METHOD__ . ': node mode ' . $nodeMode . ' is invalid.' . "\n");
+ $this->debugBackTrace(__METHOD__ . ': node mode ' . $nodeMode . ' is invalid.');
}
// Set the node instance in registry
* @return $socketResource Socket resource
*/
public static function createConnectionFromPackageData (array $packageData) {
- $this->debugBackTrace(__METHOD__ . ': Unfinished method, packageData[]=' . count($packageData) . "\n");
+ $this->debugBackTrace(__METHOD__ . ': Unfinished method, packageData[]=' . count($packageData));
}
/**
// Walk through all entries
foreach ($this->listIndex as $hash) {
- //* DEBUG: */ print __METHOD__.':hash='.$hash."\n";
+ //* DEBUG: */ print __METHOD__.':hash='.$hash.chr(10);
// Is the list entry set?
if ($this->isHashValid($hash)) {
// Add it
// Add the hash to the index
$this->listIndex[] = $hash;
- //* DEBUG: */ print $groupName.'/'.count($this->listIndex)."\n";
+ //* DEBUG: */ print $groupName.'/'.count($this->listIndex).chr(10);
// Now add the entry to the list
$this->listEntries[$hash] = $entry;
- //* DEBUG: */ print $groupName.'/'.count($this->listEntries)."\n";
+ //* DEBUG: */ print $groupName.'/'.count($this->listEntries).chr(10);
//* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
}
$this->getStackerInstance()->popNamed(self::STACKER_NAME_DECLARED);
} catch (InvalidStateException $e) {
// The state is not excepected (shall be 'connected')
- $this->debugOutput('PACKAGE: Unexpected state detected. message=' . $e->getMessage());
+ $this->debugOutput('PACKAGE: Caught exception ' . $e->__toString() . ' with message=' . $e->getMessage());
}
}