Ryan Tharp 6 years ago
commit db64547ab3

@ -399,6 +399,7 @@ set(TEST_SRC
test/encrypted_frame_unittest.cpp
test/hiddenservice_unittest.cpp
test/pq_unittest.cpp
test/net_unittest.cpp
test/test_dns_unit.cpp
test/test_dnsc_unit.cpp
test/test_dnsd_unit.cpp

@ -138,7 +138,7 @@ router's full identity
k: "<32 bytes public long term identity signing key>",
n: "<optional max 32 bytes router nickname>",
p: "<32 bytes public path encryption key>",
u: last_updated_seconds_since_epoch_uint64,
u: next_update_needed_milliseconds_since_epoch_uint64,
v: 0,
x: [ Exit, Infos ],
z: "<64 bytes signature using identity key>"

@ -23,9 +23,9 @@ struct dnsd_context;
struct dns_tracker
{
// uint c_responses;
uint c_requests;
uint32_t c_requests;
// request has to be a pointer
std::unordered_map< uint, std::unique_ptr< dnsc_answer_request > >
std::unordered_map< uint32_t, std::unique_ptr< dnsc_answer_request > >
client_request;
// FIXME: support multiple dns server contexts
dnsd_context *dnsd;

@ -12,7 +12,6 @@ namespace llarp
/// encrypted buffer base type
struct Encrypted
{
static const size_t MAX_SIZE = (1024 * 8);
Encrypted(Encrypted&&) = delete;
Encrypted(const Encrypted& other);
@ -24,13 +23,13 @@ namespace llarp
bool
BEncode(llarp_buffer_t* buf) const
{
return bencode_write_bytestring(buf, _data, _sz);
return bencode_write_bytestring(buf, data(), size());
}
bool
operator==(const Encrypted& other) const
{
return _sz == other._sz && memcmp(_data, other._data, _sz) == 0;
return size() == other.size() && memcmp(data(), other.data(), size()) == 0;
}
bool
@ -48,12 +47,10 @@ namespace llarp
Encrypted&
operator=(const llarp_buffer_t& buf)
{
if(buf.sz > MAX_SIZE)
return *this;
_sz = buf.sz;
if(_sz)
_data.resize(buf.sz);
if(buf.sz)
{
memcpy(_data, buf.base, _sz);
memcpy(data(), buf.base, buf.sz);
}
UpdateBuffer();
return *this;
@ -62,6 +59,7 @@ namespace llarp
void
Fill(byte_t fill)
{
size_t _sz = size();
size_t idx = 0;
while(idx < _sz)
_data[idx++] = fill;
@ -70,8 +68,9 @@ namespace llarp
void
Randomize()
{
size_t _sz = size();
if(_sz)
randombytes(_data, _sz);
randombytes(data(), _sz);
}
bool
@ -82,10 +81,8 @@ namespace llarp
return false;
if(strbuf.sz == 0)
return false;
if(strbuf.sz > MAX_SIZE)
return false;
_sz = strbuf.sz;
memcpy(_data, strbuf.base, _sz);
_data.resize(strbuf.sz);
memcpy(data(), strbuf.base, size());
UpdateBuffer();
return true;
}
@ -105,21 +102,27 @@ namespace llarp
size_t
size()
{
return _sz;
return _data.size();
}
size_t
size() const
{
return _sz;
return _data.size();
}
byte_t*
data()
{
return _data;
return _data.data();
}
const byte_t *
data() const
{
return _data.data();
}
protected:
void
UpdateBuffer()
@ -128,8 +131,7 @@ namespace llarp
m_Buffer.cur = data();
m_Buffer.sz = size();
}
byte_t _data[MAX_SIZE];
size_t _sz = 0;
std::vector<byte_t> _data;
llarp_buffer_t m_Buffer;
};
} // namespace llarp

@ -18,7 +18,7 @@ namespace llarp
}
EncryptedFrame(const EncryptedFrame& other)
: EncryptedFrame(other._data, other._sz)
: EncryptedFrame(other.data(), other.size())
{
}
@ -33,11 +33,8 @@ namespace llarp
EncryptedFrame&
operator=(const EncryptedFrame& other)
{
if(other._sz <= MAX_SIZE)
{
_sz = other._sz;
memcpy(_data, other._data, _sz);
}
_data.resize(other.size());
memcpy(data(), other.data(), size());
return *this;
}

