X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fdatabase%2Fwrapper%2Fnode%2Fclass_NodeDistributedHashTableDatabaseWrapper.php;h=45208a22e952bd3a9b7563b8d75b898be64a614e;hb=e8a52ce5ce49f0a5de5d73e855c9a9f9473bc826;hp=ffa6e4baa4a3e82d6268d95f27d23e01b1305d42;hpb=c4e96d8114ae68a9c8e565c80c35fc8ec1bd873d;p=hub.git diff --git a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index ffa6e4baa..45208a22e 100644 --- a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -28,7 +28,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Constants for database column names const DB_COLUMN_NODE_ID = 'node_id'; const DB_COLUMN_SESSION_ID = 'session_id'; - const DB_COLUMN_IP_PORT = 'ip_port'; + const DB_COLUMN_EXTERNAL_IP = 'external_ip'; + const DB_COLUMN_LISTEN_PORT = 'listen_port'; const DB_COLUMN_PRIVATE_KEY = 'private_key'; const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash'; const DB_COLUMN_NODE_TYPE = 'node_type'; @@ -77,9 +78,16 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Set the primary key $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID); + // Get ip:port combination and "explode" it + $ipPort = $nodeInstance->getAddressPortArray(); + + // Make sure both is valid + assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid')); + // Add public node data $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_TYPE , $requestInstance->getRequestElement('mode')); - $dataSetInstance->addCriteria(self::DB_COLUMN_IP_PORT , $nodeInstance->getAddressPort()); + $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP , $ipPort[0]); + $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT , $ipPort[1]); $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId()); $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash()); @@ -103,8 +111,15 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); + // Get ip:port combination and "explode" it + $ipPort = $nodeInstance->getAddressPortArray(); + + // Make sure both is valid + assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid')); + // Add ip:port as criteria - $searchInstance->addCriteria(self::DB_COLUMN_IP_PORT, $nodeInstance->getAddressPort()); + $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $ipPort[0]); + $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $ipPort[1]); $searchInstance->setLimit(1); // Query database and get a result instance back @@ -165,20 +180,17 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem } /** - * Finds a node by given session id + * Finds a node locally by given session id * * @param $sessionId Session id to lookup * @return $nodeData Node data array */ - public function findNodeBySessionId ($sessionId) { + public function findNodeLocalBySessionId ($sessionId) { // Get search criteria $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Search for session id and limit it to one entry - $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID, $nodeInstance->getSessionId()); + $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID, $sessionId); $searchInstance->setLimit(1); // Query database and get a result instance back