fix dht bug, probably, re-enable loopback testnet functionality

pull/35/head
Jeff Becker 6 years ago
parent c6f1355c5d
commit cc106ed37b
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -63,6 +63,10 @@ else()
set(WITH_STATIC ON)
endif()
if(TESTNET)
add_definitions(-DTESTNET=1)
endif()
add_cflags("-Wall")
add_cxxflags("-Wall")

@ -91,7 +91,7 @@ testnet-clean: clean
rm -rf $(TESTNET_ROOT)
testnet-configure: testnet-clean
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX) -DTESTNET=1
testnet-build: testnet-configure
ninja
@ -105,7 +105,7 @@ shared: shared-configure
testnet:
cp $(EXE) $(TESTNET_EXE)
mkdir -p $(TESTNET_ROOT)
python3 contrib/testnet/genconf.py --bin=$(TESTNET_EXE) --svc=$(TESTNET_SERVERS) --clients=$(TESTNET_CLIENTS) --dir=$(TESTNET_ROOT) --out $(TESTNET_CONF) --connect=3
python3 contrib/testnet/genconf.py --bin=$(TESTNET_EXE) --svc=$(TESTNET_SERVERS) --clients=$(TESTNET_CLIENTS) --dir=$(TESTNET_ROOT) --out $(TESTNET_CONF) --connect=4
LLARP_DEBUG=$(TESTNET_DEBUG) supervisord -n -d $(TESTNET_ROOT) -l $(TESTNET_LOG) -c $(TESTNET_CONF)
test: debug

@ -21,8 +21,9 @@ namespace llarp
relayed = relay;
}
FindIntroMessage(const llarp::service::Tag& tag, uint64_t txid)
: IMessage({}), N(tag), T(txid)
FindIntroMessage(const llarp::service::Tag& tag, uint64_t txid,
uint64_t r = 3)
: IMessage({}), R(r), N(tag), T(txid)
{
S.Zero();
}

@ -21,11 +21,7 @@ namespace llarp
Tag(const std::string& str) : Tag()
{
#ifndef MIN
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
memcpy(data(), str.c_str(), MIN(16UL, str.size()));
#undef MIN
#endif
memcpy(data(), str.c_str(), std::min(16UL, str.size()));
}
Tag&
@ -38,11 +34,7 @@ namespace llarp
Tag&
operator=(const std::string& str)
{
#ifndef MIN
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
memcpy(data(), str.data(), MIN(16UL, str.size()));
#undef MIN
#endif
memcpy(data(), str.data(), std::min(16UL, str.size()));
return *this;
}
@ -67,4 +59,4 @@ namespace llarp
} // namespace service
} // namespace llarp
#endif
#endif

@ -132,12 +132,6 @@ namespace llarp
ctx->ScheduleCleanupTimer();
}
void
Context::LookupTagForPath(const service::Tag &tag, uint64_t txid,
const llarp::PathID_t &path, const Key_t &askpeer)
{
}
std::set< service::IntroSet >
Context::FindRandomIntroSetsWithTagExcluding(
const service::Tag &tag, size_t max,
@ -567,7 +561,8 @@ namespace llarp
void
Start(const TXOwner &peer)
{
parent->DHTSendTo(peer.node, new FindIntroMessage(target, peer.txid));
parent->DHTSendTo(peer.node,
new FindIntroMessage(target, peer.txid, R));
}
bool
@ -590,10 +585,10 @@ namespace llarp
found.insert(remoteTag);
}
// collect our local values if we haven't hit a limit
if(found.size() < 8)
if(found.size() < 3)
{
for(const auto &localTag :
parent->FindRandomIntroSetsWithTagExcluding(target, 2, found))
parent->FindRandomIntroSetsWithTagExcluding(target, 1, found))
{
found.insert(localTag);
}
@ -616,6 +611,53 @@ namespace llarp
TXOwner asker(whoasked, whoaskedTX);
TXOwner peer(askpeer, ++ids);
pendingTagLookups.NewTX(peer, tag, new TagLookup(asker, tag, this, R));
llarp::LogInfo("ask ", askpeer, " for ", tag, " on behalf of ", whoasked,
" R=", R);
}
struct LocalTagLookup : public TagLookup
{
PathID_t localPath;
LocalTagLookup(const PathID_t &path, uint64_t txid,
const service::Tag &target, Context *ctx)
: TagLookup(TXOwner{ctx->OurKey(), txid}, target, ctx, 3)
, localPath(path)
{
}
void
SendReply()
{
auto path =
parent->router->paths.GetByUpstream(parent->OurKey(), localPath);
if(!path)
{
llarp::LogWarn(
"did not send reply for relayed dht request, no such local path "
"for pathid=",
localPath);
return;
}
routing::DHTMessage msg;
msg.M.emplace_back(new GotIntroMessage(valuesFound, whoasked.txid));
if(!path->SendRoutingMessage(&msg, parent->router))
{
llarp::LogWarn(
"failed to send routing message when informing result of dht "
"request, pathid=",
localPath);
}
}
};
void
Context::LookupTagForPath(const service::Tag &tag, uint64_t txid,
const llarp::PathID_t &path, const Key_t &askpeer)
{
TXOwner peer(askpeer, ++ids);
pendingTagLookups.NewTX(peer, tag,
new LocalTagLookup(path, txid, tag, this));
}
bool

