Commit 093537a6 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Sébastien Blin

peerdiscovery: add getNearbyPeers() function

Change-Id: Ifcf2c2b3676a1903f16818e889dac6ca85a5aa0a
Reviewed-by: Sébastien Blin's avatarSébastien Blin <sebastien.blin@savoirfairelinux.com>
parent 4e26b6a5
......@@ -559,6 +559,16 @@
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="messages"/>
</method>
<method name="getNearbyPeers" tp:name-for-bindings="getNearbyPeers">
<arg type="s" name="accountID" direction="in"/>
<arg type="a{ss}" name="result" direction="out" tp:type="String_String_Map"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/>
<tp:docstring>
Get Discovered Peer Map
</tp:docstring>
</method>
<method name="getMessageStatus" tp:name-for-bindings="getMessageStatus">
<arg type="t" name="id" direction="in"/>
<arg type="i" name="status" direction="out">
......
......@@ -168,6 +168,12 @@ DBusConfigurationManager::getLastMessages(const std::string& accountID, const ui
return result;
}
std::map<std::string, std::string>
DBusConfigurationManager::getNearbyPeers(const std::string& accountID)
{
return DRing::getNearbyPeers(accountID);
}
auto
DBusConfigurationManager::getMessageStatus(const uint64_t& id) -> decltype(DRing::getMessageStatus(id))
{
......
......@@ -84,6 +84,7 @@ class DRING_PUBLIC DBusConfigurationManager :
void registerAllAccounts(void);
uint64_t sendTextMessage(const std::string& accoundID, const std::string& to, const std::map<std::string, std::string>& payloads);
std::vector<RingDBusMessage> getLastMessages(const std::string& accountID, const uint64_t& base_timestamp);
std::map<std::string, std::string> getNearbyPeers(const std::string& accountID);
int getMessageStatus(const uint64_t& id);
int getMessageStatus(const std::string& accountID, const uint64_t& id);
bool cancelMessage(const std::string& accountID, const uint64_t& messageId);
......
......@@ -2,7 +2,7 @@ dnl Jami - configure.ac for automake 1.9 and autoconf 2.59
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
AC_INIT([Jami Daemon],[7.6.0],[ring@gnu.org],[jami])
AC_INIT([Jami Daemon],[7.7.0],[ring@gnu.org],[jami])
AC_COPYRIGHT([[Copyright (c) Savoir-faire Linux 2004-2019]])
AC_REVISION([$Revision$])
......
......@@ -160,6 +160,10 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
return {};
}
virtual std::map<std::string, std::string> getNearbyPeers(const std::string& accountID) {
return {};
}
/**
* Return the status corresponding to the token.
*/
......
......@@ -270,6 +270,13 @@ getLastMessages(const std::string& accountID, const uint64_t& base_timestamp)
return {};
}
std::map<std::string, std::string>
getNearbyPeers(const std::string& accountID)
{
return jami::Manager::instance().getNearbyPeers(accountID);
}
int
getMessageStatus(uint64_t messageId)
{
......
......@@ -77,6 +77,7 @@ DRING_PUBLIC void registerAllAccounts(void);
DRING_PUBLIC uint64_t sendAccountTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& payloads);
DRING_PUBLIC bool cancelMessage(const std::string& accountID, uint64_t message);
DRING_PUBLIC std::vector<Message> getLastMessages(const std::string& accountID, const uint64_t& base_timestamp);
DRING_PUBLIC std::map<std::string, std::string> getNearbyPeers(const std::string& accountID);
DRING_PUBLIC int getMessageStatus(uint64_t id);
DRING_PUBLIC int getMessageStatus(const std::string& accountID, uint64_t id);
......
......@@ -3709,6 +3709,7 @@ JamiAccount::startAccountDiscovery()
//Create or Find the old one
auto& dp = discoveredPeers_[v.accountId];
dp.displayName = v.displayName;
discoveredPeerMap_[v.accountId.toString()] = v.displayName;
if (dp.cleanupTask) {
dp.cleanupTask->cancel();
} else {
......@@ -3722,6 +3723,7 @@ JamiAccount::startAccountDiscovery()
{
std::lock_guard<std::mutex> lc(this_->discoveryMapMtx_);
this_->discoveredPeers_.erase(p);
this_->discoveredPeerMap_.erase(p.toString());
}
//Send Deleted Peer
emitSignal<DRing::PresenceSignal::NearbyPeerNotification>(this_->getAccountID(), p.toString(), 1, a);
......@@ -3732,4 +3734,10 @@ JamiAccount::startAccountDiscovery()
});
}
std::map<std::string, std::string>
JamiAccount::getNearbyPeers()
{
return discoveredPeerMap_;
}
} // namespace jami
......@@ -399,6 +399,11 @@ class JamiAccount : public SIPAccountBase {
void saveConfig() const;
/**
* Get current discovered peers account id and display name
*/
std::map<std::string, std::string> getNearbyPeers();
private:
NON_COPYABLE(JamiAccount);
......@@ -695,6 +700,7 @@ class JamiAccount : public SIPAccountBase {
std::mutex discoveryMapMtx_;
std::shared_ptr<dht::PeerDiscovery> peerDiscovery_;
std::map<dht::InfoHash, DiscoveredPeer> discoveredPeers_;
std::map<std::string, std::string> discoveredPeerMap_;
bool accountPeerDiscovery_ {true};
std::shared_ptr<RepeatedTask> eventHandler {};
......
......@@ -3159,4 +3159,12 @@ Manager::getLastMessages(const std::string& accountID, const uint64_t& base_time
return {};
}
std::map<std::string, std::string>
Manager::getNearbyPeers(const std::string& accountID)
{
if (const auto acc = getAccount<JamiAccount>(accountID))
return acc->getNearbyPeers();
return {};
}
} // namespace jami
......@@ -859,6 +859,8 @@ class Manager {
void addTask(std::function<bool()>&& task);
std::shared_ptr<Task> scheduleTask(std::function<void()>&& task, std::chrono::steady_clock::time_point when);
std::map<std::string, std::string> getNearbyPeers(const std::string& accountID);
#ifdef ENABLE_VIDEO
/**
* Create a new SinkClient instance, store it in an internal cache as a weak_ptr
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment