Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Dec 22, 2023
1 parent c58c0f1 commit b8beb45
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
15 changes: 7 additions & 8 deletions pdns/dnsdistdist/doq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,12 @@ static void handleReadableStream(DOQFrontend& frontend, ClientState& clientState

static void handleSocketReadable(DOQFrontend& frontend, ClientState& clientState, Socket& sock)
{
PacketBuffer packet(4096);
while (true) {
DEBUGLOG("Received datagram");
std::string bufferStr;
packet.resize(4096);
ComboAddress client;
if (!sock.recvFromAsync(bufferStr, client) || bufferStr.size() == 0) {
if (!sock.recvFromAsync(packet, client) || packet.size() == 0) {

Check warning on line 649 in pdns/dnsdistdist/doq.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, dnsdist)

the 'empty' method should be used to check for emptiness instead of 'size' (readability-container-size-empty - Level=Warning)
return;
}

Expand All @@ -658,8 +659,7 @@ static void handleSocketReadable(DOQFrontend& frontend, ClientState& clientState
std::array<uint8_t, MAX_TOKEN_LEN> token{};
size_t token_len = token.size();

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
auto res = quiche_header_info(reinterpret_cast<const uint8_t*>(bufferStr.data()), bufferStr.size(), LOCAL_CONN_ID_LEN,
auto res = quiche_header_info(packet.data(), packet.size(), LOCAL_CONN_ID_LEN,
&version, &type,
scid.data(), &scid_len,
dcid.data(), &dcid_len,
Expand Down Expand Up @@ -718,25 +718,24 @@ static void handleSocketReadable(DOQFrontend& frontend, ClientState& clientState
clientState.local.getSocklen(),
};

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
auto done = quiche_conn_recv(conn->get().d_conn.get(), reinterpret_cast<uint8_t*>(bufferStr.data()), bufferStr.size(), &recv_info);
auto done = quiche_conn_recv(conn->get().d_conn.get(), packet.data(), packet.size(), &recv_info);
if (done < 0) {
continue;
}

if (quiche_conn_is_established(conn->get().d_conn.get()) || quiche_conn_is_in_early_data(conn->get().d_conn.get())) {
auto readable = std::unique_ptr<quiche_stream_iter, decltype(&quiche_stream_iter_free)>(quiche_conn_readable(conn->get().d_conn.get()), quiche_stream_iter_free);

flushEgress(sock, conn->get().d_conn, client);

auto readable = std::unique_ptr<quiche_stream_iter, decltype(&quiche_stream_iter_free)>(quiche_conn_readable(conn->get().d_conn.get()), quiche_stream_iter_free);
uint64_t streamID = 0;
while (quiche_stream_iter_next(readable.get(), &streamID)) {
handleReadableStream(frontend, clientState, *conn, streamID, client, serverConnID);
}
}
else {
DEBUGLOG("Connection not established");
cerr<<"connection from "<<client.toStringWithPort()<<" not established yet, just fed "<<bufferStr.size()<<endl;
cerr<<"connection from "<<client.toStringWithPort()<<" not established yet, just fed "<<packet.size()<<endl;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions pdns/dnsreplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,17 +387,18 @@ std::unique_ptr<Socket> s_socket = nullptr;
static void receiveFromReference()
try
{
string packet;
PacketBuffer packet;
ComboAddress remote;
int res=waitForData(s_socket->getHandle(), g_timeoutMsec/1000, 1000*(g_timeoutMsec%1000));

if(res < 0 || res==0)
return;

while(s_socket->recvFromAsync(packet)) {
while(s_socket->recvFromAsync(packet, &remote)) {
try {
s_weanswers++;
MOADNSParser mdp(false, packet.c_str(), packet.length());
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
MOADNSParser mdp(false, reinterpret_cast<const char*>(packet.data()), packet.size());
if(!mdp.d_header.qr) {
cout<<"Received a question from our reference nameserver!"<<endl;
continue;
Expand Down
33 changes: 18 additions & 15 deletions pdns/sstuff.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <boost/utility.hpp>
#include <csignal>
#include "namespaces.hh"

#include "noinitvector.hh"

typedef int ProtocolType; //!< Supported protocol types

Expand Down Expand Up @@ -176,32 +176,35 @@ public:
void recvFrom(string &dgram, ComboAddress &ep)
{
socklen_t remlen = sizeof(ep);
ssize_t bytes;
d_buffer.resize(s_buflen);
if((bytes=recvfrom(d_socket, &d_buffer[0], s_buflen, 0, reinterpret_cast<sockaddr *>(&ep) , &remlen)) <0)
throw NetworkError("After recvfrom: "+stringerror());

dgram.assign(d_buffer, 0, static_cast<size_t>(bytes));
if (dgram.size() < s_buflen) {
dgram.resize(s_buflen);
}
auto bytes = recvfrom(d_socket, d_buffer.data(), dgram.size(), 0, reinterpret_cast<sockaddr *>(&ep) , &remlen);
if (bytes < 0) {
throw NetworkError("After recvfrom: " + stringerror());
}
dgram.resize(static_cast<size_t>(bytes));
}

bool recvFromAsync(string &dgram, ComboAddress& remote)
bool recvFromAsync(PacketBuffer& dgram, ComboAddress& remote)
{
socklen_t remlen = sizeof(remote);
ssize_t bytes;
d_buffer.resize(s_buflen);
if((bytes=recvfrom(d_socket, &d_buffer[0], s_buflen, 0, reinterpret_cast<sockaddr *>(&remote), &remlen))<0) {
if(errno!=EAGAIN) {
throw NetworkError("After async recvfrom: "+stringerror());
if (dgram.size() < s_buflen) {
dgram.resize(s_buflen);
}
auto bytes = recvfrom(d_socket, dgram.data(), dgram.size(), 0, reinterpret_cast<sockaddr *>(&remote), &remlen);
if (bytes < 0) {
if (errno != EAGAIN) {
throw NetworkError("After async recvfrom: " + stringerror());
}
else {
return false;
}
}
dgram.assign(d_buffer, 0, static_cast<size_t>(bytes));
dgram.resize(static_cast<size_t>(bytes));
return true;
}


//! For datagram sockets, send a datagram to a destination
void sendTo(const char* msg, size_t len, const ComboAddress &ep)
{
Expand Down

0 comments on commit b8beb45

Please sign in to comment.