pull/6/head^2
Jeff Becker 6 years ago
parent cf7285f159
commit 0242e293c9

@ -234,8 +234,10 @@ set(LIB_SRC
llarp/routing/path_confirm.cpp
llarp/routing/path_latency.cpp
llarp/routing/path_transfer.cpp
llarp/service/address.cpp
llarp/service/context.cpp
llarp/service/endpoint.cpp
llarp/service/info.cpp
${LIBTUNTAP_SRC}
)

@ -72,7 +72,10 @@ testnet-configure: clean
testnet-build: testnet-configure
ninja
testnet: testnet-build
$(TESTNET_ROOT): testnet-build
testnet: $(TESTNET_ROOT)
mkdir -p $(TESTNET_ROOT)
python3 contrib/testnet/genconf.py --bin=$(REPO)/llarpd --svc=$(TESTNET_SERVERS) --clients=$(TESTNET_CLIENTS) --dir=$(TESTNET_ROOT) --out $(TESTNET_CONF)
LLARP_DEBUG=$(TESTNET_DEBUG) supervisord -n -d $(TESTNET_ROOT) -l $(TESTNET_LOG) -c $(TESTNET_CONF)

@ -1,6 +1,6 @@
[router]
worker-threads=8
net-threads=2
net-threads=1
contact-file=router.signed
ident-privkey=server-ident.key
#public-address=0.0.0.0

@ -22,20 +22,20 @@ namespace llarp
AlignedBuffer(const AlignedBuffer& other)
{
for(size_t idx = 0; idx < (sz / 8); ++idx)
l[idx] = other.l[idx];
l[idx] = other.l[idx];
}
AlignedBuffer(const byte_t* data)
{
for(size_t idx = 0; idx < sz; ++idx)
b[idx] = data[idx];
b[idx] = data[idx];
}
AlignedBuffer&
operator=(const byte_t* data)
{
for(size_t idx = 0; idx < sz; ++idx)
b[idx] = data[idx];
b[idx] = data[idx];
return *this;
}
@ -80,7 +80,7 @@ namespace llarp
Fill(byte_t f)
{
for(size_t idx = 0; idx < sz; ++idx)
b[idx] = f;
b[idx] = f;
}
bool
@ -95,7 +95,7 @@ namespace llarp
Zero()
{
for(size_t idx = 0; idx * 8 < sz; ++idx)
l[idx] = 0;
l[idx] = 0;
}
void

@ -21,7 +21,7 @@ namespace llarp
{
Key_t dist;
for(size_t idx = 0; idx < 4; ++idx)
dist.l[idx] = l[idx] ^ other.l[idx];
dist.l[idx] = l[idx] ^ other.l[idx];
return dist;
}

@ -46,9 +46,10 @@ struct frame_state
std::unordered_map< uint64_t, transit_message * > tx;
typedef std::queue< sendbuf_t * > sendqueue_t;
typedef llarp::util::CoDelQueue<
InboundMessage *, InboundMessage::GetTime, InboundMessage::PutTime,
llarp::util::DummyMutex, llarp::util::DummyLock >
typedef llarp::util::CoDelQueue< InboundMessage *, InboundMessage::GetTime,
InboundMessage::PutTime,
llarp::util::DummyMutex,
llarp::util::DummyLock >
recvqueue_t;
llarp_link_session *parent = nullptr;

@ -353,8 +353,8 @@ struct llarp_link
return false;
}
llarp::LogDebug("configure link ifname=", ifname, " af=", af,
" port=", port);
llarp::LogDebug("configure link ifname=", ifname, " af=", af, " port=",
port);
// bind
sockaddr_in ip4addr;
sockaddr_in6 ip6addr;
@ -369,7 +369,7 @@ struct llarp_link
addr = (sockaddr *)&ip6addr;
llarp::Zero(addr, sizeof(ip6addr));
break;
// TODO: AF_PACKET
// TODO: AF_PACKET
default:
llarp::LogError(__FILE__, "unsupported address family", af);
return false;
@ -396,7 +396,7 @@ struct llarp_link
case AF_INET6:
ip6addr.sin6_port = htons(port);
break;
// TODO: AF_PACKET
// TODO: AF_PACKET
default:
return false;
}

