mirror of https://github.com/oxen-io/lokinet
fix crash
This commit is contained in:
parent
1a1f93c171
commit
377cc78144
|
@ -40,6 +40,18 @@ namespace llarp
|
|||
bool
|
||||
SetupNetworking();
|
||||
|
||||
/// overrides Endpoint
|
||||
void
|
||||
HandleDataMessage(service::ProtocolMessage* msg);
|
||||
|
||||
/// overrides Endpount
|
||||
bool
|
||||
IsolationFailed()
|
||||
{
|
||||
m_TunSetupResult.set_value(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
llarp_tun_io tunif;
|
||||
|
||||
static void
|
||||
|
|
|
@ -70,6 +70,15 @@ namespace llarp
|
|||
LogAppend(ss, std::forward< TArgs >(args)...);
|
||||
}
|
||||
|
||||
static inline std::string
|
||||
thread_id_string()
|
||||
{
|
||||
auto tid = std::this_thread::get_id();
|
||||
std::hash< std::thread::id > h;
|
||||
uint16_t id = h(tid) % 1000;
|
||||
return std::to_string(id);
|
||||
}
|
||||
|
||||
/** internal */
|
||||
template < typename... TArgs >
|
||||
void
|
||||
|
@ -122,8 +131,8 @@ namespace llarp
|
|||
}
|
||||
#endif
|
||||
std::string tag = fname;
|
||||
ss << _glog.nodeName << " " << llarp_time_now_ms() << " " << tag << ":"
|
||||
<< lineno;
|
||||
ss << _glog.nodeName << " (" << thread_id_string() << ") "
|
||||
<< llarp_time_now_ms() << " " << tag << ":" << lineno;
|
||||
ss << "\t";
|
||||
LogAppend(ss, std::forward< TArgs >(args)...);
|
||||
#ifndef ANDROID
|
||||
|
|
|
@ -383,6 +383,12 @@ namespace llarp
|
|||
void
|
||||
AddOwnPath(PathSet* set, Path* p);
|
||||
|
||||
void
|
||||
RemovePathBuilder(llarp_pathbuilder_context* ctx);
|
||||
|
||||
void
|
||||
RemovePathSet(PathSet* set);
|
||||
|
||||
typedef std::multimap< PathID_t, TransitHop* > TransitHopsMap_t;
|
||||
|
||||
typedef std::pair< util::Mutex, TransitHopsMap_t > SyncTransitMap_t;
|
||||
|
|
|
@ -16,7 +16,7 @@ struct llarp_pathbuilder_context : public llarp::path::PathSet
|
|||
struct llarp_dht_context* p_dht, size_t numPaths,
|
||||
size_t numHops);
|
||||
|
||||
virtual ~llarp_pathbuilder_context(){};
|
||||
virtual ~llarp_pathbuilder_context();
|
||||
|
||||
virtual bool
|
||||
SelectHop(llarp_nodedb* db, llarp_rc* prev, llarp_rc* cur, size_t hop);
|
||||
|
|
|
@ -135,4 +135,4 @@ namespace llarp
|
|||
} // namespace path
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -252,10 +252,10 @@ namespace llarp
|
|||
OnOutboundLookup(const IntroSet* i); /* */
|
||||
|
||||
static bool
|
||||
SetupIsolatedNetwork(void* user);
|
||||
SetupIsolatedNetwork(void* user, bool failed);
|
||||
|
||||
bool
|
||||
DoNetworkIsolation();
|
||||
DoNetworkIsolation(bool failed);
|
||||
|
||||
virtual bool
|
||||
SetupNetworking()
|
||||
|
@ -264,6 +264,13 @@ namespace llarp
|
|||
return true;
|
||||
}
|
||||
|
||||
virtual bool
|
||||
IsolationFailed()
|
||||
{
|
||||
// XXX: override me
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
GenTXID();
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ llarp_init_threadpool(int workers, const char *name);
|
|||
struct llarp_threadpool *
|
||||
llarp_init_same_process_threadpool();
|
||||
|
||||
typedef bool (*setup_net_func)(void *);
|
||||
typedef bool (*setup_net_func)(void *, bool);
|
||||
typedef void (*run_main_func)(void *);
|
||||
|
||||
/// for network isolation
|
||||
|
|
|
@ -193,7 +193,8 @@ struct llarp_epoll_loop : public llarp_ev_loop
|
|||
++idx;
|
||||
}
|
||||
}
|
||||
tick_listeners();
|
||||
if(result != -1)
|
||||
tick_listeners();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -228,7 +229,8 @@ struct llarp_epoll_loop : public llarp_ev_loop
|
|||
++idx;
|
||||
}
|
||||
}
|
||||
tick_listeners();
|
||||
if(result != -1)
|
||||
tick_listeners();
|
||||
} while(epollfd != -1);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -97,6 +97,12 @@ namespace llarp
|
|||
Endpoint::Tick(now);
|
||||
}
|
||||
|
||||
void
|
||||
TunEndpoint::HandleDataMessage(service::ProtocolMessage *msg)
|
||||
{
|
||||
// TODO: implement me
|
||||
}
|
||||
|
||||
void
|
||||
TunEndpoint::handleTickTun(void *u)
|
||||
{
|
||||
|
|
|
@ -295,6 +295,28 @@ namespace llarp
|
|||
m_PathBuilders.push_back(ctx);
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::RemovePathSet(PathSet* set)
|
||||
{
|
||||
util::Lock lock(m_OurPaths.first);
|
||||
auto& map = m_OurPaths.second;
|
||||
auto itr = map.begin();
|
||||
while(itr != map.end())
|
||||
{
|
||||
if(itr->second == set)
|
||||
itr = map.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::RemovePathBuilder(llarp_pathbuilder_context* ctx)
|
||||
{
|
||||
m_PathBuilders.remove(ctx);
|
||||
RemovePathSet(ctx);
|
||||
}
|
||||
|
||||
PathHopConfig::PathHopConfig()
|
||||
{
|
||||
llarp_rc_clear(&router);
|
||||
|
|
|
@ -194,6 +194,11 @@ llarp_pathbuilder_context::llarp_pathbuilder_context(
|
|||
p_router->crypto.encryption_keygen(enckey);
|
||||
}
|
||||
|
||||
llarp_pathbuilder_context::~llarp_pathbuilder_context()
|
||||
{
|
||||
router->paths.RemovePathBuilder(this);
|
||||
}
|
||||
|
||||
bool
|
||||
llarp_pathbuilder_context::SelectHop(llarp_nodedb* db, llarp_rc* prev,
|
||||
llarp_rc* cur, size_t hop)
|
||||
|
|
|
@ -267,9 +267,12 @@ llarp_router::Close()
|
|||
inboundLinks.clear();
|
||||
|
||||
llarp::LogInfo("Closing LokiNetwork client");
|
||||
outboundLink->stop_link();
|
||||
delete outboundLink;
|
||||
outboundLink = nullptr;
|
||||
if(outboundLink)
|
||||
{
|
||||
outboundLink->stop_link();
|
||||
delete outboundLink;
|
||||
outboundLink = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -93,9 +93,9 @@ namespace llarp
|
|||
};
|
||||
|
||||
bool
|
||||
Endpoint::SetupIsolatedNetwork(void* user)
|
||||
Endpoint::SetupIsolatedNetwork(void* user, bool failed)
|
||||
{
|
||||
return static_cast< Endpoint* >(user)->DoNetworkIsolation();
|
||||
return static_cast< Endpoint* >(user)->DoNetworkIsolation(failed);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -567,8 +567,10 @@ namespace llarp
|
|||
};
|
||||
|
||||
bool
|
||||
Endpoint::DoNetworkIsolation()
|
||||
Endpoint::DoNetworkIsolation(bool failed)
|
||||
{
|
||||
if(failed)
|
||||
return IsolationFailed();
|
||||
llarp_ev_loop_alloc(&m_IsolatedNetLoop);
|
||||
return SetupNetworking();
|
||||
}
|
||||
|
|
|
@ -119,7 +119,10 @@ namespace llarp
|
|||
self->m_IsolatedWorkers = workers;
|
||||
m_isolated = new std::thread([self] {
|
||||
if(unshare(self->m_flags) == -1)
|
||||
{
|
||||
llarp::LogError("unshared failed: ", strerror(errno));
|
||||
self->Fail();
|
||||
}
|
||||
else
|
||||
{
|
||||
llarp::LogInfo("spawning isolated environment");
|
||||
|
@ -149,9 +152,9 @@ namespace llarp
|
|||
}
|
||||
|
||||
#ifdef __linux__
|
||||
NetIsolatedPool::NetIsolatedPool(std::function< bool(void *) > setupNet,
|
||||
std::function< void(void *) > runMain,
|
||||
void *user)
|
||||
NetIsolatedPool::NetIsolatedPool(
|
||||
std::function< bool(void *, bool) > setupNet,
|
||||
std::function< void(void *) > runMain, void *user)
|
||||
: IsolatedPool(CLONE_NEWNET)
|
||||
{
|
||||
m_NetSetup = setupNet;
|
||||
|
@ -159,9 +162,9 @@ namespace llarp
|
|||
m_user = user;
|
||||
}
|
||||
#else
|
||||
NetIsolatedPool::NetIsolatedPool(std::function< bool(void *) > setupNet,
|
||||
std::function< void(void *) > runMain,
|
||||
void *user)
|
||||
NetIsolatedPool::NetIsolatedPool(
|
||||
std::function< bool(void *, bool) > setupNet,
|
||||
std::function< void(void *) > runMain, void *user)
|
||||
: IsolatedPool(0)
|
||||
{
|
||||
m_NetSetup = setupNet;
|
||||
|
|
|
@ -74,6 +74,12 @@ namespace llarp
|
|||
return true;
|
||||
}
|
||||
|
||||
/// called when isolation failed
|
||||
virtual void
|
||||
Fail()
|
||||
{
|
||||
}
|
||||
|
||||
std::thread* m_isolated = nullptr;
|
||||
int m_flags;
|
||||
int m_IsolatedWorkers = 0;
|
||||
|
@ -87,13 +93,19 @@ namespace llarp
|
|||
|
||||
struct NetIsolatedPool : public IsolatedPool
|
||||
{
|
||||
NetIsolatedPool(std::function< bool(void*) > setupNet,
|
||||
NetIsolatedPool(std::function< bool(void*, bool) > setupNet,
|
||||
std::function< void(void*) > runMain, void* user);
|
||||
|
||||
bool
|
||||
Isolated()
|
||||
{
|
||||
return m_NetSetup(m_user);
|
||||
return m_NetSetup(m_user, true);
|
||||
}
|
||||
|
||||
void
|
||||
Fail()
|
||||
{
|
||||
m_NetSetup(m_user, false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -102,7 +114,7 @@ namespace llarp
|
|||
m_RunMain(m_user);
|
||||
}
|
||||
|
||||
std::function< bool(void*) > m_NetSetup;
|
||||
std::function< bool(void*, bool) > m_NetSetup;
|
||||
std::function< void(void*) > m_RunMain;
|
||||
void* m_user;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue