liblokinet and lnproxy updates

* add lokinet_status function to get the current status of the context, aka are we ready to send or not.
* catch some exceptions in lnproxy
pull/1576/head
Jeff Becker 3 years ago
parent e005b34169
commit 2ed0ab1ca1
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -67,6 +67,9 @@ class Context:
def wait_for_ready(self, ms):
return self.ln_call("lokinet_wait_for_ready", ms) == 0
def ready(self):
return self.ln_call("lokinet_status") == 0
def addr(self):
return self._ln.lokinet_address(self._ctx).decode('ascii')
@ -100,6 +103,10 @@ class Context:
if addr in self._addrmap:
return self._addrmap[addr]
def delAddr(self, addr):
if addr in self._addrmap:
del self._addrmap[addr]
def __del__(self):
self.stop()
self._ln_call("lokinet_context_free")
@ -153,10 +160,17 @@ class Handler(BaseHandler):
def connect(self, host):
global ctx
if not ctx.ready():
self.send_error(501)
return
if not ctx.hasAddr(host):
stream = Stream(ctx)
result = stream.connect(host)
result = None
try:
result = stream.connect(host)
except:
pass
if not result:
self.send_error(503)
return
@ -166,7 +180,7 @@ class Handler(BaseHandler):
try:
sock.connect(ctx.getAddr(host))
except:
self.delAddr(host)
ctx.delAddr(host)
self.send_error(504)
return

@ -48,6 +48,13 @@ extern "C"
int
lokinet_context_start(struct lokinet_context*);
/// return 0 if we our endpoint has published on the network and is ready to send
/// return -1 if we don't have enough paths ready
/// retrun -2 if we look deadlocked
/// retrun -3 if context was null or not started yet
int
lokinet_status(struct lokinet_context*);
/// wait at most N milliseconds for lokinet to build paths and get ready
/// return 0 if we are ready
/// return nonzero if we are not ready

@ -240,6 +240,19 @@ extern "C"
return 0;
}
int
lokinet_status(struct lokinet_context* ctx)
{
if (ctx == nullptr)
return -3;
auto lock = ctx->acquire();
if (not ctx->impl->IsUp())
return -3;
if (not ctx->impl->LooksAlive())
return -2;
return ctx->endpoint()->IsReady() ? 0 : -1;
}
int
lokinet_wait_for_ready(int ms, struct lokinet_context* ctx)
{

Loading…
Cancel
Save