@ -182,13 +182,22 @@ namespace llarp
replies.emplace_back(new GotIntroMessage(reply, T));
return true;
}
else
else if(R < 5)
{
// tag lookup
if(dht.nodes->GetRandomNodeExcluding(peer, exclude))
{
dht.LookupTagRecursive(N, From, T, peer, R - 1);
}
else
{
replies.emplace_back(new GotIntroMessage({}, T));
}
}
else
{
// too big R value
replies.emplace_back(new GotIntroMessage({}, T));
}
}
}

@ -41,14 +41,14 @@ namespace llarp
auto tagLookup = dht.pendingTagLookups.GetPendingLookupFrom(owner);
if(tagLookup)
{
dht.pendingTagLookups.Inform(owner, tagLookup->target, I);
dht.pendingTagLookups.Found(owner, tagLookup->target, I);
return true;
}
auto serviceLookup =
dht.pendingIntrosetLookups.GetPendingLookupFrom(owner);
if(serviceLookup)
{
dht.pendingIntrosetLookups.Inform(owner, serviceLookup->target, I);
dht.pendingIntrosetLookups.Found(owner, serviceLookup->target, I);
return true;
}
llarp::LogError("no pending TX for GIM from ", From, " txid=", T);

@ -985,10 +985,14 @@ namespace llarp
bool
IsBogon(const in6_addr& addr)
{
#ifdef TESTNET
return false;
#else
if(!ipv6_is_siit(addr))
return false;
return IsIPv4Bogon(ipaddr_ipv4_bits(addr.s6_addr[12], addr.s6_addr[13],
addr.s6_addr[14], addr.s6_addr[15]));
#endif
}
bool

@ -186,7 +186,7 @@ namespace llarp
}
}
}
#ifdef TESTNET
// prefetch tags
for(const auto& tag : m_PrefetchTags)
{
@ -201,12 +201,12 @@ namespace llarp
{
if(HasPendingPathToService(introset.A.Addr()))
continue;
if(!EnsurePathToService(introset.A.Addr(),
[](Address addr, OutboundContext* ctx) {},
10000))
byte_t tmp[1024] = {0};
auto buf = StackBuffer< decltype(tmp) >(tmp);
if(!SendToOrQueue(introset.A.Addr(), buf, eProtocolText))
{
llarp::LogWarn("failed to ensure path to ", introset.A.Addr(),
" for tag ", tag.ToString());
llarp::LogWarn(Name(), " failed to send/queue data to ",
introset.A.Addr(), " for tag ", tag.ToString());
}
}
itr->second.Expire(now);
@ -216,10 +216,16 @@ namespace llarp
if(path)
{
auto job = new TagLookupJob(this, &itr->second);
job->SendRequestViaPath(path, Router());
if(!job->SendRequestViaPath(path, Router()))
llarp::LogError(Name(), " failed to send tag lookup");
}
else
{
llarp::LogError(Name(), " has no paths for tag lookup");
}
}
}
#endif
// tick remote sessions
{

Loading…
Cancel
Save