@ -207,7 +207,7 @@ namespace llarp
Contains(const huint32_t& ip) const
{
// TODO: do this "better"
return ((addr & netmask_bits) ^ ip) == (ip & (~netmask_bits));
return (addr & netmask_bits) == (ip & netmask_bits);
}
std::string
@ -221,18 +221,26 @@ namespace llarp
}
};
/// get a netmask with the higest numset bits set
constexpr uint32_t
__netmask_ipv4_bits(uint32_t numset)
{
return (32 - numset)
? (1 << (32 - (numset + 1))) | __netmask_ipv4_bits(numset + 1)
: 0;
}
/// get an ipv4 netmask given some /N range
constexpr huint32_t
netmask_ipv4_bits(byte_t netmask)
netmask_ipv4_bits(uint32_t num)
{
return (32 - netmask) ? (huint32_t{((uint32_t)1 << (32 - (netmask + 1)))}
| netmask_ipv4_bits(netmask + 1))
: huint32_t{0};
return huint32_t{__netmask_ipv4_bits(32 - num)};
}
constexpr huint32_t
ipaddr_ipv4_bits(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
{
return huint32_t{(a << 24) | (b << 16) | (c << 8) | d};
return huint32_t{(a) | (b << 8) | (c << 16) | (d << 24)};
}
constexpr IPRange

@ -40,7 +40,7 @@ namespace llarp
bool firstKey;
char key;
dict_reader reader;
IMessage* msg;
std::unique_ptr<IMessage> msg;
};
} // namespace routing
} // namespace llarp

