From: Roland Haeder Date: Mon, 11 May 2015 23:04:27 +0000 (+0200) Subject: Added private key hash distribution in announcement and answer. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=48ea1daf5f0abd43c2747e2b611c4aa79858178a;p=hub.git Added private key hash distribution in announcement and answer. Signed-off-by: Roland Haeder --- diff --git a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php index 3fe340a6c..5d212353e 100644 --- a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php +++ b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php @@ -32,11 +32,12 @@ class AnnouncementNotAcceptedException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,unl=%s/%s,status=%s,mode=%s', + $message = sprintf('[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,hash=%s,unl=%s/%s,status=%s,mode=%s', $messageArray[0]->__toString(), $this->getLine(), $messageArray[1]->__toString(), $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], + $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS], diff --git a/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php b/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php index 0b96d5654..5a3e6c1af 100644 --- a/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php +++ b/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php @@ -32,11 +32,12 @@ class NoAnnouncementAttemptedException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] This node (%s) has not attempted to announce itself, but got an answer from session-id=%s,unl=%s/%s,status=%s.', + $message = sprintf('[%s:%d] This node (%s) has not attempted to announce itself, but got an answer from session-id=%s,hash=%s,unl=%s/%s,status=%s.', $messageArray[0]->__toString(), $this->getLine(), $messageArray[1]->__toString(), $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], + $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS] diff --git a/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php b/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php index 2a6f39233..67861f789 100644 --- a/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php +++ b/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php @@ -33,10 +33,11 @@ class NodeSessionIdVerficationException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] Session id %s cannot be verfied. unl.external=%s,unl.internal=%s,status=%s.', + $message = sprintf('[%s:%d] Session id %s cannot be verfied. hash=%s,unl.external=%s,unl.internal=%s,status=%s.', $messageArray[0]->__toString(), $this->getLine(), $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], + $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS] diff --git a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php index d9519b31e..a0f58ff2e 100644 --- a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php +++ b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php @@ -38,6 +38,7 @@ class PackageAnnouncementTagFilter extends BaseNodeFilter implements FilterableP XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '' + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => '' ); } diff --git a/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php index dc7686181..4edd9057f 100644 --- a/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php @@ -41,6 +41,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, ); // Init message-data->configuration translation array @@ -48,6 +49,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id' + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash' ); // Init config-copy array @@ -56,6 +58,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash', ); // Init array diff --git a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php index d1dcfc731..1014e932f 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -40,6 +40,7 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, BaseXmlAnswerTemplateEngine::ANSWER_STATUS, ); @@ -49,15 +50,17 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id' + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash' */ ); // Init config-copy array $this->configCopy = array( - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address', + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address', + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', + XmlAnnouncementAnswerTemplateEngine::OAANNOUNCEMENT_DATA_SESSION_ID => 'session_id', + XmlAnnouncementAnswerTemplateEngine::OAANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash', ); // Init array diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 7fb24f62e..4fcd38b52 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -348,12 +348,15 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Ask DHT for session id $senderData = $dhtInstance->findNodeLocalBySessionId($sessionId); - // Make sure the element 'private_key_hash' is there - assert(isset($senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH])); - - // Return it - //* DEBUG-DIE */ die('senderData=' . print_r($senderData, TRUE)); - return $senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH]; + // Is an entry found? + if (count($senderData) > 0) { + // Make sure the element 'private_key_hash' is there + /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderData=' . print_r($senderData, TRUE)); + assert(isset($senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH])); + + // Return it + return $senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH]; + } // END - if } /** diff --git a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php index 219c692ad..b8849361c 100644 --- a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php +++ b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php @@ -27,6 +27,7 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com * Some XML nodes must be available for later data extraction */ const ANNOUNCEMENT_DATA_SESSION_ID = 'session-id'; + const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'private-key-hash'; const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status'; const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode'; const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'external-address'; @@ -48,6 +49,7 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com self::ANNOUNCEMENT_DATA_NODE_STATUS, self::ANNOUNCEMENT_DATA_NODE_MODE, self::ANNOUNCEMENT_DATA_SESSION_ID, + self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, 'object-type-list', @@ -169,6 +171,16 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_SESSION_ID); } + /** + * Starts the private key hash + * + * @return void + */ + protected function startPrivateKeyHash () { + // Push the node name on the stacker + $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH); + } + /** * Starts the public ip * @@ -229,6 +241,16 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com $this->getStackInstance()->popNamed('node_announcement'); } + /** + * Finishes the private key hash + * + * @return void + */ + protected function finishPrivateKeyHash () { + // Pop the last entry + $this->getStackInstance()->popNamed('node_announcement'); + } + /** * Finishes the session id * diff --git a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php index ab1bc4c39..98477f128 100644 --- a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php +++ b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php @@ -27,6 +27,7 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im * Some XML nodes must be available for later data extraction */ const ANNOUNCEMENT_DATA_SESSION_ID = 'my-session-id'; + const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash'; const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status'; const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address'; const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address'; @@ -50,6 +51,7 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, self::ANNOUNCEMENT_DATA_NODE_STATUS, self::ANNOUNCEMENT_DATA_SESSION_ID, + self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, // Data from other node 'your-external-address', 'your-internal-address', @@ -162,7 +164,17 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im */ protected function startMySessionId () { // Push the node name on the stacker - $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID); + $this->getStackInstance()->pushNamed('node_announcement_answer', self::OHANNOUNCEMENT_DATA_SESSION_ID); + } + + /** + * Starts the my-private-key-hash + * + * @return void + */ + protected function startMyPrivateKeyHash () { + // Push the node name on the stacker + $this->getStackInstance()->pushNamed('node_announcement_answer', self::OHANNOUNCEMENT_DATA_PRIVATE_KEY_HASH); } /** @@ -185,6 +197,16 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->popNamed('node_announcement_answer'); } + /** + * Finishes the my-private-key-hash + * + * @return void + */ + protected function finishMyPrivateKeyhash () { + // Pop the last entry + $this->getStackInstance()->popNamed('node_announcement_answer'); + } + /** * Finishes the my-session-id * @@ -265,6 +287,26 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id'); } + /** + * Starts the your-private-key-hash + * + * @return void + */ + protected function startYourPrivateKeyHash () { + // Push the node name on the stacker + $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash'); + } + + /** + * Finishes the your-private-key-hash + * + * @return void + */ + protected function finishYourPrivateKeyHash () { + // Pop the last entry + $this->getStackInstance()->popNamed('node_announcement_answer'); + } + /** * Finishes the your-session-id * diff --git a/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php b/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php index 13e4db02e..38a46461a 100644 --- a/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php +++ b/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php @@ -27,6 +27,7 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im * Some XML nodes must be available for later data extraction */ const DHT_BOOTSTRAP_DATA_SESSION_ID = 'my-session-id'; + const DHT_BOOTSTRAP_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash'; const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'my-status'; const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'my-external-address'; const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'my-internal-address'; @@ -168,6 +169,16 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_SESSION_ID); } + /** + * Starts the my-private-key-hash + * + * @return void + */ + protected function startMyPrivateKeyHash () { + // Push the node name on the stacker + $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_PRIVATE_KEY_HASH); + } + /** * Starts the my-status * @@ -208,6 +219,16 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->popNamed('node_dht_bootstrap_answer'); } + /** + * Finishes the my-private-key-hash + * + * @return void + */ + protected function finishMyPrivateKeyHash () { + // Pop the last entry + $this->getStackInstance()->popNamed('node_dht_bootstrap_answer'); + } + /** * Finishes the my-session-id * @@ -288,6 +309,26 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id'); } + /** + * Starts the your-private-key-hash + * + * @return void + */ + protected function startYourPrivateKeyHash () { + // Push the node name on the stacker + $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-private-key-hash'); + } + + /** + * Finishes the your-private-key-hash + * + * @return void + */ + protected function finishYourPrivateKeyHash () { + // Pop the last entry + $this->getStackInstance()->popNamed('node_dht_bootstrap_answer'); + } + /** * Finishes the your-session-id * diff --git a/application/hub/templates/xml/announcement/announcement.xml b/application/hub/templates/xml/announcement/announcement.xml index 4936fb585..ee55bf458 100644 --- a/application/hub/templates/xml/announcement/announcement.xml +++ b/application/hub/templates/xml/announcement/announcement.xml @@ -31,6 +31,8 @@ along with this program. If not, see {?node_default_mode?} {?session_id?} + + {?private_key_hash?} diff --git a/application/hub/templates/xml/answer/announcement/announcement_answer.xml b/application/hub/templates/xml/answer/announcement/announcement_answer.xml index cf6ac32ce..70ed64790 100644 --- a/application/hub/templates/xml/answer/announcement/announcement_answer.xml +++ b/application/hub/templates/xml/answer/announcement/announcement_answer.xml @@ -40,6 +40,10 @@ along with this program. If not, see //--> {?my_session_id?} + {?my_private_key_hash?} + {?my_status?} @@ -61,6 +65,10 @@ along with this program. If not, see Other node's session id //--> {?your_session_id?} + + {?your_private_key_hash?} {?my_session_id?} + {?my_private_key_hash?} + {?my_status?} @@ -62,6 +66,10 @@ along with this program. If not, see Other node's session id //--> {?your_session_id?} + + {?your_private_key_hash?}