diff options
Diffstat (limited to 'libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc')
-rw-r--r-- | libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc index ae8aebec6..0d45ba49d 100644 --- a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc +++ b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc @@ -14,6 +14,7 @@ */ #include <core/udp_connector.h> +#include <hicn/transport/utils/uri.h> #include <io_modules/hicn-light/hicn_forwarder_module.h> extern "C" { @@ -24,15 +25,37 @@ namespace transport { namespace core { +HicnForwarderModule::ForwarderUrlInitializer + HicnForwarderModule::forwarder_url_initializer_; + HicnForwarderModule::HicnForwarderModule() : IoModule(), connector_(nullptr), seq_(0) {} HicnForwarderModule::~HicnForwarderModule() {} void HicnForwarderModule::connect(bool is_consumer) { - connector_->connect("localhost", 9695); - connector_->setRole(is_consumer ? Connector::Role::CONSUMER - : Connector::Role::PRODUCER); + if (!connector_->isConnected()) { + // Parse forwarder URI + utils::Uri uri; + uri.parse(forwarder_url_initializer_.getForwarderUrl()); + + // Safechecks + CHECK(uri.getProtocol() == "hicn") + << "The protocol of the forwarder url should be hicn"; + uint16_t port_min = (1 << 10); + uint16_t port_max = (1 << 16) - 1; + + uint16_t port = std::stoul(uri.getPort()); + + CHECK(port > port_min && port < port_max) + << "The port should be between " << port_min << " and " << port_max; + + VLOG(1) << "Connecting to " << uri.getLocator() << ":" << uri.getPort(); + + connector_->connect(uri.getLocator(), port); + connector_->setRole(is_consumer ? Connector::Role::CONSUMER + : Connector::Role::PRODUCER); + } } bool HicnForwarderModule::isConnected() { return connector_->isConnected(); } |