@ -205,7 +205,8 @@ namespace llarp
};
virtual void
UpdateIntroSet(){};
UpdateIntroSet(bool randomizePath=false){};
virtual bool
MarkCurrentIntroBad(llarp_time_t now)
{
@ -270,7 +271,7 @@ namespace llarp
/// issues a lookup to find the current intro set of the remote service
void
UpdateIntroSet();
UpdateIntroSet(bool randomizePath);
bool
BuildOneAlignedTo(const RouterID& remote);
@ -297,7 +298,8 @@ namespace llarp
OnGeneratedIntroFrame(AsyncKeyExchange* k, PathID_t p);
bool
OnIntroSetUpdate(const Address& addr, const IntroSet* i);
OnIntroSetUpdate(const Address& addr, const IntroSet* i,
const RouterID& endpoint);
uint64_t m_UpdateIntrosetTX = 0;
IntroSet currentIntroSet;
@ -315,7 +317,7 @@ namespace llarp
/// address
bool
EnsurePathToService(const Address& remote, PathEnsureHook h,
uint64_t timeoutMS);
uint64_t timeoutMS, bool lookupOnRandomPath=false);
virtual bool
HandleAuthenticatedDataFrom(const Address& remote, llarp_buffer_t data)
@ -379,7 +381,8 @@ namespace llarp
private:
bool
OnOutboundLookup(const Address&, const IntroSet* i); /* */
OnLookup(const service::Address& addr, const IntroSet* i,
const RouterID& endpoint); /* */
static bool
SetupIsolatedNetwork(void* user, bool success);
@ -434,6 +437,8 @@ namespace llarp
std::unordered_map< Address, PathEnsureHook, Address::Hash >
m_PendingServiceLookups;
std::unordered_map<RouterID, uint32_t, RouterID::Hash> m_ServiceLookupFails;
struct RouterLookupJob
{
RouterLookupJob(Endpoint* p)

@ -50,6 +50,7 @@ namespace llarp
ILookupHolder* parent;
uint64_t txid;
const std::string name;
RouterID endpoint;
protected:
IServiceLookup(ILookupHolder* parent, uint64_t tx,

@ -145,7 +145,7 @@ extern "C"
int mode;
#endif
#if defined(Windows)
OVERLAPPED ovl;
OVERLAPPED ovl[2];
#endif
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

@ -0,0 +1,8 @@
# libabyss
![abyss.jpeg](abyss.jpeg)
http client/server with multiple layers of the abysmal hellscape of the bottomless pit of standards by the w3c encapsulated in a neat standalone little library.
Try not to die.

@ -228,7 +228,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
// FIXME: only handling one atm
dns_msg_question *question = nullptr;
for(uint i = 0; i < hdr->qdCount; i++)
for(uint32_t i = 0; i < hdr->qdCount; i++)
{
question = decode_question((const char *)castBuf);
llarp::LogDebug("Read a question");
@ -241,7 +241,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
// FIXME: only handling one atm
std::vector< dns_msg_answer * > answers;
dns_msg_answer *answer = nullptr;
for(uint i = 0; i < hdr->anCount; i++)
for(uint32_t i = 0; i < hdr->anCount; i++)
{
answer = decode_answer((const char *)castBuf);
answers.push_back(answer);
@ -275,7 +275,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
// handle authority records (usually no answers with these, so we'll just
// stomp) usually NS records tho
for(uint i = 0; i < hdr->nsCount; i++)
for(uint32_t i = 0; i < hdr->nsCount; i++)
{
answer = decode_answer((const char *)castBuf);
// answers.push_back(answer);
@ -602,7 +602,7 @@ llarp_host_resolved(dnsc_answer_request *const request)
dns_tracker *tracker = (dns_tracker *)request->context->tracker;
auto val = std::find_if(
tracker->client_request.begin(), tracker->client_request.end(),
[request](std::pair< const uint, std::unique_ptr< dnsc_answer_request > >
[request](std::pair< const uint32_t, std::unique_ptr< dnsc_answer_request > >
&element) { return element.second.get() == request; });
if(val != tracker->client_request.end())
{

@ -71,7 +71,7 @@ write404_dnss_response(const struct sockaddr *from,
put16bits(write_buffer, 1); // rdLength
*write_buffer++ = 0; // write a null byte
uint out_bytes = write_buffer - bufferBegin;
uint32_t out_bytes = write_buffer - bufferBegin;
llarp::LogDebug("Sending 404, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from, buf, out_bytes);
@ -140,7 +140,7 @@ writecname_dnss_response(std::string cname, const struct sockaddr *from,
*write_buffer++ = 0;
*write_buffer++ = 1;
uint out_bytes = write_buffer - bufferBegin;
uint32_t out_bytes = write_buffer - bufferBegin;
llarp::LogDebug("Sending cname, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from, buf, out_bytes);
@ -180,7 +180,7 @@ writesend_dnss_revresponse(std::string reverse, const struct sockaddr *from,
put16bits(write_buffer, reverse.length() + 2); // rdLength
code_domain(write_buffer, reverse);
uint out_bytes = write_buffer - bufferBegin;
uint32_t out_bytes = write_buffer - bufferBegin;
llarp::LogDebug("Sending reverse: ", reverse, " ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from, buf, out_bytes);
@ -243,7 +243,7 @@ writesend_dnss_response(struct sockaddr *hostRes, const struct sockaddr *from,
*write_buffer++ = ip[2];
*write_buffer++ = ip[3];
uint out_bytes = write_buffer - bufferBegin;
uint32_t out_bytes = write_buffer - bufferBegin;
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from, buf, out_bytes);

@ -11,20 +11,17 @@ namespace llarp
}
Encrypted::Encrypted(const Encrypted& other)
: Encrypted(other._data, other._sz)
: Encrypted(other.data(), other.size())
{
}
Encrypted::Encrypted(const byte_t* buf, size_t sz) : _sz(sz)
Encrypted::Encrypted(const byte_t* buf, size_t sz) : _data(sz)
{
if(sz <= MAX_SIZE)
{
if(buf)
memcpy(data(), buf, sz);
else
llarp::Zero(data(), sz);
UpdateBuffer();
}
if(buf)
memcpy(data(), buf, sz);
else
llarp::Zero(data(), sz);
UpdateBuffer();
}
Encrypted::~Encrypted()

@ -32,9 +32,11 @@ namespace llarp
sockaddr_in6 src;
socklen_t slen = sizeof(sockaddr_in6);
sockaddr* addr = (sockaddr*)&src;
int ret = ::recvfrom(fd, buf, sz, 0, addr, &slen);
ssize_t ret = ::recvfrom(fd, buf, sz, 0, addr, &slen);
if(ret == -1)
return -1;
if(ret > sz)
return -1;
udp->recvfrom(udp, addr, buf, ret);
return 0;
}

@ -46,6 +46,8 @@ namespace llarp
llarp::LogWarn("recvfrom failed");
return -1;
}
if(ret > sz)
return -1;
// Addr is the source
udp->recvfrom(udp, addr, buf, ret);
return 0;

@ -17,25 +17,17 @@ namespace llarp
// we receive queued data in the OVERLAPPED data field,
// much like the pipefds in the UNIX kqueue and loonix
// epoll handles
WSAOVERLAPPED portfd;
size_t iosz;
WSAOVERLAPPED portfd[2];
udp_listener(SOCKET fd, llarp_udp_io* u) : ev_io(fd), udp(u)
{
memset((void*)&portfd, 0, sizeof(WSAOVERLAPPED));
memset((void*)&portfd[0], 0, sizeof(WSAOVERLAPPED)*2);
};
~udp_listener()
{
}
int
getData(void* buf, size_t sz, size_t ret)
{
iosz = ret;
return read(buf, sz);
}
virtual int
read(void* buf, size_t sz)
{
@ -47,7 +39,7 @@ namespace llarp
// WSARecvFrom
llarp::LogDebug("read ", sz, " bytes into socket");
int ret = ::WSARecvFrom(std::get< SOCKET >(fd), &wbuf, 1, nullptr, &flags,
addr, &slen, &portfd, nullptr);
addr, &slen, &portfd[0], nullptr);
// 997 is the error code for queued ops
int s_errno = ::WSAGetLastError();
if(ret && s_errno != 997)
@ -56,7 +48,7 @@ namespace llarp
return -1;
}
// get the _real_ payload size from tick()
udp->recvfrom(udp, addr, buf, iosz);
udp->recvfrom(udp, addr, buf, sz);
return 0;
}
@ -79,7 +71,7 @@ namespace llarp
// WSASendTo
llarp::LogDebug("write ", sz, " bytes into socket");
ssize_t sent = ::WSASendTo(std::get< SOCKET >(fd), &wbuf, 1, nullptr, 0,
to, slen, &portfd, nullptr);
to, slen, &portfd[1], nullptr);
int s_errno = ::WSAGetLastError();
if(sent && s_errno != 997)
{
@ -94,7 +86,7 @@ namespace llarp
{
llarp_tun_io* t;
device* tunif;
OVERLAPPED* tun_async;
OVERLAPPED* tun_async[2];
tun(llarp_tun_io* tio)
: ev_io(INVALID_HANDLE_VALUE)
, t(tio)
@ -123,7 +115,7 @@ namespace llarp
bool
do_write(void* data, size_t sz)
{
return WriteFile(std::get< HANDLE >(fd), data, sz, nullptr, tun_async);
return WriteFile(std::get< HANDLE >(fd), data, sz, nullptr, tun_async[1]);
}
int
@ -159,7 +151,8 @@ namespace llarp
}
fd = tunif->tun_fd;
tun_async = &tunif->ovl;
tun_async[0] = &tunif->ovl[0];
tun_async[1] = &tunif->ovl[1];
if(std::get< HANDLE >(fd) == INVALID_HANDLE_VALUE)
return false;
@ -222,7 +215,8 @@ struct llarp_win32_loop : public llarp_ev_loop
{
llarp::LogDebug("size: ", iolen, "\tev_id: ", ev_id,
"\tqdata: ", qdata);
ev->getData(readbuf, sizeof(readbuf), iolen);
if(iolen <= sizeof(readbuf))
ev->read(readbuf, iolen);
}
++idx;
}
@ -262,7 +256,8 @@ struct llarp_win32_loop : public llarp_ev_loop
if(ev && !ev->fd.valueless_by_exception())
{
llarp::LogInfo("size: ", iolen, "\tev_id: ", ev_id, "\tqdata: ", qdata);
ev->getData(readbuf, sizeof(readbuf), iolen);
if(iolen <= sizeof(readbuf))
ev->read(readbuf, iolen);
}
++idx;
}
@ -381,7 +376,7 @@ struct llarp_win32_loop : public llarp_ev_loop
return false;
}
::ReadFile((HANDLE)std::get< 0 >(ev->fd), &buf, 1024, nullptr,
&udp->portfd);
&udp->portfd[0]);
break;
case 1:
t = dynamic_cast< llarp::tun* >(ev);
@ -391,7 +386,7 @@ struct llarp_win32_loop : public llarp_ev_loop
delete ev;
return false;
}
::ReadFile(std::get< 1 >(ev->fd), &buf, 1024, nullptr, t->tun_async);
::ReadFile(std::get< 1 >(ev->fd), &buf, 1024, nullptr, t->tun_async[0]);
break;
default:
return false;

@ -1015,9 +1015,6 @@ namespace llarp
{
if(bogon.Contains(addr))
{
char strbuf[32] = {0};
inet_ntop(AF_INET, &addr, strbuf, sizeof(strbuf));
llarp::LogError("bogon: ", strbuf, " in ", bogon.ToString());
return true;
}
}

@ -685,7 +685,7 @@ llarp_router::Run()
{
llarp::LogInfo("Found adapter for public address");
}
if(!a.isPrivate())
if(!llarp::IsBogon(*a.addr6()))
{
llarp::LogInfo("Loading Addr: ", a, " into our RC");
_rc.addrs.push_back(addr);

@ -43,22 +43,22 @@ namespace llarp
switch(self->key)
{
case 'D':
self->msg = new DataDiscardMessage();
self->msg.reset(new DataDiscardMessage());
break;
case 'L':
self->msg = new PathLatencyMessage();
self->msg.reset(new PathLatencyMessage());
break;
case 'M':
self->msg = new DHTMessage();
self->msg.reset(new DHTMessage());
break;
case 'P':
self->msg = new PathConfirmMessage();
self->msg.reset(new PathConfirmMessage());
break;
case 'T':
self->msg = new PathTransferMessage();
self->msg.reset(new PathTransferMessage());
break;
case 'H':
self->msg = new service::ProtocolFrame();
self->msg.reset(new service::ProtocolFrame());
break;
default:
llarp::LogError("invalid routing message id: ", *strbuf.cur);
@ -87,13 +87,13 @@ namespace llarp
result = msg->HandleMessage(h, r);
if(!result)
llarp::LogWarn("Failed to handle inbound routing message ", key);
delete msg;
}
else
{
llarp::LogError("read dict failed in routing layer");
llarp::DumpBuffer< llarp_buffer_t, 128 >(buf);
}
msg.reset();
return result;
}
} // namespace routing

@ -334,7 +334,7 @@ namespace llarp
}
if(IsExpired(now))
{
llarp::LogWarn("introset expired");
llarp::LogWarn("introset expired: ", *this);
return false;
}
return true;

@ -593,7 +593,8 @@ namespace llarp
}
Address remote;
typedef std::function< bool(const Address&, const IntroSet*) >
typedef std::function< bool(const Address&, const IntroSet*,
const RouterID&) >
HandlerFunc;
HandlerFunc handle;
@ -609,9 +610,9 @@ namespace llarp
llarp::LogInfo("found ", results.size(), " for ", remote.ToString());
if(results.size() > 0)
{
return handle(remote, &*results.begin());
return handle(remote, &*results.begin(), endpoint);
}
return handle(remote, nullptr);
return handle(remote, nullptr, endpoint);
}
llarp::routing::IMessage*
@ -765,7 +766,7 @@ namespace llarp
llarp::LogInfo(Name(), " switched intros to ", remoteIntro.router,
" via ", remoteIntro.pathID);
}
UpdateIntroSet();
UpdateIntroSet(true);
}
return true;
}
@ -841,11 +842,14 @@ namespace llarp
}
bool
Endpoint::OnOutboundLookup(const Address& addr, const IntroSet* introset)
Endpoint::OnLookup(const Address& addr, const IntroSet* introset,
const RouterID& endpoint)
{
auto now = llarp_time_now_ms();
if(introset == nullptr || introset->IsExpired(now))
{
llarp::LogError(Name(), " failed to lookup ", addr.ToString(), " from ",
endpoint);
auto itr = m_PendingServiceLookups.find(addr);
if(itr != m_PendingServiceLookups.end())
{
@ -853,6 +857,7 @@ namespace llarp
m_PendingServiceLookups.erase(itr);
func(addr, nullptr);
}
m_ServiceLookupFails[endpoint] += 1;
return false;
}
PutNewOutboundContext(*introset);
@ -861,9 +866,13 @@ namespace llarp
bool
Endpoint::EnsurePathToService(const Address& remote, PathEnsureHook hook,
llarp_time_t timeoutMS)
llarp_time_t timeoutMS, bool randomPath)
{
auto path = GetEstablishedPathClosestTo(remote.ToRouter());
path::Path* path = nullptr;
if(randomPath)
path = PickRandomEstablishedPath();
else
path = GetEstablishedPathClosestTo(remote.ToRouter());
if(!path)
{
llarp::LogWarn("No outbound path for lookup yet");
@ -878,21 +887,48 @@ namespace llarp
return true;
}
}
auto itr = m_PendingServiceLookups.find(remote);
if(itr != m_PendingServiceLookups.end())
{
// duplicate
llarp::LogWarn("duplicate pending service lookup to ",
remote.ToString());
return false;
auto itr = m_PendingServiceLookups.find(remote);
if(itr != m_PendingServiceLookups.end())
{
// duplicate
llarp::LogWarn("duplicate pending service lookup to ",
remote.ToString());
return false;
}
}
m_PendingServiceLookups.insert(std::make_pair(remote, hook));
{
RouterID endpoint = path->Endpoint();
auto itr = m_ServiceLookupFails.find(endpoint);
if(itr != m_ServiceLookupFails.end())
{
if(itr->second % 2 == 0)
{
// get far router
path = GetEstablishedPathClosestTo(~endpoint);
}
else
{
path = PickRandomEstablishedPath();
}
}
}
if(!path)
{
path = PickRandomEstablishedPath();
if(!path)
{
llarp::LogError(Name(), "no working paths for lookup");
hook(remote, nullptr);
return false;
}
}
HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup(
this,
std::bind(&Endpoint::OnOutboundLookup, this, std::placeholders::_1,
std::placeholders::_2),
std::bind(&Endpoint::OnLookup, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3),
remote, GenTXID());
if(job->SendRequestViaPath(path, Router()))
@ -954,7 +990,8 @@ namespace llarp
bool
Endpoint::OutboundContext::OnIntroSetUpdate(const Address& addr,
const IntroSet* i)
const IntroSet* i,
const RouterID& endpoint)
{
if(markedBad)
return true;
@ -968,7 +1005,7 @@ namespace llarp
auto now = llarp_time_now_ms();
if(i->IsExpired(now))
{
llarp::LogError("got expired introset from lookup");
llarp::LogError("got expired introset from lookup from ", endpoint);
return true;
}
currentIntroSet = *i;
@ -1075,7 +1112,8 @@ namespace llarp
return false;
}
// no converstation
EnsurePathToService(remote, [](Address, OutboundContext*) {}, 5000);
EnsurePathToService(remote, [](Address, OutboundContext*) {}, 5000,
false);
return false;
}
@ -1223,6 +1261,14 @@ namespace llarp
Endpoint::SendContext::AsyncEncryptAndSendTo(llarp_buffer_t data,
ProtocolType protocol)
{
auto now = llarp_time_now_ms();
if(remoteIntro.ExpiresSoon(now))
{
if(!MarkCurrentIntroBad(now))
{
llarp::LogWarn("no good path yet, your message may drop");
}
}
if(sequenceNo)
{
EncryptAndSendTo(data, protocol);
@ -1363,21 +1409,13 @@ namespace llarp
path = m_Endpoint->GetPathByRouter(remoteIntro.router);
if(path)
{
auto now = llarp_time_now_ms();
if(remoteIntro.ExpiresSoon(now))
{
if(!MarkCurrentIntroBad(now))
{
llarp::LogWarn("no good path yet, your message may drop");
}
}
++sequenceNo;
routing::PathTransferMessage transfer(msg, remoteIntro.pathID);
if(path->SendRoutingMessage(&transfer, m_Endpoint->Router()))
{
llarp::LogDebug("sent data to ", remoteIntro.pathID, " on ",
remoteIntro.router);
lastGoodSend = now;
lastGoodSend = llarp_time_now_ms();
}
else
llarp::LogError("Failed to send frame on path");
@ -1395,18 +1433,25 @@ namespace llarp
}
void
Endpoint::OutboundContext::UpdateIntroSet()
Endpoint::OutboundContext::UpdateIntroSet(bool randomizePath)
{
if(updatingIntroSet || markedBad)
return;
auto addr = currentIntroSet.A.Addr();
auto path = m_Endpoint->GetEstablishedPathClosestTo(addr.data());
path::Path* path = nullptr;
if(randomizePath)
path = m_Endpoint->PickRandomEstablishedPath();
else
path = m_Endpoint->GetEstablishedPathClosestTo(addr.data());
if(path)
{
HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup(
m_Endpoint,
std::bind(&Endpoint::OutboundContext::OnIntroSetUpdate, this,
std::placeholders::_1, std::placeholders::_2),
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
addr, m_Endpoint->GenTXID());
updatingIntroSet = job->SendRequestViaPath(path, m_Endpoint->Router());

@ -21,8 +21,9 @@ namespace llarp
if(!msg)
return false;
auto result = path->SendRoutingMessage(msg, r);
endpoint = path->Endpoint();
delete msg;
return result;
}
} // namespace service
} // namespace llarp
} // namespace llarp

