diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index a7e53ca6575efa71e8c1b75726adaa95fa097091..4e5252fb4f819405727e502a8dba1f58f4c0fa06 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -2273,15 +2273,7 @@ JamiAccount::doRegister_() auto conversationId = name.substr(sep + 1); auto remoteDevice = name.substr(6, sep - 6); - auto isServer = false; - if (!DeviceId(remoteDevice)) { - // This means that the remoteDevice is a short Id, so with a non up-to-date client - isServer = remoteDevice - == accountManager_->getInfo()->devicePk->getId().toString(); - } else { - isServer = remoteDevice == currentDeviceId(); - } - if (!isServer || currentDeviceId() == deviceId.to_c_str()) { + if (channel->isInitiator()) { // Check if wanted remote it's our side (git://remoteDevice/conversationId) return; } @@ -2335,13 +2327,9 @@ JamiAccount::doRegister_() auto sep = idstr.find('/'); auto lastSep = idstr.find_last_of('/'); auto conversationId = idstr.substr(0, sep); - auto fileHost = idstr.substr(sep + 1, lastSep - sep - 1); auto fileId = idstr.substr(lastSep + 1); - if (fileHost == currentDeviceId()) // This means we are the host, so the file is - // outgoing, ignore - { + if (channel->isInitiator()) return; - } sep = fileId.find_last_of('?'); std::string arguments; diff --git a/src/jamidht/multiplexed_socket.cpp b/src/jamidht/multiplexed_socket.cpp index 8a9b328eadf24825e34a44464c68ff94aff04f10..1b337f6b1d8368037378710cdcd2b6350902462f 100644 --- a/src/jamidht/multiplexed_socket.cpp +++ b/src/jamidht/multiplexed_socket.cpp @@ -120,11 +120,11 @@ public: clearSockets(); } - std::shared_ptr<ChannelSocket> makeSocket(const std::string& name, uint16_t channel) + std::shared_ptr<ChannelSocket> makeSocket(const std::string& name, uint16_t channel, bool isInitiator = false) { auto& channelSocket = sockets[channel]; if (not channelSocket) - channelSocket = std::make_shared<ChannelSocket>(parent_.weak(), name, channel); + channelSocket = std::make_shared<ChannelSocket>(parent_.weak(), name, channel, isInitiator); else { JAMI_WARN("A channel is already present on that socket, accepting " "the request will close the previous one %s", @@ -510,7 +510,7 @@ MultiplexedSocket::addChannel(const std::string& name) if (c == CONTROL_CHANNEL || c == PROTOCOL_CHANNEL || pimpl_->sockets.find(c) != pimpl_->sockets.end()) continue; - return pimpl_->makeSocket(name, c); + return pimpl_->makeSocket(name, c, true); } return {}; } @@ -699,10 +699,11 @@ MultiplexedSocket::sendVersion() class ChannelSocket::Impl { public: - Impl(std::weak_ptr<MultiplexedSocket> endpoint, const std::string& name, const uint16_t& channel) + Impl(std::weak_ptr<MultiplexedSocket> endpoint, const std::string& name, const uint16_t& channel, bool isInitiator) : name(name) , channel(channel) , endpoint(std::move(endpoint)) + , isInitiator_(isInitiator) {} ~Impl() {} @@ -713,6 +714,7 @@ public: std::string name {}; uint16_t channel {}; std::weak_ptr<MultiplexedSocket> endpoint {}; + bool isInitiator_ {false}; std::vector<uint8_t> buf {}; std::mutex mutex {}; @@ -722,8 +724,9 @@ public: ChannelSocket::ChannelSocket(std::weak_ptr<MultiplexedSocket> endpoint, const std::string& name, - const uint16_t& channel) - : pimpl_ {std::make_unique<Impl>(endpoint, name, channel)} + const uint16_t& channel, + bool isInitiator) + : pimpl_ {std::make_unique<Impl>(endpoint, name, channel, isInitiator)} {} ChannelSocket::~ChannelSocket() {} @@ -761,10 +764,11 @@ ChannelSocket::isReliable() const bool ChannelSocket::isInitiator() const { - if (auto ep = pimpl_->endpoint.lock()) { - return ep->isInitiator(); - } - return false; + // Note. Is initiator here as not the same meaning of MultiplexedSocket. + // because a multiplexed socket can have sockets from accepted requests + // or made via connectDevice(). Here, isInitiator_ return if the socket + // is from connectDevice. + return pimpl_->isInitiator_; } int diff --git a/src/jamidht/multiplexed_socket.h b/src/jamidht/multiplexed_socket.h index 206d7f1e4ce970414621094ef951adea4944be28..8ff5f2352824d3e0375213eecb748fa8263c1053 100644 --- a/src/jamidht/multiplexed_socket.h +++ b/src/jamidht/multiplexed_socket.h @@ -176,7 +176,8 @@ public: using SocketType = GenericSocket<uint8_t>; ChannelSocket(std::weak_ptr<MultiplexedSocket> endpoint, const std::string& name, - const uint16_t& channel); + const uint16_t& channel, + bool isInitiator = false); ~ChannelSocket(); DeviceId deviceId() const;