Skip to content
Snippets Groups Projects
Commit f3d893b9 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Improve net connection detection

parent 40e76e51
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28531 failed
...@@ -86,6 +86,9 @@ class Universe : public ftl::Configurable { ...@@ -86,6 +86,9 @@ class Universe : public ftl::Configurable {
*/ */
Peer *connect(const std::string &addr); Peer *connect(const std::string &addr);
bool isConnected(const ftl::URI &uri);
bool isConnected(const std::string &s);
size_t numberOfPeers() const { return peers_.size(); } size_t numberOfPeers() const { return peers_.size(); }
/** /**
......
...@@ -148,15 +148,26 @@ bool Universe::listen(const string &addr) { ...@@ -148,15 +148,26 @@ bool Universe::listen(const string &addr) {
return l->isListening(); return l->isListening();
} }
bool Universe::isConnected(const ftl::URI &uri) {
UNIQUE_LOCK(net_mutex_,lk);
return (peer_by_uri_.find(uri.getBaseURI()) != peer_by_uri_.end());
}
bool Universe::isConnected(const std::string &s) {
ftl::URI uri(s);
return isConnected(uri);
}
Peer *Universe::connect(const string &addr) { Peer *Universe::connect(const string &addr) {
ftl::URI u(addr);
// Check if already connected or if self // Check if already connected or if self
{ {
UNIQUE_LOCK(net_mutex_,lk); UNIQUE_LOCK(net_mutex_,lk);
if (peer_by_uri_.find(addr) != peer_by_uri_.end()) { if (peer_by_uri_.find(u.getBaseURI()) != peer_by_uri_.end()) {
return peer_by_uri_[addr]; return peer_by_uri_.at(u.getBaseURI());
} }
ftl::URI u(addr);
if (u.getHost() == "localhost" || u.getHost() == "127.0.0.1") { if (u.getHost() == "localhost" || u.getHost() == "127.0.0.1") {
for (const auto *l : listeners_) { for (const auto *l : listeners_) {
if (l->port() == u.getPort()) { if (l->port() == u.getPort()) {
...@@ -173,7 +184,7 @@ Peer *Universe::connect(const string &addr) { ...@@ -173,7 +184,7 @@ Peer *Universe::connect(const string &addr) {
if (p->status() != Peer::kInvalid) { if (p->status() != Peer::kInvalid) {
UNIQUE_LOCK(net_mutex_,lk); UNIQUE_LOCK(net_mutex_,lk);
peers_.push_back(p); peers_.push_back(p);
peer_by_uri_[addr] = p; peer_by_uri_[u.getBaseURI()] = p;
} }
_installBindings(p); _installBindings(p);
......
...@@ -600,9 +600,14 @@ bool Feed::sourceAvailable(const std::string &uri) { ...@@ -600,9 +600,14 @@ bool Feed::sourceAvailable(const std::string &uri) {
bool Feed::sourceActive(const std::string &suri) { bool Feed::sourceActive(const std::string &suri) {
ftl::URI uri(suri); ftl::URI uri(suri);
if (uri.getScheme() == ftl::URI::SCHEME_TCP || uri.getScheme() == ftl::URI::SCHEME_WS) {
return net_->isConnected(uri);
} else {
SHARED_LOCK(mtx_, lk); SHARED_LOCK(mtx_, lk);
return fsid_lookup_.count(uri.getBaseURI()) > 0; return fsid_lookup_.count(uri.getBaseURI()) > 0;
} }
}
std::string Feed::getName(const std::string &puri) { std::string Feed::getName(const std::string &puri) {
ftl::URI uri(puri); ftl::URI uri(puri);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment