mirror of https://github.com/oxen-io/lokinet
fixes for testnet
This commit is contained in:
parent
a73418abe3
commit
38a92cb1a8
2
Makefile
2
Makefile
|
@ -105,6 +105,7 @@ $(TARGETS): release-compile
|
|||
release: $(SIGS)
|
||||
|
||||
shadow-configure: clean
|
||||
mkdir -p $(BUILD_ROOT)
|
||||
$(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Debug -DSHADOW=ON -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)
|
||||
|
||||
shadow-build: shadow-configure
|
||||
|
@ -124,6 +125,7 @@ testnet-clean: clean
|
|||
rm -rf $(TESTNET_ROOT)
|
||||
|
||||
testnet-configure: testnet-clean
|
||||
mkdir -p $(BUILD_ROOT)
|
||||
$(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX) -DTESTNET=1
|
||||
|
||||
testnet-build: testnet-configure
|
||||
|
|
|
@ -2,16 +2,18 @@ DHT messages
|
|||
|
||||
these messages can be either wrapped in a LIDM message or sent anonymously over a path
|
||||
|
||||
The distance function is distance = A ^ B
|
||||
|
||||
This document is currently out of date (probably)
|
||||
|
||||
|
||||
find introduction message (FIM)
|
||||
|
||||
variant 1: recursively find an IS by SA
|
||||
variant 1: find an IS by SA
|
||||
|
||||
{
|
||||
A: "F",
|
||||
I: 0 or 1 if iterative request,
|
||||
R: 0 or 1 if recurisve request,
|
||||
S: "<32 bytes SA>",
|
||||
T: transaction_id_uint64,
|
||||
V: 0
|
||||
|
@ -21,8 +23,8 @@ variant 2: recursively find many IS in a tag
|
|||
|
||||
{
|
||||
A: "F",
|
||||
E: "<N*32 bytes optional exclude SA list>",
|
||||
I: 0 or 1 if iterative request,
|
||||
E: [list, of, excluded, SA],
|
||||
R: 0 or 1 if recurisve request,
|
||||
N: "<16 bytes topic tag>",
|
||||
T: transaction_id_uint64,
|
||||
V: 0
|
||||
|
@ -38,13 +40,13 @@ sent in reply to FIM and PIM
|
|||
{
|
||||
A: "G",
|
||||
I: [IS, IS, IS, ...],
|
||||
K: "<32 bytes public key of router who is closer, provided ONLY if FIM.R is 0>",
|
||||
T: transaction_id_uint64,
|
||||
V: 0,
|
||||
}
|
||||
|
||||
|
||||
The I value MUST NOT contain more than 8 IS.
|
||||
The I value is either 1 or 0 IS long for PIM and FIM variant 1.
|
||||
The I value MUST NOT contain more than 4 IS.
|
||||
The I value contain either 1 or 0 IS for PIM and FIM variant 1.
|
||||
|
||||
|
||||
publish introduction message (PIM)
|
||||
|
@ -101,6 +103,7 @@ sent in reply to FRCM only
|
|||
|
||||
{
|
||||
A: "S",
|
||||
K: "<32 bytes public identity key of router closer, provided ONLY if FRCM.I is 1>",
|
||||
R: [RC],
|
||||
T: transaction_id_uint64,
|
||||
V: 0
|
||||
|
|
|
@ -91,16 +91,24 @@ namespace llarp
|
|||
|
||||
/// return true if we want to persist this tx
|
||||
bool
|
||||
AskNextPeer(const Key_t& prevPeer)
|
||||
AskNextPeer(const Key_t& prevPeer, const std::unique_ptr< Key_t >& next)
|
||||
{
|
||||
peersAsked.insert(prevPeer);
|
||||
Key_t peer;
|
||||
if(!GetNextPeer(peer, peersAsked))
|
||||
if(next)
|
||||
{
|
||||
// no more peers
|
||||
SendReply();
|
||||
return false;
|
||||
peer = *next.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!GetNextPeer(peer, peersAsked))
|
||||
{
|
||||
// no more peers
|
||||
SendReply();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
DoNextRequest(peer);
|
||||
return true;
|
||||
}
|
||||
|
@ -283,12 +291,12 @@ namespace llarp
|
|||
}
|
||||
|
||||
void
|
||||
NewTX(const TXOwner& owner, const K& k, TX< K, V >* t,
|
||||
bool forceStart = true)
|
||||
NewTX(const TXOwner& askpeer, const TXOwner& whoasked, const K& k,
|
||||
TX< K, V >* t, bool forceSend = false)
|
||||
{
|
||||
tx.emplace(owner, std::unique_ptr< TX< K, V > >(t));
|
||||
auto n = waiting.count(k);
|
||||
waiting.insert(std::make_pair(k, owner));
|
||||
tx.emplace(askpeer, std::unique_ptr< TX< K, V > >(t));
|
||||
bool send = waiting.count(k) == 0;
|
||||
waiting.insert(std::make_pair(k, whoasked));
|
||||
|
||||
auto itr = timeouts.find(k);
|
||||
if(itr == timeouts.end())
|
||||
|
@ -296,22 +304,24 @@ namespace llarp
|
|||
timeouts.insert(
|
||||
std::make_pair(k, llarp_time_now_ms() + requestTimeoutMS));
|
||||
}
|
||||
if(forceStart || n == 0)
|
||||
t->Start(owner);
|
||||
if(send || forceSend)
|
||||
t->Start(askpeer);
|
||||
}
|
||||
|
||||
/// mark tx as not fond
|
||||
void
|
||||
NotFound(const TXOwner& from)
|
||||
NotFound(const TXOwner& from, const std::unique_ptr< Key_t >& next)
|
||||
{
|
||||
bool sendReply = true;
|
||||
auto txitr = tx.find(from);
|
||||
if(txitr == tx.end())
|
||||
return;
|
||||
|
||||
// ask for next peer
|
||||
if(txitr->second->AskNextPeer(from.node))
|
||||
sendReply = false;
|
||||
if(next)
|
||||
{
|
||||
// ask for next peer
|
||||
if(txitr->second->AskNextPeer(from.node, next))
|
||||
sendReply = false;
|
||||
}
|
||||
llarp::LogWarn("Target key ", txitr->second->target);
|
||||
Inform(from, txitr->second->target, {}, sendReply, sendReply);
|
||||
}
|
||||
|
|
|
@ -22,17 +22,25 @@ namespace llarp
|
|||
}
|
||||
|
||||
FindIntroMessage(const llarp::service::Tag& tag, uint64_t txid,
|
||||
uint64_t r = 3)
|
||||
: IMessage({}), R(r), N(tag), T(txid)
|
||||
bool iterate = true)
|
||||
: IMessage({}), N(tag), T(txid)
|
||||
{
|
||||
S.Zero();
|
||||
if(iterate)
|
||||
R = 0;
|
||||
else
|
||||
R = 1;
|
||||
}
|
||||
|
||||
FindIntroMessage(uint64_t txid, const llarp::service::Address& addr,
|
||||
uint64_t r)
|
||||
: IMessage({}), R(r), S(addr), T(txid)
|
||||
bool iterate = true)
|
||||
: IMessage({}), S(addr), T(txid)
|
||||
{
|
||||
N.Zero();
|
||||
if(iterate)
|
||||
R = 0;
|
||||
else
|
||||
R = 1;
|
||||
}
|
||||
|
||||
~FindIntroMessage();
|
||||
|
|
|
@ -8,16 +8,27 @@ namespace llarp
|
|||
{
|
||||
namespace dht
|
||||
{
|
||||
/// acknowledgement to PublishIntroMessage or reply to FinIntroMessage
|
||||
/// acknowledgement to PublishIntroMessage or reply to FindIntroMessage
|
||||
struct GotIntroMessage : public IMessage
|
||||
{
|
||||
/// the found introsets
|
||||
std::vector< llarp::service::IntroSet > I;
|
||||
/// txid
|
||||
uint64_t T = 0;
|
||||
/// the key of a router closer in keyspace if iterative lookup
|
||||
std::unique_ptr< Key_t > K;
|
||||
|
||||
GotIntroMessage(const Key_t& from) : IMessage(from)
|
||||
{
|
||||
}
|
||||
|
||||
/// for iterative reply
|
||||
GotIntroMessage(const Key_t& from, const Key_t& closer, uint64_t txid)
|
||||
: IMessage(from), T(txid), K(new Key_t(closer))
|
||||
{
|
||||
}
|
||||
|
||||
/// for recursive reply
|
||||
GotIntroMessage(const std::vector< llarp::service::IntroSet >& results,
|
||||
uint64_t txid);
|
||||
|
||||
|
|
|
@ -20,6 +20,12 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
GotRouterMessage(const Key_t& from, const Key_t& closer, uint64_t id,
|
||||
bool tunneled)
|
||||
: IMessage(from), K(new Key_t(closer)), txid(id), relayed(tunneled)
|
||||
{
|
||||
}
|
||||
|
||||
GotRouterMessage(uint64_t id, const std::vector< RouterID >& near,
|
||||
bool tunneled)
|
||||
: IMessage({}), N(near), txid(id), relayed(tunneled)
|
||||
|
@ -41,6 +47,7 @@ namespace llarp
|
|||
|
||||
std::vector< RouterContact > R;
|
||||
std::vector< RouterID > N;
|
||||
std::unique_ptr< Key_t > K;
|
||||
uint64_t txid = 0;
|
||||
uint64_t version = 0;
|
||||
bool relayed = false;
|
||||
|
|
|
@ -88,7 +88,8 @@ namespace llarp
|
|||
Context::ExploreNetworkVia(const Key_t &askpeer)
|
||||
{
|
||||
TXOwner peer(askpeer, ++ids);
|
||||
pendingExploreLookups.NewTX(peer, askpeer,
|
||||
TXOwner whoasked(OurKey(), 0);
|
||||
pendingExploreLookups.NewTX(peer, whoasked, askpeer,
|
||||
new ExploreNetworkJob(askpeer, this));
|
||||
}
|
||||
|
||||
|
@ -219,11 +220,11 @@ namespace llarp
|
|||
new GotRouterMessage(requester, txid, {}, false));
|
||||
}
|
||||
}
|
||||
else // iterative lookup and we don't have it tell them we don't have
|
||||
// the target router
|
||||
else
|
||||
{
|
||||
// iterative lookup and we don't have it tell them who is closer
|
||||
replies.emplace_back(
|
||||
new GotRouterMessage(requester, txid, {}, false));
|
||||
new GotRouterMessage(requester, next, txid, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -439,7 +440,7 @@ namespace llarp
|
|||
TXOwner asker(OurKey(), txid);
|
||||
TXOwner peer(askpeer, ++ids);
|
||||
pendingIntrosetLookups.NewTX(
|
||||
peer, addr,
|
||||
peer, asker, addr,
|
||||
new LocalServiceAddressLookup(path, txid, addr, this, askpeer));
|
||||
}
|
||||
|
||||
|
@ -509,8 +510,8 @@ namespace llarp
|
|||
TXOwner peer(tellpeer, ++ids);
|
||||
service::Address addr = introset.A.Addr();
|
||||
pendingIntrosetLookups.NewTX(
|
||||
asker, addr, new PublishServiceJob(asker, introset, this, S, exclude),
|
||||
true);
|
||||
peer, asker, addr,
|
||||
new PublishServiceJob(asker, introset, this, S, exclude));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -522,7 +523,8 @@ namespace llarp
|
|||
TXOwner asker(whoasked, txid);
|
||||
TXOwner peer(askpeer, ++ids);
|
||||
pendingIntrosetLookups.NewTX(
|
||||
peer, addr, new ServiceAddressLookup(asker, addr, this, R, handler));
|
||||
peer, asker, addr,
|
||||
new ServiceAddressLookup(asker, addr, this, R, handler));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -534,7 +536,8 @@ namespace llarp
|
|||
TXOwner asker(whoasked, txid);
|
||||
TXOwner peer(askpeer, ++ids);
|
||||
pendingIntrosetLookups.NewTX(
|
||||
peer, addr, new ServiceAddressLookup(asker, addr, this, 0, handler));
|
||||
peer, asker, addr,
|
||||
new ServiceAddressLookup(asker, addr, this, 0, handler));
|
||||
}
|
||||
|
||||
struct TagLookup : public TX< service::Tag, service::IntroSet >
|
||||
|
@ -615,7 +618,8 @@ namespace llarp
|
|||
{
|
||||
TXOwner asker(whoasked, whoaskedTX);
|
||||
TXOwner peer(askpeer, ++ids);
|
||||
pendingTagLookups.NewTX(peer, tag, new TagLookup(asker, tag, this, R));
|
||||
pendingTagLookups.NewTX(peer, asker, tag,
|
||||
new TagLookup(asker, tag, this, R));
|
||||
llarp::LogInfo("ask ", askpeer, " for ", tag, " on behalf of ", whoasked,
|
||||
" R=", R);
|
||||
}
|
||||
|
@ -661,8 +665,9 @@ namespace llarp
|
|||
const llarp::PathID_t &path, const Key_t &askpeer)
|
||||
{
|
||||
TXOwner peer(askpeer, ++ids);
|
||||
pendingTagLookups.NewTX(peer, tag,
|
||||
new LocalTagLookup(path, txid, tag, this));
|
||||
TXOwner whoasked(OurKey(), 0);
|
||||
pendingTagLookups.NewTX(peer, whoasked, tag,
|
||||
new LocalTagLookup(path, txid, tag, this), true);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -802,8 +807,10 @@ namespace llarp
|
|||
|
||||
{
|
||||
TXOwner peer(askpeer, ++ids);
|
||||
TXOwner whoasked(OurKey(), txid);
|
||||
pendingRouterLookups.NewTX(
|
||||
peer, target, new LocalRouterLookup(path, txid, target, this));
|
||||
peer, whoasked, target,
|
||||
new LocalRouterLookup(path, txid, target, this));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -817,7 +824,7 @@ namespace llarp
|
|||
if(target != askpeer)
|
||||
{
|
||||
pendingRouterLookups.NewTX(
|
||||
peer, target,
|
||||
peer, asker, target,
|
||||
new RecursiveRouterLookup(asker, target, this, handler));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace llarp
|
|||
return false;
|
||||
if(N.Empty())
|
||||
{
|
||||
// r5n counter
|
||||
// recursion
|
||||
if(!BEncodeWriteDictInt("R", R, buf))
|
||||
return false;
|
||||
// service address
|
||||
|
@ -70,7 +70,7 @@ namespace llarp
|
|||
{
|
||||
if(!BEncodeWriteDictEntry("N", N, buf))
|
||||
return false;
|
||||
// r5n counter
|
||||
// recursion
|
||||
if(!BEncodeWriteDictInt("R", R, buf))
|
||||
return false;
|
||||
}
|
||||
|
@ -116,8 +116,16 @@ namespace llarp
|
|||
{
|
||||
if(R == 0)
|
||||
{
|
||||
// we don't have it, reply with a direct reply
|
||||
replies.emplace_back(new GotIntroMessage({}, T));
|
||||
// we don't have it
|
||||
Key_t target = S.data();
|
||||
Key_t closer;
|
||||
// find closer peer
|
||||
if(!dht.nodes->FindClosest(target, closer))
|
||||
return false;
|
||||
if(relayed)
|
||||
dht.LookupIntroSetForPath(S, T, pathID, closer);
|
||||
else
|
||||
replies.emplace_back(new GotIntroMessage(From, closer, T));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -49,7 +49,14 @@ namespace llarp
|
|||
dht.pendingIntrosetLookups.GetPendingLookupFrom(owner);
|
||||
if(serviceLookup)
|
||||
{
|
||||
dht.pendingIntrosetLookups.Found(owner, serviceLookup->target, I);
|
||||
if(I.size())
|
||||
{
|
||||
dht.pendingIntrosetLookups.Found(owner, serviceLookup->target, I);
|
||||
}
|
||||
else
|
||||
{
|
||||
dht.pendingIntrosetLookups.NotFound(owner, K);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
llarp::LogError("no pending TX for GIM from ", From, " txid=", T);
|
||||
|
@ -79,6 +86,13 @@ namespace llarp
|
|||
{
|
||||
return BEncodeReadList(I, buf);
|
||||
}
|
||||
if(llarp_buffer_eq(key, "K"))
|
||||
{
|
||||
if(K) // duplicate key?
|
||||
return false;
|
||||
K.reset(new dht::Key_t());
|
||||
return K->BDecode(buf);
|
||||
}
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, key, buf))
|
||||
return false;
|
||||
|
@ -96,6 +110,11 @@ namespace llarp
|
|||
return false;
|
||||
if(!BEncodeWriteDictList("I", I, buf))
|
||||
return false;
|
||||
if(K)
|
||||
{
|
||||
if(!BEncodeWriteDictEntry("K", *K.get(), buf))
|
||||
return false;
|
||||
}
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
|
|
|
@ -21,6 +21,12 @@ namespace llarp
|
|||
if(!BEncodeWriteDictMsgType(buf, "A", "S"))
|
||||
return false;
|
||||
|
||||
if(K)
|
||||
{
|
||||
if(!BEncodeWriteDictEntry("K", *K.get(), buf))
|
||||
return false;
|
||||
}
|
||||
|
||||
// near
|
||||
if(N.size())
|
||||
{
|
||||
|
@ -45,6 +51,13 @@ namespace llarp
|
|||
bool
|
||||
GotRouterMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *val)
|
||||
{
|
||||
if(llarp_buffer_eq(key, "K"))
|
||||
{
|
||||
if(K) // duplicate key?
|
||||
return false;
|
||||
K.reset(new dht::Key_t());
|
||||
return K->BDecode(val);
|
||||
}
|
||||
if(llarp_buffer_eq(key, "N"))
|
||||
{
|
||||
return BEncodeReadList(N, val);
|
||||
|
@ -83,7 +96,7 @@ namespace llarp
|
|||
if(dht.pendingExploreLookups.HasPendingLookupFrom(owner))
|
||||
{
|
||||
if(N.size() == 0)
|
||||
dht.pendingExploreLookups.NotFound(owner);
|
||||
dht.pendingExploreLookups.NotFound(owner, K);
|
||||
else
|
||||
{
|
||||
dht.pendingExploreLookups.Found(owner, From, N);
|
||||
|
@ -103,7 +116,7 @@ namespace llarp
|
|||
if(R.size() == 1)
|
||||
dht.pendingRouterLookups.Found(owner, R[0].pubkey, {R[0]});
|
||||
else
|
||||
dht.pendingRouterLookups.NotFound(owner);
|
||||
dht.pendingRouterLookups.NotFound(owner, K);
|
||||
return true;
|
||||
}
|
||||
} // namespace dht
|
||||
|
|
|
@ -977,6 +977,7 @@ namespace llarp
|
|||
IsBogon(const in6_addr& addr)
|
||||
{
|
||||
#ifdef TESTNET
|
||||
(void)addr;
|
||||
return false;
|
||||
#else
|
||||
if(!ipv6_is_siit(addr))
|
||||
|
|
|
@ -143,7 +143,8 @@ namespace llarp
|
|||
llarp::LogError("null router");
|
||||
return;
|
||||
}
|
||||
if(!router->SendToOrQueue(remote, &ctx->LRCM))
|
||||
const ILinkMessage* msg = &ctx->LRCM;
|
||||
if(!router->SendToOrQueue(remote, msg))
|
||||
{
|
||||
llarp::LogError("failed to send LRCM");
|
||||
return;
|
||||
|
|
|
@ -196,9 +196,9 @@ namespace llarp
|
|||
auto itr = m_PrefetchedTags.find(tag);
|
||||
if(itr == m_PrefetchedTags.end())
|
||||
{
|
||||
itr =
|
||||
m_PrefetchedTags.insert(std::make_pair(tag, CachedTagResult(tag)))
|
||||
.first;
|
||||
itr = m_PrefetchedTags
|
||||
.insert(std::make_pair(tag, CachedTagResult(tag, this)))
|
||||
.first;
|
||||
}
|
||||
for(const auto& introset : itr->second.result)
|
||||
{
|
||||
|
@ -630,7 +630,7 @@ namespace llarp
|
|||
BuildRequestMessage()
|
||||
{
|
||||
llarp::routing::DHTMessage* msg = new llarp::routing::DHTMessage();
|
||||
msg->M.emplace_back(new llarp::dht::FindIntroMessage(txid, remote, 5));
|
||||
msg->M.emplace_back(new llarp::dht::FindIntroMessage(txid, remote, 0));
|
||||
return msg;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue