Fix received packet storing unnecessary header

Added rtt (uint16_t) to UDPC_PacketInfo.
This commit is contained in:
Stephen Seo 2019-12-27 13:35:28 +09:00
parent fdd57bc538
commit 1a39039065
4 changed files with 34 additions and 4 deletions

View file

@ -263,6 +263,8 @@ uint32_t generateConnectionID(Context &ctx);
float durationToFSec(const std::chrono::steady_clock::duration& duration); float durationToFSec(const std::chrono::steady_clock::duration& duration);
uint16_t durationToMS(const std::chrono::steady_clock::duration& duration);
float timePointsToFSec( float timePointsToFSec(
const std::chrono::steady_clock::time_point& older, const std::chrono::steady_clock::time_point& older,
const std::chrono::steady_clock::time_point& newer); const std::chrono::steady_clock::time_point& newer);

View file

@ -1657,11 +1657,12 @@ void UDPC::Context::update_impl() {
"Received packet is out of order"); "Received packet is out of order");
} }
if((pktType == 0 && bytes > (int)UDPC_NSFULL_HEADER_SIZE) if(pktType == 0 && bytes > (int)UDPC_NSFULL_HEADER_SIZE) {
| (pktType == 1 && bytes > (int)UDPC_LSFULL_HEADER_SIZE)) {
UDPC_PacketInfo recPktInfo = UDPC::get_empty_pinfo(); UDPC_PacketInfo recPktInfo = UDPC::get_empty_pinfo();
std::memcpy(recPktInfo.data, recvBuf, bytes); std::memcpy(recPktInfo.data + UDPC_NSFULL_HEADER_SIZE,
recPktInfo.dataSize = bytes; recvBuf,
bytes - UDPC_NSFULL_HEADER_SIZE);
recPktInfo.dataSize = bytes - UDPC_NSFULL_HEADER_SIZE;
recPktInfo.flags = recPktInfo.flags =
(isConnect ? 0x1 : 0) (isConnect ? 0x1 : 0)
| (isPing ? 0x2 : 0) | (isPing ? 0x2 : 0)
@ -1671,6 +1672,25 @@ void UDPC::Context::update_impl() {
recPktInfo.receiver.addr = in6addr_loopback; recPktInfo.receiver.addr = in6addr_loopback;
recPktInfo.sender.port = ntohs(receivedData.sin6_port); recPktInfo.sender.port = ntohs(receivedData.sin6_port);
recPktInfo.receiver.port = ntohs(socketInfo.sin6_port); recPktInfo.receiver.port = ntohs(socketInfo.sin6_port);
recPktInfo.rtt = durationToMS(iter->second.rtt);
receivedPkts.push(recPktInfo);
} else if(pktType == 1 && bytes > (int)UDPC_LSFULL_HEADER_SIZE) {
UDPC_PacketInfo recPktInfo = UDPC::get_empty_pinfo();
std::memcpy(recPktInfo.data + UDPC_LSFULL_HEADER_SIZE,
recvBuf,
bytes - UDPC_LSFULL_HEADER_SIZE);
recPktInfo.dataSize = bytes - UDPC_LSFULL_HEADER_SIZE;
recPktInfo.flags =
(isConnect ? 0x1 : 0)
| (isPing ? 0x2 : 0)
| (isNotRecChecked ? 0x4 : 0)
| (isResending ? 0x8 : 0);
recPktInfo.sender.addr = receivedData.sin6_addr;
recPktInfo.receiver.addr = in6addr_loopback;
recPktInfo.sender.port = ntohs(receivedData.sin6_port);
recPktInfo.receiver.port = ntohs(socketInfo.sin6_port);
recPktInfo.rtt = durationToMS(iter->second.rtt);
receivedPkts.push(recPktInfo); receivedPkts.push(recPktInfo);
} else { } else {
@ -1753,6 +1773,10 @@ float UDPC::durationToFSec(const std::chrono::steady_clock::duration& duration)
/ (float)std::decay_t<decltype(duration)>::period::den; / (float)std::decay_t<decltype(duration)>::period::den;
} }
uint16_t UDPC::durationToMS(const std::chrono::steady_clock::duration& duration) {
return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
}
float UDPC::timePointsToFSec( float UDPC::timePointsToFSec(
const std::chrono::steady_clock::time_point& older, const std::chrono::steady_clock::time_point& older,
const std::chrono::steady_clock::time_point& newer) { const std::chrono::steady_clock::time_point& newer) {
@ -1766,6 +1790,7 @@ UDPC_PacketInfo UDPC::get_empty_pinfo() {
{0}, // data (array) {0}, // data (array)
0, // flags 0, // flags
0, // dataSize 0, // dataSize
0, // rtt
{ // sender { // sender
{0}, // ipv6 addr {0}, // ipv6 addr
0, // scope_id 0, // scope_id

View file

@ -168,6 +168,7 @@ typedef struct {
* was received. * was received.
*/ */
uint16_t dataSize; uint16_t dataSize;
uint16_t rtt;
/// The \p UDPC_ConnectionId of the sender /// The \p UDPC_ConnectionId of the sender
UDPC_ConnectionId sender; UDPC_ConnectionId sender;
/// The \p UDPC_ConnectionId of the receiver /// The \p UDPC_ConnectionId of the receiver

View file

@ -271,11 +271,13 @@ int main(int argc, char **argv) {
} }
do { do {
received = UDPC_get_received(context, &size); received = UDPC_get_received(context, &size);
// printf("Received data size = %u\n", received.dataSize);
if(received.dataSize == sizeof(unsigned int)) { if(received.dataSize == sizeof(unsigned int)) {
if((received.flags & 0x8) != 0) { if((received.flags & 0x8) != 0) {
temp2 = ntohl(*((unsigned int*)received.data)); temp2 = ntohl(*((unsigned int*)received.data));
printf("Got out of order, data = %u\n", temp2); printf("Got out of order, data = %u\n", temp2);
} }
// printf("Got rtt %u\n", received.rtt);
} }
} while (size > 0); } while (size > 0);
} }