aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport')
-rw-r--r--libtransport/src/hicn/transport/core/content_object.cc68
-rw-r--r--libtransport/src/hicn/transport/core/content_object.h4
-rw-r--r--libtransport/src/hicn/transport/core/interest.cc42
-rw-r--r--libtransport/src/hicn/transport/core/interest.h4
-rw-r--r--libtransport/src/hicn/transport/core/packet.cc16
-rw-r--r--libtransport/src/hicn/transport/core/packet.h4
6 files changed, 79 insertions, 59 deletions
diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/hicn/transport/core/content_object.cc
index df16923e9..107ab8567 100644
--- a/libtransport/src/hicn/transport/core/content_object.cc
+++ b/libtransport/src/hicn/transport/core/content_object.cc
@@ -34,14 +34,14 @@ namespace core {
ContentObject::ContentObject(const Name &name, Packet::Format format)
: Packet(format) {
if (TRANSPORT_EXPECT_FALSE(
- hicn_data_set_name(format, (hicn_header_t *)packet_start_,
- name.getStructReference()) < 0)) {
+ hicn_data_set_name(format, packet_start_, name.getStructReference()) <
+ 0)) {
throw errors::RuntimeException("Error filling the packet name.");
}
- if (TRANSPORT_EXPECT_FALSE(
- hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
- name_.getStructReference()) < 0)) {
+ if (TRANSPORT_EXPECT_FALSE(hicn_data_get_name(format_, packet_start_,
+ name_.getStructReference()) <
+ 0)) {
throw errors::MalformedPacketException();
}
}
@@ -57,15 +57,15 @@ ContentObject::ContentObject(const Name &name, hicn_format_t format,
ContentObject::ContentObject(const uint8_t *buffer, std::size_t size)
: Packet(buffer, size) {
- if (hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
+ 0) {
throw errors::RuntimeException("Error getting name from content object.");
}
}
ContentObject::ContentObject(MemBufPtr &&buffer) : Packet(std::move(buffer)) {
- if (hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
+ 0) {
throw errors::RuntimeException("Error getting name from content object.");
}
}
@@ -73,8 +73,8 @@ ContentObject::ContentObject(MemBufPtr &&buffer) : Packet(std::move(buffer)) {
ContentObject::ContentObject(ContentObject &&other) : Packet(std::move(other)) {
name_ = std::move(other.name_);
- if (hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
+ 0) {
throw errors::MalformedPacketException();
}
}
@@ -84,15 +84,15 @@ ContentObject::~ContentObject() {}
void ContentObject::replace(MemBufPtr &&buffer) {
Packet::replace(std::move(buffer));
- if (hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
+ 0) {
throw errors::RuntimeException("Error getting name from content object.");
}
}
const Name &ContentObject::getName() const {
if (!name_) {
- if (hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_data_get_name(format_, packet_start_,
(hicn_name_t *)name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
@@ -104,34 +104,33 @@ const Name &ContentObject::getName() const {
Name &ContentObject::getWritableName() { return const_cast<Name &>(getName()); }
void ContentObject::setName(const Name &name) {
- if (hicn_data_set_name(format_, (hicn_header_t *)packet_start_,
- name.getStructReference()) < 0) {
+ if (hicn_data_set_name(format_, packet_start_, name.getStructReference()) <
+ 0) {
throw errors::RuntimeException("Error setting content object name.");
}
- if (hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
+ 0) {
throw errors::MalformedPacketException();
}
}
void ContentObject::setName(Name &&name) {
- if (hicn_data_set_name(format_, (hicn_header_t *)packet_start_,
- name.getStructReference()) < 0) {
+ if (hicn_data_set_name(format_, packet_start_, name.getStructReference()) <
+ 0) {
throw errors::RuntimeException(
"Error getting the payload length from content object.");
}
- if (hicn_data_get_name(format_, (hicn_header_t *)packet_start_,
- name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
+ 0) {
throw errors::MalformedPacketException();
}
}
uint32_t ContentObject::getPathLabel() const {
uint32_t path_label;
- if (hicn_data_get_path_label((hicn_header_t *)packet_start_, &path_label) <
- 0) {
+ if (hicn_data_get_path_label(packet_start_, &path_label) < 0) {
throw errors::RuntimeException(
"Error retrieving the path label from content object");
}
@@ -150,8 +149,7 @@ ContentObject &ContentObject::setPathLabel(uint32_t path_label) {
}
void ContentObject::setLocator(const ip_address_t &ip_address) {
- if (hicn_data_set_locator(format_, (hicn_header_t *)packet_start_,
- &ip_address) < 0) {
+ if (hicn_data_set_locator(format_, packet_start_, &ip_address) < 0) {
throw errors::RuntimeException("Error setting content object locator");
}
@@ -161,13 +159,29 @@ void ContentObject::setLocator(const ip_address_t &ip_address) {
ip_address_t ContentObject::getLocator() const {
ip_address_t ip;
- if (hicn_data_get_locator(format_, (hicn_header_t *)packet_start_, &ip) < 0) {
+ if (hicn_data_get_locator(format_, packet_start_, &ip) < 0) {
throw errors::RuntimeException("Error getting content object locator.");
}
return ip;
}
+void ContentObject::setLifetime(uint32_t lifetime) {
+ if (hicn_data_set_expiry_time(packet_start_, lifetime) < 0) {
+ throw errors::MalformedPacketException();
+ }
+}
+
+uint32_t ContentObject::getLifetime() const {
+ uint32_t lifetime = 0;
+
+ if (hicn_data_get_expiry_time(packet_start_, &lifetime) < 0) {
+ throw errors::MalformedPacketException();
+ }
+
+ return lifetime;
+}
+
void ContentObject::resetForHash() {
if (hicn_data_reset_for_hash(
format_, reinterpret_cast<hicn_header_t *>(packet_start_)) < 0) {
diff --git a/libtransport/src/hicn/transport/core/content_object.h b/libtransport/src/hicn/transport/core/content_object.h
index fd531e8bc..5af548fe4 100644
--- a/libtransport/src/hicn/transport/core/content_object.h
+++ b/libtransport/src/hicn/transport/core/content_object.h
@@ -64,6 +64,10 @@ class ContentObject : public Packet {
ip_address_t getLocator() const override;
+ void setLifetime(uint32_t lifetime) override;
+
+ uint32_t getLifetime() const override;
+
private:
void resetForHash() override;
};
diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/hicn/transport/core/interest.cc
index 85f24bb25..bd7b57422 100644
--- a/libtransport/src/hicn/transport/core/interest.cc
+++ b/libtransport/src/hicn/transport/core/interest.cc
@@ -33,12 +33,12 @@ namespace core {
Interest::Interest(const Name &interest_name, Packet::Format format)
: Packet(format) {
- if (hicn_interest_set_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_set_name(format_, packet_start_,
interest_name.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_get_name(format_, packet_start_,
name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
@@ -48,14 +48,14 @@ Interest::Interest(hicn_format_t format) : Interest(base_name, format) {}
Interest::Interest(const uint8_t *buffer, std::size_t size)
: Packet(buffer, size) {
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_get_name(format_, packet_start_,
name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
Interest::Interest(MemBufPtr &&buffer) : Packet(std::move(buffer)) {
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_get_name(format_, packet_start_,
name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
@@ -71,7 +71,7 @@ Interest::~Interest() {}
void Interest::replace(MemBufPtr &&buffer) {
Packet::replace(std::move(buffer));
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_get_name(format_, packet_start_,
name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
@@ -79,7 +79,7 @@ void Interest::replace(MemBufPtr &&buffer) {
const Name &Interest::getName() const {
if (!name_) {
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_get_name(format_, packet_start_,
(hicn_name_t *)name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
@@ -91,32 +91,31 @@ const Name &Interest::getName() const {
Name &Interest::getWritableName() { return const_cast<Name &>(getName()); }
void Interest::setName(const Name &name) {
- if (hicn_interest_set_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_set_name(format_, packet_start_,
name.getStructReference()) < 0) {
throw errors::RuntimeException("Error setting interest name.");
}
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_get_name(format_, packet_start_,
name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
void Interest::setName(Name &&name) {
- if (hicn_interest_set_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_set_name(format_, packet_start_,
name.getStructReference()) < 0) {
throw errors::RuntimeException("Error setting interest name.");
}
- if (hicn_interest_get_name(format_, (hicn_header_t *)packet_start_,
+ if (hicn_interest_get_name(format_, packet_start_,
name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
void Interest::setLocator(const ip_address_t &ip_address) {
- if (hicn_interest_set_locator(format_, (hicn_header_t *)packet_start_,
- &ip_address) < 0) {
+ if (hicn_interest_set_locator(format_, packet_start_, &ip_address) < 0) {
throw errors::RuntimeException("Error setting interest locator.");
}
@@ -126,14 +125,29 @@ void Interest::setLocator(const ip_address_t &ip_address) {
ip_address_t Interest::getLocator() const {
ip_address_t ip;
- if (hicn_interest_get_locator(format_, (hicn_header_t *)packet_start_, &ip) <
- 0) {
+ if (hicn_interest_get_locator(format_, packet_start_, &ip) < 0) {
throw errors::RuntimeException("Error getting interest locator.");
}
return ip;
}
+void Interest::setLifetime(uint32_t lifetime) {
+ if (hicn_interest_set_lifetime(packet_start_, lifetime) < 0) {
+ throw errors::MalformedPacketException();
+ }
+}
+
+uint32_t Interest::getLifetime() const {
+ uint32_t lifetime = 0;
+
+ if (hicn_interest_get_lifetime(packet_start_, &lifetime) < 0) {
+ throw errors::MalformedPacketException();
+ }
+
+ return lifetime;
+}
+
void Interest::resetForHash() {
if (hicn_interest_reset_for_hash(
format_, reinterpret_cast<hicn_header_t *>(packet_start_)) < 0) {
diff --git a/libtransport/src/hicn/transport/core/interest.h b/libtransport/src/hicn/transport/core/interest.h
index 74979d8d0..48c833a73 100644
--- a/libtransport/src/hicn/transport/core/interest.h
+++ b/libtransport/src/hicn/transport/core/interest.h
@@ -59,6 +59,10 @@ class Interest
ip_address_t getLocator() const override;
+ void setLifetime(uint32_t lifetime) override;
+
+ uint32_t getLifetime() const override;
+
private:
void resetForHash() override;
};
diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/hicn/transport/core/packet.cc
index ea9666ff7..c5c2b9796 100644
--- a/libtransport/src/hicn/transport/core/packet.cc
+++ b/libtransport/src/hicn/transport/core/packet.cc
@@ -140,22 +140,6 @@ std::size_t Packet::headerSize() const {
reinterpret_cast<uint8_t *>(packet_start_));
}
-void Packet::setLifetime(uint32_t lifetime) {
- if (hicn_interest_set_lifetime(packet_start_, lifetime) < 0) {
- throw errors::MalformedPacketException();
- }
-}
-
-uint32_t Packet::getLifetime() const {
- uint32_t lifetime = 0;
-
- if (hicn_packet_get_lifetime(packet_start_, &lifetime) < 0) {
- throw errors::MalformedPacketException();
- }
-
- return lifetime;
-}
-
Packet &Packet::appendPayload(std::unique_ptr<utils::MemBuf> &&payload) {
separateHeaderPayload();
diff --git a/libtransport/src/hicn/transport/core/packet.h b/libtransport/src/hicn/transport/core/packet.h
index 16191dd7f..88d9f9318 100644
--- a/libtransport/src/hicn/transport/core/packet.h
+++ b/libtransport/src/hicn/transport/core/packet.h
@@ -109,9 +109,9 @@ class Packet : public std::enable_shared_from_this<Packet> {
virtual void setName(Name &&name) = 0;
- virtual void setLifetime(uint32_t lifetime);
+ virtual void setLifetime(uint32_t lifetime) = 0;
- virtual uint32_t getLifetime() const;
+ virtual uint32_t getLifetime() const = 0;
Packet &appendPayload(const uint8_t *buffer, std::size_t length);