@ -43,6 +43,10 @@ namespace llarp
<< " v=" << i.version << " x=" << i.vanity << "]";
}
/// compute .loki address
std::string
Name() const;
/// calculate our address
bool
CalculateAddress(byte_t* buf) const;

@ -22,6 +22,9 @@ namespace llarp
bool
Start();
std::string
Name() const;
bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg);

@ -62,7 +62,7 @@ llarp_load_config(struct llarp_config *conf, const char *fname)
void
llarp_config_iter(struct llarp_config *conf, struct llarp_config_iterator *iter)
{
iter->conf = conf;
iter->conf = conf;
std::map< std::string, llarp::Config::section_t & > sections = {
{"network", conf->impl.network},
{"connect", conf->impl.connect},

@ -197,8 +197,8 @@ namespace llarp
#if(__APPLE__ && __MACH__)
#elif(__FreeBSD__)
pthread_set_name_np(netio_threads.back().native_handle(),
"llarp-netio");
pthread_set_name_np(netio_threads.back().native_handle(), "llarp-"
"netio");
#else
pthread_setname_np(netio_threads.back().native_handle(), "llarp-netio");
#endif
@ -303,7 +303,7 @@ struct llarp_main *
llarp_main_init(const char *fname, bool multiProcess)
{
if(!fname)
fname = "daemon.ini";
fname = "daemon.ini";
char *var = getenv("LLARP_DEBUG");
if(var && *var == '1')
{

@ -54,6 +54,8 @@ llarp_dht_lookup_router(struct llarp_dht_context *ctx,
{
job->dht = ctx;
job->found = false;
// TODO: check for reuse
llarp_rc_clear(&job->result);
llarp_logic_queue_job(ctx->parent->logic,
{job, &llarp::dht::Context::queue_router_lookup});
}

@ -85,7 +85,8 @@ namespace llarp
job->user = informer;
job->hook = &PathLookupInformer::InformReply;
job->found = false;
job->dht = ctx;
llarp_rc_clear(&job->result);
job->dht = ctx;
memcpy(job->target, K, sizeof(job->target));
Key_t peer;
if(dht.nodes->FindClosest(K, peer))
@ -191,5 +192,5 @@ namespace llarp
dht.LookupRouterRelayed(From, txid, K, !iterative, replies);
return true;
}
}
}
} // namespace dht
} // namespace llarp

@ -92,8 +92,8 @@ namespace llarp
{
if(size() <= size_t(EncryptedFrame::OverheadSize))
{
llarp::LogWarn("encrypted frame too small, ", size(),
" <= ", size_t(EncryptedFrame::OverheadSize));
llarp::LogWarn("encrypted frame too small, ", size(), " <= ",
size_t(EncryptedFrame::OverheadSize));
return false;
}
// format of frame is

@ -179,7 +179,7 @@ namespace ini
lp = l.parent;
size_t n = l.depth - depth;
for(size_t i = 0; i < n; ++i)
lp = lp->parent;
lp = lp->parent;
parent = lp;
lp = &lp->sections[sname];
}

@ -93,8 +93,8 @@ frame_state::got_xmit(frame_header hdr, size_t sz)
{
auto msg = new transit_message(x);
rx[id] = msg;
llarp::LogDebug("got message XMIT with ", (int)x.numfrags(),
" fragments");
llarp::LogDebug("got message XMIT with ", (int)x.numfrags(), " fragment"
"s");
// inserted, put last fragment
msg->put_lastfrag(hdr.data() + sizeof(x.buffer), x.lastfrag());
push_ackfor(id, 0);
@ -195,8 +195,8 @@ frame_state::inbound_frame_complete(uint64_t id)
if(memcmp(digest, rxmsg->msginfo.hash(), 32))
{
llarp::LogWarn("message hash missmatch ",
llarp::AlignedBuffer< 32 >(digest),
" != ", llarp::AlignedBuffer< 32 >(rxmsg->msginfo.hash()));
llarp::AlignedBuffer< 32 >(digest), " != ",
llarp::AlignedBuffer< 32 >(rxmsg->msginfo.hash()));
return false;
}

