Merge branch 'dev'

pull/34/head
Jeff 6 years ago
commit 1cb2bb6136

@ -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>"

@ -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;
}

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

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.

@ -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()

@ -47,9 +47,7 @@ namespace llarp
llarp::LogWarn("recv socket error ", s_errno);
return -1;
}
/*if (sz > EV_READ_BUF_SZ)
return -1;*/
// get the _real_ payload size from tick()
udp->recvfrom(udp, addr, buf, sz);
return 0;
}
@ -217,7 +215,8 @@ struct llarp_win32_loop : public llarp_ev_loop
{
llarp::LogDebug("size: ", iolen, "\tev_id: ", ev_id,
"\tqdata: ", qdata);
ev->read(readbuf, iolen);
if(iolen <= sizeof(readbuf))
ev->read(readbuf, iolen);
}
++idx;
}
@ -257,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->read(readbuf, sizeof(readbuf));
if(iolen <= sizeof(readbuf))
ev->read(readbuf, iolen);
}
++idx;
}

@ -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;

@ -903,7 +903,7 @@ namespace llarp
auto itr = m_ServiceLookupFails.find(endpoint);
if(itr != m_ServiceLookupFails.end())
{
if(itr->second % 2)
if(itr->second % 2 == 0)
{
// get far router
path = GetEstablishedPathClosestTo(~endpoint);
@ -916,8 +916,13 @@ namespace llarp
}
if(!path)
{
llarp::LogError("no backup path");
return false;
path = PickRandomEstablishedPath();
if(!path)
{
llarp::LogError(Name(), "no working paths for lookup");
hook(remote, nullptr);
return false;
}
}
HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup(

Loading…
Cancel
Save