@ -18,12 +18,6 @@
#include <llarp/linux/netns.hpp>
#endif
#ifdef _MSC_VER
#include <windows.h>
extern "C" void
SetThreadName(DWORD dwThreadID, LPCSTR szThreadName);
#endif
namespace llarp
{
namespace thread
@ -43,8 +37,6 @@ namespace llarp
pthread_set_name_np(pthread_self(), name);
#elif(__linux__) || (__MINGW32__)
pthread_setname_np(pthread_self(), name);
#elif defined(_MSC_VER)
SetThreadName(GetCurrentThreadId(), name);
#endif
}
for(;;)

@ -0,0 +1,51 @@
#include <gtest/gtest.h>
#include <llarp/net.hpp>
struct NetTest : public ::testing::Test
{
};
TEST_F(NetTest, TestRangeContains)
{
ASSERT_TRUE(llarp::iprange_ipv4(10, 0, 0, 0, 8)
.Contains(llarp::ipaddr_ipv4_bits(10, 40, 11, 6)));
}
TEST_F(NetTest, TestIPv4Netmask)
{
ASSERT_TRUE(llarp::xhtonl(llarp::netmask_ipv4_bits(8))
== llarp::nuint32_t{0xFF000000});
};
TEST_F(NetTest, TestBogon_10_8)
{
ASSERT_TRUE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(10, 40, 11, 6)));
};
TEST_F(NetTest, TestBogon_192_168_16)
{
ASSERT_TRUE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(192, 168, 1, 111)));
};
TEST_F(NetTest, TestBogon_DoD_8)
{
ASSERT_TRUE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(21, 3, 37, 70)));
};
TEST_F(NetTest, TestBogon_127_8)
{
ASSERT_TRUE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(127, 0, 0, 1)));
};
TEST_F(NetTest, TestBogon_0_8)
{
ASSERT_TRUE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(0, 0, 0, 0)));
};
TEST_F(NetTest, TestBogon_NonBogon)
{
ASSERT_FALSE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(1, 1, 1, 1)));
ASSERT_FALSE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(8, 8, 6, 6)));
ASSERT_FALSE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(141, 55, 12, 99)));
ASSERT_FALSE(llarp::IsIPv4Bogon(llarp::ipaddr_ipv4_bits(79, 12, 3, 4)));
}

@ -394,7 +394,7 @@ tuntap_read(struct device *dev, void *buf, size_t size)
{
DWORD len;
if(ReadFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl) == 0)
if(ReadFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl[0]) == 0)
{
int errcode = GetLastError();
@ -415,7 +415,7 @@ tuntap_write(struct device *dev, void *buf, size_t size)
{
DWORD len;
if(WriteFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl) == 0)
if(WriteFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl[1]) == 0)
{
int errcode = GetLastError();

@ -69,7 +69,7 @@ extern "C"
dev->ctrl_sock = -1;
dev->flags = 0;
#if defined(Windows)
memset(&dev->ovl, 0, sizeof(OVERLAPPED));
memset(&dev->ovl[0], 0, sizeof(OVERLAPPED)*2);
#endif
__tuntap_log = &tuntap_log_default;

Loading…
Cancel
Save