Convert to span and avoid deprecated ndn-cxx functions
Change-Id: I45c50527fe53498b53a3d951458bdff8e7d7778c
This commit is contained in:
1 parent
b98aa3aca6
commit
a599d2aac9
24 files changed
+117
-130
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -46,7 +46,7 @@ template<class Protocol, class Addressing = Unicast>
|
||||
class DatagramTransport : public Transport
|
||||
{
|
||||
public:
|
||||
typedef Protocol protocol;
|
||||
using protocol = Protocol;
|
||||
|
||||
/** \brief Construct datagram transport.
|
||||
*
|
||||
@@ -58,11 +58,11 @@ public:
|
||||
ssize_t
|
||||
getSendQueueLength() override;
|
||||
|
||||
/** \brief Receive datagram, translate buffer into packet, deliver to parent class.
|
||||
/**
|
||||
* \brief Receive datagram, translate buffer into packet, deliver to parent class.
|
||||
*/
|
||||
void
|
||||
receiveDatagram(const uint8_t* buffer, size_t nBytesReceived,
|
||||
const boost::system::error_code& error);
|
||||
receiveDatagram(span<const uint8_t> buffer, const boost::system::error_code& error);
|
||||
|
||||
protected:
|
||||
void
|
||||
@@ -170,23 +170,23 @@ DatagramTransport<T, U>::doSend(const Block& packet)
|
||||
|
||||
template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::receiveDatagram(const uint8_t* buffer, size_t nBytesReceived,
|
||||
DatagramTransport<T, U>::receiveDatagram(span<const uint8_t> buffer,
|
||||
const boost::system::error_code& error)
|
||||
{
|
||||
if (error)
|
||||
return processErrorCode(error);
|
||||
|
||||
NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes from " << m_sender);
|
||||
NFD_LOG_FACE_TRACE("Received: " << buffer.size() << " bytes from " << m_sender);
|
||||
|
||||
bool isOk = false;
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
|
||||
std::tie(isOk, element) = Block::fromBuffer(buffer);
|
||||
if (!isOk) {
|
||||
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << m_sender);
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
}
|
||||
if (element.size() != nBytesReceived) {
|
||||
if (element.size() != buffer.size()) {
|
||||
NFD_LOG_FACE_WARN("Received datagram size and decoded element size don't match");
|
||||
// This packet won't extend the face lifetime
|
||||
return;
|
||||
@@ -200,7 +200,7 @@ template<class T, class U>
|
||||
void
|
||||
DatagramTransport<T, U>::handleReceive(const boost::system::error_code& error, size_t nBytesReceived)
|
||||
{
|
||||
receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
|
||||
receiveDatagram(ndn::make_span(m_receiveBuffer).first(nBytesReceived), error);
|
||||
|
||||
if (m_socket.is_open())
|
||||
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -120,26 +120,24 @@ EthernetChannel::handleRead(const boost::system::error_code& error,
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t* pkt;
|
||||
size_t len;
|
||||
span<const uint8_t> pkt;
|
||||
std::string err;
|
||||
std::tie(pkt, len, err) = m_pcap.readNextPacket();
|
||||
std::tie(pkt, err) = m_pcap.readNextPacket();
|
||||
|
||||
if (pkt == nullptr) {
|
||||
if (pkt.empty()) {
|
||||
NFD_LOG_CHAN_WARN("Read error: " << err);
|
||||
}
|
||||
else {
|
||||
const ether_header* eh;
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, m_localEndpoint->getEthernetAddress(),
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_localEndpoint->getEthernetAddress(),
|
||||
m_localEndpoint->getEthernetAddress());
|
||||
if (eh == nullptr) {
|
||||
NFD_LOG_CHAN_DEBUG(err);
|
||||
}
|
||||
else {
|
||||
ethernet::Address sender(eh->ether_shost);
|
||||
pkt += ethernet::HDR_LEN;
|
||||
len -= ethernet::HDR_LEN;
|
||||
processIncomingPacket(pkt, len, sender, onFaceCreated, onReceiveFailed);
|
||||
pkt = pkt.subspan(ethernet::HDR_LEN);
|
||||
processIncomingPacket(pkt, sender, onFaceCreated, onReceiveFailed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +152,7 @@ EthernetChannel::handleRead(const boost::system::error_code& error,
|
||||
}
|
||||
|
||||
void
|
||||
EthernetChannel::processIncomingPacket(const uint8_t* packet, size_t length,
|
||||
EthernetChannel::processIncomingPacket(span<const uint8_t> packet,
|
||||
const ethernet::Address& sender,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed)
|
||||
@@ -182,7 +180,7 @@ EthernetChannel::processIncomingPacket(const uint8_t* packet, size_t length,
|
||||
|
||||
// dispatch the packet to the face for processing
|
||||
auto* transport = static_cast<UnicastEthernetTransport*>(face->getTransport());
|
||||
transport->receivePayload(packet, length, sender);
|
||||
transport->receivePayload(packet, sender);
|
||||
}
|
||||
|
||||
std::pair<bool, shared_ptr<Face>>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -111,7 +111,7 @@ private:
|
||||
const FaceCreationFailedCallback& onReceiveFailed);
|
||||
|
||||
void
|
||||
processIncomingPacket(const uint8_t* packet, size_t length,
|
||||
processIncomingPacket(span<const uint8_t> packet,
|
||||
const ethernet::Address& sender,
|
||||
const FaceCreatedCallback& onFaceCreated,
|
||||
const FaceCreationFailedCallback& onReceiveFailed);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2018, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -30,14 +30,13 @@
|
||||
namespace nfd {
|
||||
namespace ethernet {
|
||||
|
||||
std::pair<const ether_header*, std::string>
|
||||
checkFrameHeader(const uint8_t* packet, size_t length,
|
||||
const Address& localAddr, const Address& destAddr)
|
||||
std::tuple<const ether_header*, std::string>
|
||||
checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Address& destAddr)
|
||||
{
|
||||
if (length < HDR_LEN + MIN_DATA_LEN)
|
||||
return {nullptr, "Received frame too short: " + to_string(length) + " bytes"};
|
||||
if (packet.size() < HDR_LEN + MIN_DATA_LEN)
|
||||
return {nullptr, "Received frame too short: " + to_string(packet.size()) + " bytes"};
|
||||
|
||||
const ether_header* eh = reinterpret_cast<const ether_header*>(packet);
|
||||
const ether_header* eh = reinterpret_cast<const ether_header*>(packet.data());
|
||||
|
||||
// in some cases VLAN-tagged frames may survive the BPF filter,
|
||||
// make sure we do not process those frames (see #3348)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -27,6 +27,7 @@
|
||||
#define NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
|
||||
|
||||
#include "core/common.hpp"
|
||||
|
||||
#include <ndn-cxx/net/ethernet.hpp>
|
||||
#include <net/ethernet.h>
|
||||
|
||||
@@ -35,9 +36,8 @@ namespace ethernet {
|
||||
|
||||
using namespace ndn::ethernet;
|
||||
|
||||
std::pair<const ether_header*, std::string>
|
||||
checkFrameHeader(const uint8_t* packet, size_t length,
|
||||
const Address& localAddr, const Address& destAddr);
|
||||
std::tuple<const ether_header*, std::string>
|
||||
checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Address& destAddr);
|
||||
|
||||
} // namespace ethernet
|
||||
} // namespace nfd
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -125,17 +125,17 @@ EthernetTransport::sendPacket(const ndn::Block& block)
|
||||
// pad with zeroes if the payload is too short
|
||||
if (block.size() < ethernet::MIN_DATA_LEN) {
|
||||
static const uint8_t padding[ethernet::MIN_DATA_LEN] = {};
|
||||
buffer.appendByteArray(padding, ethernet::MIN_DATA_LEN - block.size());
|
||||
buffer.appendBytes(ndn::make_span(padding).subspan(block.size()));
|
||||
}
|
||||
|
||||
// construct and prepend the ethernet header
|
||||
uint16_t ethertype = boost::endian::native_to_big(ethernet::ETHERTYPE_NDN);
|
||||
buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ðertype), ethernet::TYPE_LEN);
|
||||
buffer.prependByteArray(m_srcAddress.data(), m_srcAddress.size());
|
||||
buffer.prependByteArray(m_destAddress.data(), m_destAddress.size());
|
||||
buffer.prependBytes({reinterpret_cast<const uint8_t*>(ðertype), ethernet::TYPE_LEN});
|
||||
buffer.prependBytes(m_srcAddress);
|
||||
buffer.prependBytes(m_destAddress);
|
||||
|
||||
// send the frame
|
||||
int sent = pcap_inject(m_pcap, buffer.buf(), buffer.size());
|
||||
int sent = pcap_inject(m_pcap, buffer.data(), buffer.size());
|
||||
if (sent < 0)
|
||||
handleError("Send operation failed: " + m_pcap.getLastError());
|
||||
else if (static_cast<size_t>(sent) < buffer.size())
|
||||
@@ -168,26 +168,24 @@ EthernetTransport::handleRead(const boost::system::error_code& error)
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t* pkt;
|
||||
size_t len;
|
||||
span<const uint8_t> pkt;
|
||||
std::string err;
|
||||
std::tie(pkt, len, err) = m_pcap.readNextPacket();
|
||||
std::tie(pkt, err) = m_pcap.readNextPacket();
|
||||
|
||||
if (pkt == nullptr) {
|
||||
if (pkt.empty()) {
|
||||
NFD_LOG_FACE_WARN("Read error: " << err);
|
||||
}
|
||||
else {
|
||||
const ether_header* eh;
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, m_srcAddress,
|
||||
std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_srcAddress,
|
||||
m_destAddress.isMulticast() ? m_destAddress : m_srcAddress);
|
||||
if (eh == nullptr) {
|
||||
NFD_LOG_FACE_WARN(err);
|
||||
}
|
||||
else {
|
||||
ethernet::Address sender(eh->ether_shost);
|
||||
pkt += ethernet::HDR_LEN;
|
||||
len -= ethernet::HDR_LEN;
|
||||
receivePayload(pkt, len, sender);
|
||||
pkt = pkt.subspan(ethernet::HDR_LEN);
|
||||
receivePayload(pkt, sender);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,14 +200,13 @@ EthernetTransport::handleRead(const boost::system::error_code& error)
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTransport::receivePayload(const uint8_t* payload, size_t length,
|
||||
const ethernet::Address& sender)
|
||||
EthernetTransport::receivePayload(span<const uint8_t> payload, const ethernet::Address& sender)
|
||||
{
|
||||
NFD_LOG_FACE_TRACE("Received: " << length << " bytes from " << sender);
|
||||
NFD_LOG_FACE_TRACE("Received: " << payload.size() << " bytes from " << sender);
|
||||
|
||||
bool isOk = false;
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(payload, length);
|
||||
std::tie(isOk, element) = Block::fromBuffer(payload);
|
||||
if (!isOk) {
|
||||
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << sender);
|
||||
// This packet won't extend the face lifetime
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -49,13 +49,11 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Processes the payload of an incoming frame
|
||||
* @param payload Pointer to the first byte of data after the Ethernet header
|
||||
* @param length Payload length
|
||||
* @param payload Payload bytes, starting from the first byte after the Ethernet header
|
||||
* @param sender Sender address
|
||||
*/
|
||||
void
|
||||
receivePayload(const uint8_t* payload, size_t length,
|
||||
const ethernet::Address& sender);
|
||||
receivePayload(span<const uint8_t> payload, const ethernet::Address& sender);
|
||||
|
||||
protected:
|
||||
EthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -69,10 +69,9 @@ LpReassembler::receiveFragment(EndpointId remoteEndpoint, const lp::Packet& pack
|
||||
|
||||
// check for fast path
|
||||
if (fragIndex == 0 && fragCount == 1) {
|
||||
ndn::Buffer::const_iterator fragBegin, fragEnd;
|
||||
std::tie(fragBegin, fragEnd) = packet.get<lp::FragmentField>();
|
||||
Block netPkt(&*fragBegin, std::distance(fragBegin, fragEnd));
|
||||
return std::make_tuple(true, netPkt, packet);
|
||||
auto frag = packet.get<lp::FragmentField>();
|
||||
Block netPkt({frag.first, frag.second});
|
||||
return {true, netPkt, packet};
|
||||
}
|
||||
|
||||
// check Sequence and compute message identifier
|
||||
@@ -140,7 +139,7 @@ LpReassembler::doReassembly(const Key& key)
|
||||
it = std::copy(fragBegin, fragEnd, it);
|
||||
}
|
||||
|
||||
return Block(&*(fragBuffer.cbegin()), std::distance(fragBuffer.cbegin(), fragBuffer.cend()));
|
||||
return Block(fragBuffer);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -174,7 +174,7 @@ LpReliability::processIncomingPacket(const lp::Packet& pkt)
|
||||
// Check for recent received Sequences to remove
|
||||
auto now = time::steady_clock::now();
|
||||
auto rto = m_rttEst.getEstimatedRto();
|
||||
while (m_recentRecvSeqsQueue.size() > 0 &&
|
||||
while (!m_recentRecvSeqsQueue.empty() &&
|
||||
now > m_recentRecvSeqs[m_recentRecvSeqsQueue.front()] + rto) {
|
||||
m_recentRecvSeqs.erase(m_recentRecvSeqsQueue.front());
|
||||
m_recentRecvSeqsQueue.pop();
|
||||
@@ -226,7 +226,7 @@ LpReliability::assignTxSequence(lp::Packet& frag)
|
||||
{
|
||||
lp::Sequence txSeq = ++m_lastTxSeqNo;
|
||||
frag.set<lp::TxSequenceField>(txSeq);
|
||||
if (m_unackedFrags.size() > 0 && m_lastTxSeqNo == m_firstUnackedFrag->first) {
|
||||
if (!m_unackedFrags.empty() && m_lastTxSeqNo == m_firstUnackedFrag->first) {
|
||||
NDN_THROW(std::length_error("TxSequence range exceeded"));
|
||||
}
|
||||
return m_lastTxSeqNo;
|
||||
@@ -310,10 +310,8 @@ LpReliability::onLpPacketLost(lp::Sequence txSeq, bool isTimeout)
|
||||
// Notify strategy of dropped Interest (if any)
|
||||
if (netPkt->isInterest) {
|
||||
BOOST_ASSERT(netPkt->pkt.has<lp::FragmentField>());
|
||||
ndn::Buffer::const_iterator fragBegin, fragEnd;
|
||||
std::tie(fragBegin, fragEnd) = netPkt->pkt.get<lp::FragmentField>();
|
||||
Block frag(&*fragBegin, std::distance(fragBegin, fragEnd));
|
||||
onDroppedInterest(Interest(frag));
|
||||
auto frag = netPkt->pkt.get<lp::FragmentField>();
|
||||
onDroppedInterest(Interest(Block({frag.first, frag.second})));
|
||||
}
|
||||
|
||||
// Delete this LpPacket from m_unackedFrags
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -79,7 +79,7 @@ PcapHelper::activate(int dlt)
|
||||
}
|
||||
|
||||
void
|
||||
PcapHelper::close()
|
||||
PcapHelper::close() noexcept
|
||||
{
|
||||
if (m_pcap) {
|
||||
pcap_close(m_pcap);
|
||||
@@ -100,7 +100,7 @@ PcapHelper::getFd() const
|
||||
}
|
||||
|
||||
std::string
|
||||
PcapHelper::getLastError() const
|
||||
PcapHelper::getLastError() const noexcept
|
||||
{
|
||||
return pcap_geterr(m_pcap);
|
||||
}
|
||||
@@ -128,19 +128,19 @@ PcapHelper::setPacketFilter(const char* filter) const
|
||||
NDN_THROW(Error("pcap_setfilter: " + getLastError()));
|
||||
}
|
||||
|
||||
std::tuple<const uint8_t*, size_t, std::string>
|
||||
PcapHelper::readNextPacket() const
|
||||
std::tuple<span<const uint8_t>, std::string>
|
||||
PcapHelper::readNextPacket() const noexcept
|
||||
{
|
||||
pcap_pkthdr* header;
|
||||
const uint8_t* packet;
|
||||
|
||||
int ret = pcap_next_ex(m_pcap, &header, &packet);
|
||||
if (ret < 0)
|
||||
return std::make_tuple(nullptr, 0, getLastError());
|
||||
return {span<uint8_t>{}, getLastError()};
|
||||
else if (ret == 0)
|
||||
return std::make_tuple(nullptr, 0, "timed out");
|
||||
return {span<uint8_t>{}, "timed out"};
|
||||
else
|
||||
return std::make_tuple(packet, header->caplen, "");
|
||||
return {{packet, header->caplen}, ""};
|
||||
}
|
||||
|
||||
} // namespace face
|
||||
|
||||
+11
-12
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
* @sa pcap_close(3pcap)
|
||||
*/
|
||||
void
|
||||
close();
|
||||
close() noexcept;
|
||||
|
||||
/**
|
||||
* @brief Obtain a file descriptor that can be used in calls such as select(2) and poll(2).
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
* @sa pcap_geterr(3pcap)
|
||||
*/
|
||||
std::string
|
||||
getLastError() const;
|
||||
getLastError() const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Get the number of packets dropped by the kernel, as reported by libpcap.
|
||||
@@ -120,18 +120,17 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Read the next packet captured on the interface.
|
||||
* @return If successful, returns a tuple containing a pointer to the received packet
|
||||
* (including the link-layer header) and the size of the packet; the third
|
||||
* element must be ignored. On failure, returns a tuple containing nullptr,
|
||||
* 0, and the reason for the failure.
|
||||
* @warning The returned pointer must not be freed by the caller, and is valid only
|
||||
* until the next call to this function.
|
||||
* @return If successful, returns a tuple containing a read-only view of the received
|
||||
* packet bytes (including the link-layer header) and a second element that
|
||||
* must be ignored. On failure, returns a tuple containing an empty span and
|
||||
* the reason for the failure.
|
||||
* @warning The returned span is valid only until the next call to this function.
|
||||
* @sa pcap_next_ex(3pcap)
|
||||
*/
|
||||
std::tuple<const uint8_t*, size_t, std::string>
|
||||
readNextPacket() const;
|
||||
std::tuple<span<const uint8_t>, std::string>
|
||||
readNextPacket() const noexcept;
|
||||
|
||||
operator pcap_t*() const
|
||||
operator pcap_t*() const noexcept
|
||||
{
|
||||
return m_pcap;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -43,7 +43,7 @@ template<class Protocol>
|
||||
class StreamTransport : public Transport
|
||||
{
|
||||
public:
|
||||
typedef Protocol protocol;
|
||||
using protocol = Protocol;
|
||||
|
||||
/** \brief Construct stream transport.
|
||||
*
|
||||
@@ -244,16 +244,17 @@ StreamTransport<T>::handleReceive(const boost::system::error_code& error,
|
||||
NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
|
||||
|
||||
m_receiveBufferSize += nBytesReceived;
|
||||
auto bufferView = ndn::make_span(m_receiveBuffer, m_receiveBufferSize);
|
||||
size_t offset = 0;
|
||||
bool isOk = true;
|
||||
while (m_receiveBufferSize - offset > 0) {
|
||||
while (offset < bufferView.size()) {
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(m_receiveBuffer + offset, m_receiveBufferSize - offset);
|
||||
std::tie(isOk, element) = Block::fromBuffer(bufferView.subspan(offset));
|
||||
if (!isOk)
|
||||
break;
|
||||
|
||||
offset += element.size();
|
||||
BOOST_ASSERT(offset <= m_receiveBufferSize);
|
||||
BOOST_ASSERT(offset <= bufferView.size());
|
||||
|
||||
this->receive(element);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -141,7 +141,7 @@ UdpChannel::handleNewPeer(const boost::system::error_code& error,
|
||||
|
||||
// dispatch the datagram to the face for processing
|
||||
auto* transport = static_cast<UnicastUdpTransport*>(face->getTransport());
|
||||
transport->receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
|
||||
transport->receiveDatagram(ndn::make_span(m_receiveBuffer).first(nBytesReceived), error);
|
||||
|
||||
waitForNewPeer(onFaceCreated, onReceiveFailed);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -98,7 +98,7 @@ WebSocketTransport::receiveMessage(const std::string& msg)
|
||||
|
||||
bool isOk = false;
|
||||
Block element;
|
||||
std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.data()), msg.size());
|
||||
std::tie(isOk, element) = Block::fromBuffer({reinterpret_cast<const uint8_t*>(msg.data()), msg.size()});
|
||||
if (!isOk) {
|
||||
NFD_LOG_FACE_WARN("Failed to parse message payload");
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -120,12 +120,12 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveTooLarge, T, DatagramTransportFixtures,
|
||||
{
|
||||
TRANSPORT_TEST_INIT();
|
||||
|
||||
std::vector<uint8_t> bytes(ndn::MAX_NDN_PACKET_SIZE, 0);
|
||||
auto pkt1 = ndn::encoding::makeBinaryBlock(300, bytes.data(), bytes.size() - 6);
|
||||
const std::vector<uint8_t> bytes(ndn::MAX_NDN_PACKET_SIZE, 0);
|
||||
auto pkt1 = ndn::encoding::makeBinaryBlock(300, ndn::make_span(bytes).subspan(6));
|
||||
ndn::Buffer buf1(pkt1.begin(), pkt1.end());
|
||||
BOOST_REQUIRE_EQUAL(buf1.size(), ndn::MAX_NDN_PACKET_SIZE);
|
||||
|
||||
auto pkt2 = ndn::encoding::makeBinaryBlock(301, bytes.data(), bytes.size());
|
||||
auto pkt2 = ndn::encoding::makeBinaryBlock(301, bytes);
|
||||
ndn::Buffer buf2(pkt2.begin(), pkt2.end());
|
||||
BOOST_REQUIRE_GT(buf2.size(), ndn::MAX_NDN_PACKET_SIZE);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -141,12 +141,12 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveTooLarge, T, StreamTransportFixtures, T)
|
||||
{
|
||||
TRANSPORT_TEST_INIT();
|
||||
|
||||
std::vector<uint8_t> bytes(ndn::MAX_NDN_PACKET_SIZE, 0);
|
||||
auto pkt1 = ndn::encoding::makeBinaryBlock(300, bytes.data(), bytes.size() - 6);
|
||||
const std::vector<uint8_t> bytes(ndn::MAX_NDN_PACKET_SIZE, 0);
|
||||
auto pkt1 = ndn::encoding::makeBinaryBlock(300, ndn::make_span(bytes).subspan(6));
|
||||
ndn::Buffer buf1(pkt1.begin(), pkt1.end());
|
||||
BOOST_REQUIRE_EQUAL(buf1.size(), ndn::MAX_NDN_PACKET_SIZE);
|
||||
|
||||
auto pkt2 = ndn::encoding::makeBinaryBlock(301, bytes.data(), bytes.size());
|
||||
auto pkt2 = ndn::encoding::makeBinaryBlock(301, bytes);
|
||||
ndn::Buffer buf2(pkt2.begin(), pkt2.end());
|
||||
BOOST_REQUIRE_GT(buf2.size(), ndn::MAX_NDN_PACKET_SIZE);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -309,7 +309,8 @@ BOOST_AUTO_TEST_CASE(BadKeyLocator_BadKeyLocatorType)
|
||||
BOOST_CHECK_EQUAL(authorize1(
|
||||
[] (Interest& interest) {
|
||||
ndn::KeyLocator kl;
|
||||
kl.setKeyDigest(ndn::encoding::makeBinaryBlock(tlv::KeyDigest, "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD", 8));
|
||||
kl.setKeyDigest(ndn::makeBinaryBlock(tlv::KeyDigest,
|
||||
{0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD}));
|
||||
ndn::SignatureInfo sigInfo(tlv::SignatureSha256WithRsa);
|
||||
sigInfo.setKeyLocator(kl);
|
||||
setNameComponent(interest, ndn::signed_interest::POS_SIG_INFO,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -217,15 +217,17 @@ BOOST_AUTO_TEST_CASE(FaceQuery)
|
||||
auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
|
||||
|
||||
auto generateQuery = [] (const FaceQueryFilter& filter) {
|
||||
return Interest(Name("/localhost/nfd/faces/query").append(filter.wireEncode()))
|
||||
return Interest(Name("/localhost/nfd/faces/query")
|
||||
.append(filter.wireEncode().begin(), filter.wireEncode().end()))
|
||||
.setCanBePrefix(true);
|
||||
};
|
||||
|
||||
auto schemeQuery = generateQuery(FaceQueryFilter().setUriScheme("dummy"));
|
||||
auto idQuery = generateQuery(FaceQueryFilter().setFaceId(face1->getId()));
|
||||
auto scopeQuery = generateQuery(FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL));
|
||||
auto invalidContent = ndn::makeStringBlock(tlv::Content, "invalid");
|
||||
auto invalidQueryName = Name("/localhost/nfd/faces/query")
|
||||
.append(ndn::makeStringBlock(tlv::Content, "invalid"));
|
||||
.append(invalidContent.begin(), invalidContent.end());
|
||||
auto invalidQuery = Interest(invalidQueryName).setCanBePrefix(true);
|
||||
|
||||
receiveInterest(schemeQuery); // face1 and face2 expected
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -123,8 +123,7 @@ BOOST_AUTO_TEST_CASE(RegisterNotificationStream)
|
||||
auto post = m_manager.registerNotificationStream("test-notification");
|
||||
setTopPrefix();
|
||||
|
||||
const uint8_t buf[] = {0x82, 0x01, 0x02};
|
||||
post(Block(buf, sizeof(buf)));
|
||||
post(Block({0x82, 0x01, 0x02}));
|
||||
advanceClocks(1_ms);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -49,7 +49,7 @@ protected:
|
||||
bool isUnsolicited = false)
|
||||
{
|
||||
auto data = makeData(name);
|
||||
data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
|
||||
data->setContent(ndn::make_span(reinterpret_cast<const uint8_t*>(&id), sizeof(id)));
|
||||
|
||||
if (modifyData != nullptr) {
|
||||
modifyData(*data);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -60,7 +60,7 @@ KeyChainFixture::makeCert(const Key& key, const std::string& issuer, const Key&
|
||||
cert.setFreshnessPeriod(1_h);
|
||||
|
||||
// set content
|
||||
cert.setContent(key.getPublicKey().data(), key.getPublicKey().size());
|
||||
cert.setContent(key.getPublicKey());
|
||||
|
||||
// set signature info
|
||||
ndn::SignatureInfo info;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -105,7 +105,7 @@ protected: // StatusDataset
|
||||
void
|
||||
sendEmptyDataset(const Name& prefix)
|
||||
{
|
||||
this->sendDatasetReply(prefix, nullptr, 0);
|
||||
this->sendDatasetReply(prefix, span<uint8_t>{});
|
||||
}
|
||||
|
||||
/** \brief send one WireEncodable in reply to StatusDataset request
|
||||
@@ -141,7 +141,7 @@ protected: // StatusDataset
|
||||
payload2.wireEncode(buffer);
|
||||
payload1.wireEncode(buffer);
|
||||
|
||||
this->sendDatasetReply(prefix, buffer.buf(), buffer.size());
|
||||
this->sendDatasetReply(prefix, buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2019, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -98,10 +98,9 @@ BOOST_AUTO_TEST_CASE(Normal)
|
||||
}
|
||||
|
||||
if (interest.getName() == "/localhop/ndn-autoconf/hub") {
|
||||
const char FACEURI[] = "udp://router.example.net";
|
||||
auto data = makeData(Name("/localhop/ndn-autoconf/hub").appendVersion());
|
||||
data->setFreshnessPeriod(1_s);
|
||||
data->setContent(makeBinaryBlock(tlv::nfd::Uri, FACEURI, ::strlen(FACEURI)));
|
||||
data->setContent(makeStringBlock(tlv::nfd::Uri, "udp://router.example.net"));
|
||||
face.receive(*data);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2021, Regents of the University of California,
|
||||
* Copyright (c) 2014-2022, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -53,12 +53,9 @@ Program::Program(const Options& options, Face& face, KeyChain& keyChain)
|
||||
void
|
||||
Program::enableHubData(const FaceUri& hubFaceUri)
|
||||
{
|
||||
std::string uri = hubFaceUri.toString();
|
||||
|
||||
auto data = make_shared<Data>(Name(HUB_DATA_NAME).appendVersion());
|
||||
data->setFreshnessPeriod(1_h);
|
||||
data->setContent(makeBinaryBlock(tlv::nfd::Uri,
|
||||
reinterpret_cast<const uint8_t*>(uri.data()), uri.size()));
|
||||
data->setContent(makeStringBlock(tlv::nfd::Uri, hubFaceUri.toString()));
|
||||
m_keyChain.sign(*data);
|
||||
|
||||
m_face.setInterestFilter(HUB_DATA_NAME,
|
||||
|
||||
Reference in new issue
Block a user