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) set(WITH_STATIC ON)
endif() endif()
if(TESTNET)
add_definitions(-DTESTNET=1)
endif()
add_cflags("-Wall") add_cflags("-Wall")
add_cxxflags("-Wall") add_cxxflags("-Wall")

@ -91,7 +91,7 @@ testnet-clean: clean
rm -rf $(TESTNET_ROOT) rm -rf $(TESTNET_ROOT)
testnet-configure: testnet-clean 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 testnet-build: testnet-configure
ninja ninja
@ -105,7 +105,7 @@ shared: shared-configure
testnet: testnet:
cp $(EXE) $(TESTNET_EXE) cp $(EXE) $(TESTNET_EXE)
mkdir -p $(TESTNET_ROOT) 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) LLARP_DEBUG=$(TESTNET_DEBUG) supervisord -n -d $(TESTNET_ROOT) -l $(TESTNET_LOG) -c $(TESTNET_CONF)
test: debug test: debug

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

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

@ -132,12 +132,6 @@ namespace llarp
ctx->ScheduleCleanupTimer(); 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 > std::set< service::IntroSet >
Context::FindRandomIntroSetsWithTagExcluding( Context::FindRandomIntroSetsWithTagExcluding(
const service::Tag &tag, size_t max, const service::Tag &tag, size_t max,
@ -567,7 +561,8 @@ namespace llarp
void void
Start(const TXOwner &peer) Start(const TXOwner &peer)
{ {
parent->DHTSendTo(peer.node, new FindIntroMessage(target, peer.txid)); parent->DHTSendTo(peer.node,
new FindIntroMessage(target, peer.txid, R));
} }
bool bool
@ -590,10 +585,10 @@ namespace llarp
found.insert(remoteTag); found.insert(remoteTag);
} }
// collect our local values if we haven't hit a limit // collect our local values if we haven't hit a limit
if(found.size() < 8) if(found.size() < 3)
{ {
for(const auto &localTag : for(const auto &localTag :
parent->FindRandomIntroSetsWithTagExcluding(target, 2, found)) parent->FindRandomIntroSetsWithTagExcluding(target, 1, found))
{ {
found.insert(localTag); found.insert(localTag);
} }
@ -616,6 +611,53 @@ namespace llarp
TXOwner asker(whoasked, whoaskedTX); TXOwner asker(whoasked, whoaskedTX);
TXOwner peer(askpeer, ++ids); TXOwner peer(askpeer, ++ids);
pendingTagLookups.NewTX(peer, tag, new TagLookup(asker, tag, this, R)); 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 bool

@ -182,13 +182,22 @@ namespace llarp
replies.emplace_back(new GotIntroMessage(reply, T)); replies.emplace_back(new GotIntroMessage(reply, T));
return true; return true;
} }
else else if(R < 5)
{ {
// tag lookup // tag lookup
if(dht.nodes->GetRandomNodeExcluding(peer, exclude)) if(dht.nodes->GetRandomNodeExcluding(peer, exclude))
{ {
dht.LookupTagRecursive(N, From, T, peer, R - 1); 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); auto tagLookup = dht.pendingTagLookups.GetPendingLookupFrom(owner);
if(tagLookup) if(tagLookup)
{ {
dht.pendingTagLookups.Inform(owner, tagLookup->target, I); dht.pendingTagLookups.Found(owner, tagLookup->target, I);
return true; return true;
} }
auto serviceLookup = auto serviceLookup =
dht.pendingIntrosetLookups.GetPendingLookupFrom(owner); dht.pendingIntrosetLookups.GetPendingLookupFrom(owner);
if(serviceLookup) if(serviceLookup)
{ {
dht.pendingIntrosetLookups.Inform(owner, serviceLookup->target, I); dht.pendingIntrosetLookups.Found(owner, serviceLookup->target, I);
return true; return true;
} }
llarp::LogError("no pending TX for GIM from ", From, " txid=", T); llarp::LogError("no pending TX for GIM from ", From, " txid=", T);

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

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

Loading…
Cancel
Save