// Get an instance of this class
$discoveryInstance = new PackageRecipientDiscovery();
- // Output debug message
- $discoveryInstance->debugOutput('RECIPIENT-DISCOVERY: Initialized.');
-
// Get recipients list instance and set it
$listInstance = RecipientListFactory::createRecipientListInstance();
$discoveryInstance->setListInstance($listInstance);
+ // Output debug message
+ $discoveryInstance->debugOutput('RECIPIENT-DISCOVERY: Initialized.');
+
// Return the prepared instance
return $discoveryInstance;
}
} // END - switch
}
+ /**
+ * Tries to discover all recipients by given decoded package data.
+ *
+ * @param $decodedData Decoded raw package data array
+ * @return void
+ * @todo Add some validation of recipient field, e.g. ip:port is found
+ */
+ public function discoverDecodedRecipients (array $decodedData) {
+ // First clear all recipients
+ $this->clearRecipients();
+
+ // Explode 'recipient', first element is the IP/hostname
+ $recipient = explode(':', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Is the 'recipient' field same as this peer's IP?
+ if ($recipient[0] == HubTools::determineOwnExternalIp()) {
+ /*
+ * Is same as own external IP, don't do anything here so other
+ * classes found an empty recipient list for internal (own) handling
+ * of the original content.
+ */
+
+ // Debug output (may flood)
+ /* NOISY-DEBUG: */ $this->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' matches own ip (' . HubTools::determineOwnExternalIp() . ')');
+ } else {
+ // Debug output (may flood)
+ /* NOISY-DEBUG: */ $this->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' is different than own ip (' . HubTools::determineOwnExternalIp() . '), need to forward (not yet implemented)!');
+
+ // This package is to be delivered to someone else, so add it
+ $this->getListInstance()->addEntry('ip_port', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ }
+ }
+
/**
* "Getter" for recipient iterator
*
return $iteratorInstance;
}
+ /**
+ * Checks whether the recipient list is empty
+ *
+ * @return $isEmpty Whether the recipient list is empty
+ */
+ public function isRecipientListEmpty () {
+ // Check it ...
+ $isEmpty = ($this->getListInstance()->count() == 0);
+
+ // Return it
+ return $isEmpty;
+ }
+
/**
* Clears all recipients for e.g. another package to deliver. This method
* simply clears the inner list instance.