Merge pull request #140 from majestrate/dev

flush snode traffic queues
This commit is contained in:
Jeff 2018-12-12 13:37:48 -05:00 committed by GitHub
commit 8d630eb5a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 4 deletions

View File

@ -547,6 +547,7 @@ set(TEST_SRC
test/test_llarp_queue.cpp
test/test_llarp_queue_manager.cpp
test/test_llarp_thread_pool.cpp
test/test_service_address.cpp
)
set(TEST_EXE testAll)

View File

@ -205,7 +205,7 @@ namespace llarp
{
if(HasAddress(addr.data()))
{
huint32_t ip = ObtainIPForAddr(addr.data(), true);
huint32_t ip = ObtainIPForAddr(addr.data(), false);
msg.AddINReply(ip);
}
else
@ -460,6 +460,7 @@ namespace llarp
if(m_SNodes.at(itr->second))
{
llarp::LogInfo(Name(), " send to service node");
sendFunc = std::bind(&TunEndpoint::SendToSNodeOrQueue, this,
itr->second.data(), std::placeholders::_1);
}
@ -480,6 +481,7 @@ namespace llarp
});
if(m_Exit)
m_Exit->FlushUpstreamTraffic();
FlushSNodeTraffic();
}
bool

View File

@ -123,6 +123,17 @@ namespace llarp
}
}
void
Endpoint::FlushSNodeTraffic()
{
auto itr = m_SNodeSessions.begin();
while(itr != m_SNodeSessions.end())
{
itr->second->FlushUpstreamTraffic();
++itr;
}
}
void
Endpoint::Tick(llarp_time_t now)
{
@ -1068,8 +1079,7 @@ namespace llarp
void
Endpoint::EnsurePathToSNode(const RouterID& snode)
{
auto range = m_SNodeSessions.equal_range(snode);
if(range.first == range.second)
if(m_SNodeSessions.count(snode) == 0)
{
auto themIP = ObtainIPForAddr(snode, true);
m_SNodeSessions.emplace(std::make_pair(

View File

@ -162,6 +162,9 @@ namespace llarp
bool
SendToSNodeOrQueue(const byte_t* addr, llarp_buffer_t payload);
void
FlushSNodeTraffic();
struct PendingBuffer
{
std::vector< byte_t > payload;

View File

@ -0,0 +1,24 @@
#include <gtest/gtest.h>
#include <service/address.hpp>
struct ServiceAddressTest : public ::testing::Test
{
const std::string snode =
"8zfiwpgonsu5zpddpxwdurxyb19x6r96xy4qbikff99jwsziws9y.snode";
const std::string loki =
"7okic5x5do3uh3usttnqz9ek3uuoemdrwzto1hciwim9f947or6y.loki";
};
TEST_F(ServiceAddressTest, TestParseSNodeNotLoki)
{
llarp::service::Address addr;
ASSERT_TRUE(addr.FromString(snode, ".snode"));
ASSERT_FALSE(addr.FromString(snode, ".loki"));
}
TEST_F(ServiceAddressTest, TestParseLokiNotSNode)
{
llarp::service::Address addr;
ASSERT_FALSE(addr.FromString(loki, ".snode"));
ASSERT_TRUE(addr.FromString(loki, ".loki"));
}