aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2020-04-20 12:55:28 +0200
committerMauro Sardara <msardara@cisco.com>2020-09-14 17:29:46 +0000
commit1fc9a18f95fd2ff491679e4c8de519afe49d8c47 (patch)
tree15a6cbe5fd92745ab9859ad701f9fc3e44737aaa /libtransport/src
parent9c1aa190114dcd0be16dd4ce49459955fc4f7434 (diff)
[HICN-598] [HICN-599] Fix hicn_name_t definition conflicts.
Change-Id: Ica8db44e27c3a4911ea869e91f96b781809373d8 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src')
-rw-r--r--libtransport/src/core/name.cc41
-rw-r--r--libtransport/src/implementation/socket_producer.h8
2 files changed, 10 insertions, 39 deletions
diff --git a/libtransport/src/core/name.cc b/libtransport/src/core/name.cc
index 811e93b87..3455460fc 100644
--- a/libtransport/src/core/name.cc
+++ b/libtransport/src/core/name.cc
@@ -13,14 +13,13 @@
* limitations under the License.
*/
+#include <core/manifest_format.h>
#include <hicn/transport/core/name.h>
#include <hicn/transport/errors/errors.h>
#include <hicn/transport/errors/tokenizer_exception.h>
#include <hicn/transport/utils/hash.h>
#include <hicn/transport/utils/string_tokenizer.h>
-#include <core/manifest_format.h>
-
namespace transport {
namespace core {
@@ -29,28 +28,19 @@ Name::Name() { name_ = {}; }
Name::Name(int family, const uint8_t *ip_address, std::uint32_t suffix)
: name_({}) {
- name_.type = HNT_UNSPEC;
- std::size_t length;
- uint8_t *dst = NULL;
-
if (family == AF_INET) {
- dst = name_.ip4.prefix_as_u8;
- length = IPV4_ADDR_LEN;
- name_.type = HNT_CONTIGUOUS_V4;
+ name_.prefix.ip4.as_u32 = *(u32 *)(ip_address);
} else if (family == AF_INET6) {
- dst = name_.ip6.prefix_as_u8;
- length = IPV6_ADDR_LEN;
- name_.type = HNT_CONTIGUOUS_V6;
+ std::memcpy(&name_.prefix.ip6.as_u64[0], ip_address, IPV6_ADDR_LEN);
} else {
throw errors::RuntimeException("Specified name family does not exist.");
}
- std::memcpy(dst, ip_address, length);
- *reinterpret_cast<std::uint32_t *>(dst + length) = suffix;
+ name_.suffix = suffix;
}
Name::Name(const char *name, uint32_t segment) {
- name_.type = HNT_UNSPEC;
+ name_ = {};
if (hicn_name_create(name, segment, &name_) < 0) {
throw errors::InvalidIpAddressException();
}
@@ -60,7 +50,7 @@ Name::Name(const std::string &uri, uint32_t segment)
: Name(uri.c_str(), segment) {}
Name::Name(const std::string &uri) {
- name_.type = HNT_UNSPEC;
+ name_ = {};
utils::StringTokenizer tokenizer(uri, "|");
std::string ip_address;
std::string seq_number;
@@ -125,9 +115,7 @@ uint32_t Name::getHash32(bool consider_suffix) const {
return hash;
}
-void Name::clear() { name_.type = HNT_UNSPEC; };
-
-Name::Type Name::getType() const { return name_.type; }
+void Name::clear() { name_ = {}; };
uint32_t Name::getSuffix() const {
uint32_t ret = 0;
@@ -148,20 +136,7 @@ Name &Name::setSuffix(uint32_t seq_number) {
}
std::shared_ptr<Sockaddr> Name::getAddress() const {
- Sockaddr *ret = nullptr;
-
- switch (name_.type) {
- case HNT_CONTIGUOUS_V4:
- case HNT_IOV_V4:
- ret = (Sockaddr *)new Sockaddr4;
- break;
- case HNT_CONTIGUOUS_V6:
- case HNT_IOV_V6:
- ret = (Sockaddr *)new Sockaddr6;
- break;
- default:
- throw errors::MalformedNameException();
- }
+ Sockaddr *ret = (Sockaddr *)(new sockaddr_storage());
if (hicn_name_to_sockaddr_address((hicn_name_t *)&name_, ret) < 0) {
throw errors::MalformedNameException();
diff --git a/libtransport/src/implementation/socket_producer.h b/libtransport/src/implementation/socket_producer.h
index a6f0f969e..574723607 100644
--- a/libtransport/src/implementation/socket_producer.h
+++ b/libtransport/src/implementation/socket_producer.h
@@ -134,16 +134,12 @@ class ProducerSocket : public Socket<BasePortal>,
core::Packet::Format hf_format = core::Packet::Format::HF_UNSPEC;
core::Packet::Format hf_format_ah = core::Packet::Format::HF_UNSPEC;
- if (content_name.getType() == HNT_CONTIGUOUS_V4 ||
- content_name.getType() == HNT_IOV_V4) {
+ if (content_name.isIp4()) {
hf_format = core::Packet::Format::HF_INET_TCP;
hf_format_ah = core::Packet::Format::HF_INET_TCP_AH;
- } else if (content_name.getType() == HNT_CONTIGUOUS_V6 ||
- content_name.getType() == HNT_IOV_V6) {
+ } else {
hf_format = core::Packet::Format::HF_INET6_TCP;
hf_format_ah = core::Packet::Format::HF_INET6_TCP_AH;
- } else {
- throw errors::RuntimeException("Unknown name format.");
}
format = hf_format;