@ -141,9 +141,9 @@ void
llarp_link_session::add_outbound_message(uint64_t id, transit_message *msg)
{
llarp::LogDebug("add outbound message ", id, " of size ",
msg->msginfo.totalsize(),
" numfrags=", (int)msg->msginfo.numfrags(),
" lastfrag=", (int)msg->msginfo.lastfrag());
msg->msginfo.totalsize(), " numfrags=",
(int)msg->msginfo.numfrags(), " lastfrag=",
(int)msg->msginfo.lastfrag());
frame.queue_tx(id, msg);
pump();

@ -30,8 +30,8 @@ namespace llarp
return false;
if(version != LLARP_PROTO_VERSION)
{
llarp::LogWarn("llarp protocol version missmatch ", version,
" != ", LLARP_PROTO_VERSION);
llarp::LogWarn("llarp protocol version missmatch ", version, " != ",
LLARP_PROTO_VERSION);
return false;
}
llarp::LogDebug("LIM version ", version);

@ -97,7 +97,7 @@ namespace llarp
16);
*port = ((sockaddr_in6*)(&other))->sin6_port;
break;
// TODO : sockaddr_ll
// TODO : sockaddr_ll
default:
break;
}

@ -138,9 +138,8 @@ struct llarp_nodedb
buf.sz = buf.cur - buf.base;
auto filepath = getRCFilePath(pk);
llarp::LogDebug("saving RC.pubkey ", filepath);
std::ofstream ofs(
filepath,
std::ofstream::out & std::ofstream::binary & std::ofstream::trunc);
std::ofstream ofs(filepath, std::ofstream::out & std::ofstream::binary
& std::ofstream::trunc);
ofs.write((char *)buf.base, buf.sz);
ofs.close();
if(!ofs)

@ -413,8 +413,8 @@ namespace llarp
Path::HandlePathTransferMessage(
const llarp::routing::PathTransferMessage* msg, llarp_router* r)
{
llarp::LogWarn("unwarrented path transfer message on tx=", TXID(),
" rx=", RXID());
llarp::LogWarn("unwarrented path transfer message on tx=", TXID(), " rx=",
RXID());
return false;
}

@ -49,8 +49,8 @@ namespace llarp
{
if(frames.size() != MAXHOPS)
{
llarp::LogError("LRCM invalid number of records, ", frames.size(),
"!=", MAXHOPS);
llarp::LogError("LRCM invalid number of records, ", frames.size(), "!=",
MAXHOPS);
return false;
}
if(!router->paths.AllowingTransit())

@ -804,7 +804,7 @@ llarp_init_router(struct llarp_threadpool *tp, struct llarp_ev_loop *netloop,
router->netloop = netloop;
router->tp = tp;
router->logic = logic;
// TODO: make disk io threadpool count configurable
// TODO: make disk io threadpool count configurable
#ifdef TESTNET
router->disk = tp;
#else

@ -56,8 +56,8 @@ namespace llarp
{
return path->HandleDownstream(T.Buffer(), Y, r);
}
llarp::LogWarn("No such local path for path transfer src=", from,
" dst=", P);
llarp::LogWarn("No such local path for path transfer src=", from, " dst=",
P);
return false;
}
} // namespace routing

