From: Roland Haeder Date: Fri, 11 Sep 2015 22:42:33 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=490d9083df3d1353555888355b3ecc633ebafba7;p=hub.git Continued: - got rid of some array fields as the miner doesn't need this. - Introduced TAG_SELF_CONNECT and TAG_CLAIM_MINING_REWARD constants Signed-off-by: Roland Haeder --- diff --git a/application/hub/classes/filter/tags/class_PackageSelfConnectTagFilter.php b/application/hub/classes/filter/tags/class_PackageSelfConnectTagFilter.php index bd75e4505..97331fd7b 100644 --- a/application/hub/classes/filter/tags/class_PackageSelfConnectTagFilter.php +++ b/application/hub/classes/filter/tags/class_PackageSelfConnectTagFilter.php @@ -81,7 +81,7 @@ class PackageSelfConnectTagFilter extends BaseNodeFilter implements FilterablePa */ public function processMessage (array $messageData, Receivable $packageInstance) { // Process generic - $this->genericProcessMessage('self_connect', $messageData, $packageInstance); + $this->genericProcessMessage(BaseTag::TAG_SELF_CONNECT, $messageData, $packageInstance); } /** diff --git a/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php b/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php index 5c57946f0..45fa460ba 100644 --- a/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php +++ b/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php @@ -36,7 +36,7 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode { $this->setRecipientType(NetworkPackage::NETWORK_TARGET_SELF); // Set package tags - $this->setPackageTags(array('self_connect')); + $this->setPackageTags(array(BaseTags::TAG_SELF_CONNECT)); } /** diff --git a/application/hub/classes/package/class_NetworkPackage.php b/application/hub/classes/package/class_NetworkPackage.php index af1de4a2a..620e14728 100644 --- a/application/hub/classes/package/class_NetworkPackage.php +++ b/application/hub/classes/package/class_NetworkPackage.php @@ -117,11 +117,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R /** * Constants for message data array */ - const MESSAGE_ARRAY_DATA = 'message_data'; - const MESSAGE_ARRAY_TYPE = 'message_type'; - const MESSAGE_ARRAY_SENDER = 'message_sender'; - const MESSAGE_ARRAY_HASH = 'message_hash'; - const MESSAGE_ARRAY_TAGS = 'message_tags'; + const MESSAGE_ARRAY_DATA = 'message_data'; + const MESSAGE_ARRAY_TYPE = 'message_type'; + const MESSAGE_ARRAY_SENDER = 'message_sender'; + const MESSAGE_ARRAY_HASH = 'message_hash'; + const MESSAGE_ARRAY_TAGS = 'message_tags'; + const MESSAGE_ARRAY_DATA_NODE_ID = 'node-id'; /** * Generic answer status field @@ -1468,7 +1469,14 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Make sure the required elements are there assert(isset($messageData[self::MESSAGE_ARRAY_SENDER])); assert(isset($messageData[self::MESSAGE_ARRAY_HASH])); - assert(isset($messageData[self::MESSAGE_ARRAY_TAGS])); + assert(isset($messageData[self::MESSAGE_ARRAY_DATA][self::MESSAGE_ARRAY_DATA_NODE_ID])); + + // Copy node id + $messageData[self::MESSAGE_ARRAY_DATA_NODE_ID] = $messageData[self::MESSAGE_ARRAY_DATA][self::MESSAGE_ARRAY_DATA_NODE_ID]; + + // Let's get rid of some fields that is not needed by the miner: + unset($messageData[self::MESSAGE_ARRAY_TYPE]); + unset($messageData[self::MESSAGE_ARRAY_DATA]); // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE)); @@ -1477,7 +1485,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $nodeId = HubTools::resolveNodeIdBySessionId($messageData[self::MESSAGE_ARRAY_SENDER]); // Is 'claim_reward' the message type? - if (in_array('claim_reward', $messageData[self::MESSAGE_ARRAY_TAGS])) { + if (in_array(BaseTag::TAG_CLAIM_MINING_REWARD, $messageData[self::MESSAGE_ARRAY_TAGS])) { /* * Then don't feed this message to the miner as this causes an * endless loop of mining. @@ -1485,6 +1493,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R return; } // END - if + // Also remove tags as the miner don't need this. + unset($messageData[self::MESSAGE_ARRAY_TAGS]); + $this->partialStub('@TODO nodeId=' . $nodeId . ',messageData=' . print_r($messageData, TRUE)); } } diff --git a/application/hub/classes/tags/class_BaseTags.php b/application/hub/classes/tags/class_BaseTags.php index f48581776..da61999b3 100644 --- a/application/hub/classes/tags/class_BaseTags.php +++ b/application/hub/classes/tags/class_BaseTags.php @@ -22,6 +22,12 @@ * along with this program. If not, see . */ class BaseTags extends BaseHubSystem implements Registerable { + /** + * Constants for tags + */ + const TAG_SELF_CONNECT = 'self_connect'; + const TAG_CLAIM_MINING_REWARD = 'claim_reward'; + /** * An array with all tags */ diff --git a/application/hub/classes/template/connect/class_XmlSelfConnectTemplateEngine.php b/application/hub/classes/template/connect/class_XmlSelfConnectTemplateEngine.php index 543fc7251..d0552c20d 100644 --- a/application/hub/classes/template/connect/class_XmlSelfConnectTemplateEngine.php +++ b/application/hub/classes/template/connect/class_XmlSelfConnectTemplateEngine.php @@ -62,7 +62,7 @@ class XmlSelfConnectTemplateEngine extends BaseXmlTemplateEngine implements Comp $templateInstance = new XmlSelfConnectTemplateEngine(); // Init template instance - $templateInstance->initXmlTemplateEngine('node', 'self_connect'); + $templateInstance->initXmlTemplateEngine('node', BaseTag::TAG_SELF_CONNECT); // Return the prepared instance return $templateInstance; diff --git a/application/hub/templates/xml/dht_publish/publish.xml b/application/hub/templates/xml/dht_publish/publish.xml index 63738a82f..9608075f2 100644 --- a/application/hub/templates/xml/dht_publish/publish.xml +++ b/application/hub/templates/xml/dht_publish/publish.xml @@ -33,7 +33,7 @@ along with this program. If not, see type as much as you want here, as all will be removed by the compaction step. - The following example data will be published (execept __idx): + The following example data will be published (except __idx): Array ( [node_mode] => regular