}
/**
- * Resolves a session id into an ip:port combination
+ * Resolves a session id into an ip:port combination. The opposite method
+ * is resolveSessionIdByIpPort()
*
* @param $sessionId A valid session id
* @param $protocol Name of the used protocol: TCP/UDP
* @return $recipient Recipient as ip:port combination
*/
protected function resolveIpPortBySessionId ($sessionId, $protocol) {
- // Get a wrapper instance
- $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
- // And ask it for the session id
- $recipient = $wrapperInstance->resolveIpPortBySessionId($sessionId, $protocol);
+ // And ask it for ip:port by given session id
+ $recipient = $dhtInstance->findNodeBySessionId($sessionId, $protocol);
+ die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
// Is the recipient invalid?
if ($recipient == 'invalid:invalid') {
// Is the session id the same?
if ($nodeInstance->getSessionId() == $sessionId) {
// Then get the ip:port from it, assume TCP by default
- $recipient = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_' . strtolower($protocol) . '_listen_port');
+ $recipient = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
} // END - if
} // END - if
}
/**
- * Resolves a ip:port combination into a session id
+ * Resolves a ip:port combination into a session id. The "opposite" method
+ * is resolveIpPortBySessionId().
*
* @param $ipPort Ip:port combination
* @param $protocol Name of used protocol (TCP/UDP)
* @return $sessionId Valid session id
*/
public static function resolveSessionIdByIpPort ($ipPort, $protocol) {
- // Get a wrapper instance
- $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
- // And ask it for the session id
- $sessionId = $wrapperInstance->resolveSessionIdByIpPort($ipPort, $protocol);
+ // And ask it for session id by given ip:port
+ $recipient = $dhtInstance->findNodeByIpPort($ipPort, $protocol);
+ die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
// Return result
return $sessionId;
// Return it
return $ip;
}
+
+ /**
+ * Determine IP or 'internal_ip' if set
+ *
+ * @return $ip The determined external ip of this node
+ */
+ public static function determineOwnInternalIp () {
+ // Is the internal_ip config entry set?
+ if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('allow_publish_internal_ip') == 'N') {
+ // Not allowed to publish internal IP, so use external
+ $ip = self::determineOwnExternalIp();
+ } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_ip') != '') {
+ // Use it as internal ip
+ $ip = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_ip');
+ } else {
+ // Determine own internal ip by connecting to my (coder) server at 188.138.90.169
+ $ip = ConsoleTools::acquireSelfIPAddress();
+ }
+
+ // Return it
+ return $ip;
+ }
}
// [EOF]