@ -7,69 +7,6 @@ namespace llarp
{
namespace service
{
std::string
AddressToString(const Address& addr)
{
char tmp[(1 + 32) * 2] = {0};
std::string str = Base32Encode(addr, tmp);
return str + ".loki";
}
ServiceInfo::ServiceInfo()
{
vanity.Zero();
}
ServiceInfo::~ServiceInfo()
{
}
bool
ServiceInfo::DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("e", enckey, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("s", signkey, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("v", version, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("x", vanity, read, key, val))
return false;
return read;
}
bool
ServiceInfo::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictEntry("e", enckey, buf))
return false;
if(!BEncodeWriteDictEntry("s", signkey, buf))
return false;
if(!BEncodeWriteDictInt(buf, "v", LLARP_PROTO_VERSION))
return false;
if(!vanity.IsZero())
{
if(!BEncodeWriteDictEntry("x", vanity, buf))
return false;
}
return bencode_end(buf);
}
bool
ServiceInfo::CalculateAddress(byte_t* addr) const
{
byte_t tmp[128];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!BEncode(&buf))
return false;
return crypto_generichash(addr, 32, buf.base, buf.cur - buf.base, nullptr,
0)
!= -1;
}
IntroSet::~IntroSet()
{
if(W)

@ -0,0 +1,15 @@
#include <llarp/service/address.hpp>
namespace llarp
{
namespace service
{
std::string
Address::ToString() const
{
char tmp[(1 + 32) * 2] = {0};
std::string str = Base32Encode(*this, tmp);
return str + ".loki";
}
} // namespace service
} // namespace llarp

@ -25,30 +25,35 @@ namespace llarp
{
if(ShouldPublishDescriptors())
{
llarp::LogDebug("publish descriptor for endpoint ", m_Name);
IntroSet introset;
if(!GetCurrentIntroductions(introset.I))
{
llarp::LogWarn("could not publish descriptors for endpoint ", m_Name,
llarp::LogWarn("could not publish descriptors for endpoint ", Name(),
" because we couldn't get any introductions");
return;
}
if(!m_Identity.SignIntroSet(introset, &m_Router->crypto))
{
llarp::LogWarn("failed to sign introset for endpoint ", m_Name);
llarp::LogWarn("failed to sign introset for endpoint ", Name());
return;
}
if(PublishIntroSet(introset, m_Router))
{
llarp::LogInfo("publishing introset for endpoint ", m_Name);
llarp::LogInfo("publishing introset for endpoint ", Name());
}
else
{
llarp::LogWarn("failed to publish intro set for endpoint ", m_Name);
llarp::LogWarn("failed to publish intro set for endpoint ", Name());
}
}
}
std::string
Endpoint::Name() const
{
return m_Name + ":" + m_Identity.pub.Name();
}
bool
Endpoint::HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg)
{
@ -59,14 +64,14 @@ namespace llarp
{
llarp::LogWarn(
"invalid signature in got intro message for service endpoint ",
m_Name);
Name());
return false;
}
if(m_Identity.pub == introset.A)
{
llarp::LogInfo(
"got introset publish confirmation for hidden service endpoint ",
m_Name);
Name());
}
else
{
@ -115,4 +120,4 @@ namespace llarp
return false;
}
} // namespace service
} // namespace llarp
} // namespace llarp

@ -0,0 +1,72 @@
#include <cassert>
#include <llarp/service/Info.hpp>
#include <llarp/service/address.hpp>
#include "buffer.hpp"
namespace llarp
{
namespace service
{
ServiceInfo::ServiceInfo()
{
vanity.Zero();
}
ServiceInfo::~ServiceInfo()
{
}
bool
ServiceInfo::DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("e", enckey, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("s", signkey, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("v", version, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("x", vanity, read, key, val))
return false;
return read;
}
bool
ServiceInfo::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictEntry("e", enckey, buf))
return false;
if(!BEncodeWriteDictEntry("s", signkey, buf))
return false;
if(!BEncodeWriteDictInt(buf, "v", LLARP_PROTO_VERSION))
return false;
if(!vanity.IsZero())
{
if(!BEncodeWriteDictEntry("x", vanity, buf))
return false;
}
return bencode_end(buf);
}
std::string
ServiceInfo::Name() const
{
// TODO: caching addr
Address addr;
CalculateAddress(addr);
return addr.ToString();
}
bool
ServiceInfo::CalculateAddress(byte_t* addr) const
{
byte_t tmp[128];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
assert(BEncode(&buf));
return crypto_generichash(addr, 32, buf.base, buf.cur - buf.base, nullptr,
0)
!= -1;
}
} // namespace service
} // namespace llarp
Loading…
Cancel
Save