Ring Daemon 16.0.0
Loading...
Searching...
No Matches
jamiaccount.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include "def.h"
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include "sip/sipaccountbase.h"
27#include "data_transfer.h"
28#include "uri.h"
29#include "jamiaccount_config.h"
30
31#include "noncopyable.h"
32#include "ring_types.h" // enable_if_base_of
33#include "scheduled_executor.h"
34#include "gitserver.h"
35#include "channel_handler.h"
36#include "conversation_module.h"
37#include "sync_module.h"
39
40#include <dhtnet/diffie-hellman.h>
41#include <dhtnet/tls_session.h>
42#include <dhtnet/multiplexed_socket.h>
43#include <dhtnet/certstore.h>
44#include <dhtnet/connectionmanager.h>
45#include <dhtnet/upnp/mapping.h>
46#include <dhtnet/ip_utils.h>
47#include <dhtnet/fileutils.h>
48
49#include <opendht/dhtrunner.h>
50#include <opendht/default_types.h>
51
52#include <pjsip/sip_types.h>
53#include <json/json.h>
54
55#include <chrono>
56#include <functional>
57#include <future>
58#include <list>
59#include <map>
60#include <optional>
61#include <vector>
62#include <filesystem>
63#include <shared_mutex>
64
65#if HAVE_RINGNS
66#include "namedirectory.h"
67#endif
68
69namespace dev {
70template<unsigned N>
71class FixedHash;
72using h160 = FixedHash<20>;
73using Address = h160;
74} // namespace dev
75
76namespace jami {
77
78class IceTransport;
79struct Contact;
80struct AccountArchive;
82class AccountManager;
83struct AccountInfo;
84class SipTransport;
86class SyncModule;
87
88using SipConnectionKey = std::pair<std::string /* uri */, DeviceId>;
89
90static constexpr const char MIME_TYPE_IM_COMPOSING[] {"application/im-iscomposing+xml"};
91
96{
97public:
98 constexpr static auto ACCOUNT_TYPE = ACCOUNT_TYPE_JAMI;
99 constexpr static const std::pair<uint16_t, uint16_t> DHT_PORT_RANGE {4000, 8888};
100 constexpr static int ICE_STREAMS_COUNT {1};
101 constexpr static int ICE_COMP_COUNT_PER_STREAM {1};
102
103 std::string_view getAccountType() const override { return ACCOUNT_TYPE; }
104
105 std::shared_ptr<JamiAccount> shared()
106 {
107 return std::static_pointer_cast<JamiAccount>(shared_from_this());
108 }
109 std::shared_ptr<JamiAccount const> shared() const
110 {
111 return std::static_pointer_cast<JamiAccount const>(shared_from_this());
112 }
113 std::weak_ptr<JamiAccount> weak()
114 {
115 return std::static_pointer_cast<JamiAccount>(shared_from_this());
116 }
117 std::weak_ptr<JamiAccount const> weak() const
118 {
119 return std::static_pointer_cast<JamiAccount const>(shared_from_this());
120 }
121
123 {
124 return *static_cast<const JamiAccountConfig*>(&Account::config());
125 }
126
128 {
129 auto conf = static_cast<JamiAccountConfig*>(config_.get());
130 return std::move(conf->credentials);
131 }
132
133 void loadConfig() override;
134
139 JamiAccount(const std::string& accountId);
140
142
147 virtual std::map<std::string, std::string> getVolatileAccountDetails() const override;
148
150 {
151 return std::make_unique<JamiAccountConfig>(getAccountID(), idPath_);
152 }
153
160 void trackBuddyPresence(const std::string& buddy_id, bool track);
161
168 std::map<std::string, bool> getTrackedBuddyPresence() const;
169
170 void setActiveCodecs(const std::vector<unsigned>& list) override;
171
175 void doRegister() override;
176
180 void doUnregister(bool forceShutdownConnections = false) override;
181
187 int detail_code = 0,
188 const std::string& detail_str = {}) override;
189
199 std::string getFromUri() const override;
200
209 std::string getToUri(const std::string& username) const override;
210
219 std::string getServerUri() const { return ""; };
220
221 void setIsComposing(const std::string& conversationUri, bool isWriting) override;
222
223 bool setMessageDisplayed(const std::string& conversationUri,
224 const std::string& messageId,
225 int status) override;
226
231 std::string getContactHeader(const std::shared_ptr<SipTransport>& sipTransport);
232
233 /* Returns true if the username and/or hostname match this account */
234 MatchRank matches(std::string_view username, std::string_view hostname) const override;
235
246 std::shared_ptr<Call> newOutgoingCall(std::string_view toUrl,
247 const std::vector<libjami::MediaMap>& mediaList) override;
248
256 std::shared_ptr<SIPCall> newIncomingCall(
257 const std::string& from,
258 const std::vector<libjami::MediaMap>& mediaList,
259 const std::shared_ptr<SipTransport>& sipTr = {}) override;
260
261 void onTextMessage(const std::string& id,
262 const std::string& from,
263 const std::shared_ptr<dht::crypto::Certificate>& peerCert,
264 const std::map<std::string, std::string>& payloads) override;
265 void loadConversation(const std::string& convId);
266
267 virtual bool isTlsEnabled() const override { return true; }
268 bool isSrtpEnabled() const override { return true; }
269
270 virtual bool getSrtpFallback() const override { return false; }
271
272 bool setCertificateStatus(const std::string& cert_id,
273 dhtnet::tls::TrustStore::PermissionStatus status);
274 bool setCertificateStatus(const std::shared_ptr<crypto::Certificate>& cert,
275 dhtnet::tls::TrustStore::PermissionStatus status,
276 bool local = true);
277 std::vector<std::string> getCertificatesByStatus(
278 dhtnet::tls::TrustStore::PermissionStatus status);
279
280 bool findCertificate(const std::string& id);
281 bool findCertificate(
282 const dht::InfoHash& h,
283 std::function<void(const std::shared_ptr<dht::crypto::Certificate>&)>&& cb = {});
284 bool findCertificate(
285 const dht::PkId& h,
286 std::function<void(const std::shared_ptr<dht::crypto::Certificate>&)>&& cb = {});
287
288 /* contact requests */
289 std::vector<std::map<std::string, std::string>> getTrustRequests() const;
290 // Note: includeConversation used for compatibility test. Do not change
291 bool acceptTrustRequest(const std::string& from, bool includeConversation = true);
292 bool discardTrustRequest(const std::string& from);
293 void declineConversationRequest(const std::string& conversationId);
294
299 void addContact(const std::string& uri, bool confirmed = false);
300 void removeContact(const std::string& uri, bool banned = true);
301 std::vector<std::map<std::string, std::string>> getContacts(bool includeRemoved = false) const;
302
306 std::map<std::string, std::string> getContactDetails(const std::string& uri) const;
307 std::optional<Contact> getContactInfo(const std::string& uri) const;
308
309 void sendTrustRequest(const std::string& to, const std::vector<uint8_t>& payload);
310 void sendMessage(const std::string& to,
311 const std::string& deviceId,
312 const std::map<std::string, std::string>& payloads,
313 uint64_t id,
314 bool retryOnTimeout = true,
315 bool onlyConnected = false) override;
316
317 uint64_t sendTextMessage(const std::string& to,
318 const std::string& deviceId,
319 const std::map<std::string, std::string>& payloads,
321 bool onlyConnected = false) override;
322 void sendInstantMessage(const std::string& convId,
323 const std::map<std::string, std::string>& msg);
324
328 dhtnet::IceTransportOptions getIceOptions() const override;
329 void getIceOptions(std::function<void(dhtnet::IceTransportOptions&&)> cb) const;
330 dhtnet::IpAddr getPublishedIpAddress(uint16_t family = PF_UNSPEC) const override;
331
332 /* Devices - existing device */
341 int32_t addDevice(const std::string& uriProvided);
344 /* Devices - new device */
345 bool provideAccountAuthentication(const std::string& credentialsFromUser,
346 const std::string& scheme);
347
355 bool exportArchive(const std::string& destinationPath,
356 std::string_view scheme = {},
357 const std::string& password = {});
358 bool revokeDevice(const std::string& device,
359 std::string_view scheme = {},
360 const std::string& password = {});
361 std::map<std::string, std::string> getKnownDevices() const;
362
363 bool isPasswordValid(const std::string& password);
364 std::vector<uint8_t> getPasswordKey(const std::string& password);
365
366 bool changeArchivePassword(const std::string& password_old, const std::string& password_new);
367
368 void connectivityChanged() override;
369
370 // overloaded methods
371 void flush() override;
372
373#if HAVE_RINGNS
374 void lookupName(const std::string& name);
375 void lookupAddress(const std::string& address);
376 void registerName(const std::string& name,
377 const std::string& scheme,
378 const std::string& password);
379#endif
380 bool searchUser(const std::string& nameQuery);
381
385 bool isMessageTreated(dht::Value::Id id);
386
387 std::shared_ptr<dht::DhtRunner> dht() { return dht_; }
388
389 const dht::crypto::Identity& identity() const { return id_; }
390
391 void forEachDevice(const dht::InfoHash& to,
392 std::function<void(const std::shared_ptr<dht::crypto::PublicKey>&)>&& op,
393 std::function<void(bool)>&& end = {});
394
395 bool setPushNotificationToken(const std::string& pushDeviceToken = "") override;
396 bool setPushNotificationTopic(const std::string& topic) override;
397 bool setPushNotificationConfig(const std::map<std::string, std::string>& data) override;
398
402 void pushNotificationReceived(const std::string& from,
403 const std::map<std::string, std::string>& data);
404
405 std::string getUserUri() const override;
406
411 std::vector<libjami::Message> getLastMessages(const uint64_t& base_timestamp) override;
412
416 void startAccountPublish();
417
422
423 void saveConfig() const override;
424
425 inline void editConfig(std::function<void(JamiAccountConfig& conf)>&& edit)
426 {
428 [&](AccountConfig& conf) { edit(*static_cast<JamiAccountConfig*>(&conf)); });
429 }
430
434 std::map<std::string, std::string> getNearbyPeers() const override;
435
436 void sendProfileToPeers();
437
444 void updateProfile(const std::string& displayName,
445 const std::string& avatar,
446 const std::string& fileType,
447 int32_t flag) override;
448
449#ifdef LIBJAMI_TEST
450 dhtnet::ConnectionManager& connectionManager() { return *connectionManager_; }
451
457
458 void publishPresence(bool newValue) { publishPresence_ = newValue; }
459#endif
460
465 void shutdownConnections();
466
467 std::string_view currentDeviceId() const;
468
469 // Received a new commit notification
470
471 bool handleMessage(const std::shared_ptr<dht::crypto::Certificate>& cert,
472 const std::string& from,
473 const std::pair<std::string, std::string>& message) override;
474
475 void monitor();
476 // conversationId optional
477 std::vector<std::map<std::string, std::string>> getConnectionList(
478 const std::string& conversationId = "");
479 std::vector<std::map<std::string, std::string>> getChannelList(const std::string& connectionId);
480
481 // File transfer
482 void sendFile(const std::string& conversationId,
483 const std::filesystem::path& path,
484 const std::string& name,
485 const std::string& replyTo);
486
487 void transferFile(const std::string& conversationId,
488 const std::string& path,
489 const std::string& deviceId,
490 const std::string& fileId,
491 const std::string& interactionId,
492 size_t start = 0,
493 size_t end = 0,
494 const std::string& sha3Sum = "",
496 std::function<void()> onFinished = {});
497
498 void askForFileChannel(const std::string& conversationId,
499 const std::string& deviceId,
500 const std::string& interactionId,
501 const std::string& fileId,
502 size_t start = 0,
503 size_t end = 0);
504
505 void askForProfile(const std::string& conversationId,
506 const std::string& deviceId,
507 const std::string& memberUri);
508
514 std::shared_ptr<TransferManager> dataTransfer(const std::string& id = "");
515
522 ConversationModule* convModule(bool noCreation = false);
523 SyncModule* syncModule();
524
531 // Note: when swarm will be merged, this can be moved in transferManager
532 bool needToSendProfile(const std::string& peerUri,
533 const std::string& deviceId,
534 const std::string& sha3Sum);
541 void sendProfile(const std::string& convId,
542 const std::string& peerUri,
543 const std::string& deviceId);
549 void sendProfile(const std::string& peerUri, const std::string& deviceId);
554 void clearProfileCache(const std::string& peerUri);
555
556 std::filesystem::path profilePath() const;
557
558 const std::shared_ptr<AccountManager>& accountManager() { return accountManager_; }
559
560 bool sha3SumVerify() const;
561
569 bool setValidity(std::string_view scheme,
570 const std::string& pwd,
571 const dht::InfoHash& id,
576 void forceReloadAccount();
577
578 void reloadContacts();
579
584 void unlinkConversations(const std::set<std::string>& removedConv);
585
586 bool isValidAccountDevice(const dht::crypto::Certificate& cert) const;
587
593 void handleIncomingConversationCall(const std::string& callId, const std::string& destination);
594
600 bool isMobile() const { return config().proxyEnabled and not config().deviceKey.empty(); }
601
602#ifdef LIBJAMI_TEST
603 std::map<Uri::Scheme, std::unique_ptr<ChannelHandlerInterface>>& channelHandlers()
604 {
605 return channelHandlers_;
606 };
607#endif
608
609 dhtnet::tls::CertificateStore& certStore() const { return *certStore_; }
615 bool isConnectedWith(const DeviceId& deviceId) const;
616
621 void sendPresenceNote(const std::string& note);
622
623private:
625
626 using clock = std::chrono::system_clock;
627 using time_point = clock::time_point;
628
632 struct PendingCall;
633 struct PendingMessage;
634 struct BuddyInfo;
635 struct DiscoveredPeer;
636
637 inline std::string getProxyConfigKey() const
638 {
639 const auto& conf = config();
640 return dht::InfoHash::get(conf.proxyServer + conf.proxyListUrl).toString();
641 }
642
646 /* static std::pair<std::vector<uint8_t>, dht::InfoHash> computeKeys(const std::string&
647 password, const std::string& pin, bool previous = false);
648 */
649
650 void trackPresence(const dht::InfoHash& h, BuddyInfo& buddy);
651 void onPeerConnected(const std::string& peerId, bool connected);
652
653 void doRegister_();
654
655 const dht::ValueType USER_PROFILE_TYPE = {9, "User profile", std::chrono::hours(24 * 7)};
656
657 void startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::string& toUri);
658
659 void onConnectedOutgoingCall(const std::shared_ptr<SIPCall>& call,
660 const std::string& to_id,
661 dhtnet::IpAddr target);
662
668 bool SIPStartCall(SIPCall& call, const dhtnet::IpAddr& target);
669
673 void onTrackedBuddyOffline(const dht::InfoHash&);
674
678 void onTrackedBuddyOnline(const dht::InfoHash&);
679
683 void registerAsyncOps();
687 void onPortMappingAdded(uint16_t port_used, bool success);
688 void forEachPendingCall(const DeviceId& deviceId,
689 const std::function<void(const std::shared_ptr<SIPCall>&)>& cb);
690
691 void loadAccountFromDHT(const std::string& archive_password, const std::string& archive_pin);
692 void loadAccount(const std::string& archive_password_scheme = {},
693 const std::string& archive_password = {},
694 const std::string& archive_pin = {},
695 const std::string& archive_path = {});
696
697 std::vector<std::string> loadBootstrap() const;
698
699 static std::pair<std::string, std::string> saveIdentity(const dht::crypto::Identity id,
700 const std::filesystem::path& path,
701 const std::string& name);
702
703 void replyToIncomingIceMsg(const std::shared_ptr<SIPCall>&,
704 const std::shared_ptr<IceTransport>&,
705 const std::shared_ptr<IceTransport>&,
706 const dht::IceCandidates&,
707 const std::shared_ptr<dht::crypto::Certificate>& from_cert,
708 const dht::InfoHash& from);
709
710 void loadCachedUrl(const std::string& url,
711 const std::filesystem::path& cachePath,
712 const std::chrono::seconds& cacheDuration,
713 std::function<void(const dht::http::Response& response)>);
714
715 std::string getDhtProxyServer(const std::string& serverList);
716 void loadCachedProxyServer(std::function<void(const std::string&)> cb);
717
721 void generateDhParams();
722
723 void newOutgoingCallHelper(const std::shared_ptr<SIPCall>& call, const Uri& uri);
724 std::shared_ptr<SIPCall> newSwarmOutgoingCallHelper(
725 const Uri& uri, const std::vector<libjami::MediaMap>& mediaList);
726 std::shared_ptr<SIPCall> createSubCall(const std::shared_ptr<SIPCall>& mainCall);
727
728 std::filesystem::path cachePath_ {};
729 std::filesystem::path dataPath_ {};
730
731#if HAVE_RINGNS
732 mutable std::mutex registeredNameMutex_;
733 std::string registeredName_;
734
735 bool setRegisteredName(const std::string& name)
736 {
737 std::lock_guard<std::mutex> lock(registeredNameMutex_);
738 if (registeredName_ != name) {
739 registeredName_ = name;
740 return true;
741 }
742 return false;
743 }
744 std::string getRegisteredName() const
745 {
746 std::lock_guard<std::mutex> lock(registeredNameMutex_);
747 return registeredName_;
748 }
749#endif
750 std::shared_ptr<dht::Logger> logger_;
751 std::shared_ptr<dhtnet::tls::CertificateStore> certStore_;
752
753 std::shared_ptr<dht::DhtRunner> dht_ {};
754 std::shared_ptr<AccountManager> accountManager_;
755 dht::crypto::Identity id_ {};
756
757 mutable std::mutex messageMutex_ {};
758 std::map<dht::Value::Id, PendingMessage> sentMessages_;
759 dhtnet::fileutils::IdList treatedMessages_;
760
761 /* tracked buddies presence */
762 mutable std::mutex buddyInfoMtx;
763 std::map<dht::InfoHash, BuddyInfo> trackedBuddies_;
764
765 mutable std::mutex dhtValuesMtx_;
766
767 std::atomic_int syncCnt_ {0};
768
774 in_port_t dhtPortUsed()
775 {
776 return (upnpCtrl_ and dhtUpnpMapping_.isValid()) ? dhtUpnpMapping_.getExternalPort()
777 : config().dhtPort;
778 }
779
780 /* Current UPNP mapping */
781 dhtnet::upnp::Mapping dhtUpnpMapping_ {dhtnet::upnp::PortType::UDP};
782
786 std::string proxyServerCached_ {};
787
791 pjsip_host_port via_addr_ {};
792
793 pjsip_transport* via_tp_ {nullptr};
794
798 mutable std::shared_mutex connManagerMtx_ {};
799 std::unique_ptr<dhtnet::ConnectionManager> connectionManager_;
800
801 virtual void updateUpnpController() override;
802
803 std::mutex discoveryMapMtx_;
804 std::shared_ptr<dht::PeerDiscovery> peerDiscovery_;
805 std::map<dht::InfoHash, DiscoveredPeer> discoveredPeers_;
806 std::map<std::string, std::string> discoveredPeerMap_;
807
808 std::set<std::shared_ptr<dht::http::Request>> requests_;
809
810 mutable std::mutex sipConnsMtx_ {};
811 struct SipConnection
812 {
813 std::shared_ptr<SipTransport> transport;
814 // Needs to keep track of that channel to access underlying ICE
815 // information, as the SipTransport use a generic transport
816 std::shared_ptr<dhtnet::ChannelSocket> channel;
817 };
818 // NOTE: here we use a vector to avoid race conditions. In fact the contact
819 // can ask for a SIP channel when we are creating a new SIP Channel with this
820 // peer too.
821 std::map<SipConnectionKey, std::vector<SipConnection>> sipConns_;
822
823 std::mutex pendingCallsMutex_;
824 std::map<DeviceId, std::vector<std::shared_ptr<SIPCall>>> pendingCalls_;
825
826 std::mutex onConnectionClosedMtx_ {};
827 std::map<DeviceId, std::function<void(const DeviceId&, bool)>> onConnectionClosed_ {};
834 void callConnectionClosed(const DeviceId& deviceId, bool eraseDummy);
835
844 void requestSIPConnection(const std::string& peerId,
845 const DeviceId& deviceId,
846 const std::string& connectionType,
847 bool forceNewConnection = false,
848 const std::shared_ptr<SIPCall>& pc = {});
855 void cacheSIPConnection(std::shared_ptr<dhtnet::ChannelSocket>&& channel,
856 const std::string& peerId,
857 const DeviceId& deviceId);
864 void shutdownSIPConnection(const std::shared_ptr<dhtnet::ChannelSocket>& channel,
865 const std::string& peerId,
866 const DeviceId& deviceId);
867
868 void requestMessageConnection(const std::string& peerId,
869 const DeviceId& deviceId,
870 const std::string& connectionType);
871
872 // File transfers
873 std::mutex transfersMtx_ {};
874 std::set<std::string> incomingFileTransfers_ {};
875
887 bool sendSIPMessage(SipConnection& conn,
888 const std::string& to,
889 void* ctx,
890 uint64_t token,
891 const std::map<std::string, std::string>& data,
893 void onMessageSent(const std::string& to, uint64_t id, const std::string& deviceId, bool success, bool onlyConnected, bool retry);
894
895 std::mutex gitServersMtx_ {};
896 std::map<dht::Value::Id, std::unique_ptr<GitServer>> gitServers_ {};
897
899 std::shared_ptr<TransferManager> nonSwarmTransferManager_;
900
901 std::atomic_bool deviceAnnounced_ {false};
902 std::atomic_bool noSha3sumVerification_ {false};
903
904 bool publishPresence_ {true};
905
906 std::map<Uri::Scheme, std::unique_ptr<ChannelHandlerInterface>> channelHandlers_ {};
907
908 std::unique_ptr<ConversationModule> convModule_;
909 std::mutex moduleMtx_;
910 std::unique_ptr<SyncModule> syncModule_;
911
912 std::mutex rdvMtx_;
913
914 int dhtBoundPort_ {0};
915
916 void initConnectionManager();
917
918 enum class PresenceState : int { DISCONNECTED = 0, AVAILABLE, CONNECTED };
919 std::map<std::string, PresenceState> presenceState_;
920 std::string presenceNote_;
921};
922
923static inline std::ostream&
924operator<<(std::ostream& os, const JamiAccount& acc)
925{
926 os << "[Account " << acc.getAccountID() << "] ";
927 return os;
928}
929
930} // namespace jami
const std::string & getAccountID() const
Get the account ID.
Definition account.h:154
std::filesystem::path idPath_
path to account
Definition account.h:500
std::unique_ptr< AccountConfig > config_
Definition account.h:455
void editConfig(std::function< void(AccountConfig &config)> &&edit)
Definition account.h:121
const AccountConfig & config() const
Definition account.h:113
std::shared_ptr< dhtnet::upnp::Controller > upnpCtrl_
Definition account.h:511
Ring Account is build on top of SIPAccountBase and uses DHT to handle call connectivity.
Definition jamiaccount.h:96
dhtnet::IpAddr getPublishedIpAddress(uint16_t family=PF_UNSPEC) const override
void askForFileChannel(const std::string &conversationId, const std::string &deviceId, const std::string &interactionId, const std::string &fileId, size_t start=0, size_t end=0)
void forceReloadAccount()
Try to reload the account to force the identity to be updated.
std::optional< Contact > getContactInfo(const std::string &uri) const
void sendTrustRequest(const std::string &to, const std::vector< uint8_t > &payload)
bool isConnectedWith(const DeviceId &deviceId) const
Check if a Device is connected.
void addContact(const std::string &uri, bool confirmed=false)
Add contact to the account contact list.
static constexpr int ICE_STREAMS_COUNT
std::shared_ptr< Call > newOutgoingCall(std::string_view toUrl, const std::vector< libjami::MediaMap > &mediaList) override
Create outgoing SIPCall.
bool needToSendProfile(const std::string &peerUri, const std::string &deviceId, const std::string &sha3Sum)
Check (via the cache) if we need to send our profile to a specific device.
std::vector< std::map< std::string, std::string > > getConnectionList(const std::string &conversationId="")
bool provideAccountAuthentication(const std::string &credentialsFromUser, const std::string &scheme)
void sendPresenceNote(const std::string &note)
Send a presence note.
const JamiAccountConfig & config() const
std::map< std::string, std::string > getKnownDevices() const
void startAccountDiscovery()
Start Discovery the Jami Account from the Network.
std::vector< std::map< std::string, std::string > > getChannelList(const std::string &connectionId)
~JamiAccount() noexcept
bool discardTrustRequest(const std::string &from)
void declineConversationRequest(const std::string &conversationId)
void doRegister() override
Connect to the DHT.
std::string getContactHeader(const std::shared_ptr< SipTransport > &sipTransport)
Get the contact header for.
void unlinkConversations(const std::set< std::string > &removedConv)
Make sure appdata/contacts.yml contains correct information.
bool isSrtpEnabled() const override
static constexpr int ICE_COMP_COUNT_PER_STREAM
void sendProfile(const std::string &peerUri, const std::string &deviceId)
Send profile via cached SIP connection.
std::vector< std::string > getCertificatesByStatus(dhtnet::tls::TrustStore::PermissionStatus status)
void setRegistrationState(RegistrationState state, int detail_code=0, const std::string &detail_str={}) override
Set the registration state of the specified link.
void sendFile(const std::string &conversationId, const std::filesystem::path &path, const std::string &name, const std::string &replyTo)
bool setPushNotificationConfig(const std::map< std::string, std::string > &data) override
void pushNotificationReceived(const std::string &from, const std::map< std::string, std::string > &data)
To be called by clients with relevant data when a push notification is received.
virtual bool getSrtpFallback() const override
std::shared_ptr< dht::DhtRunner > dht()
JamiAccountConfig::Credentials consumeConfigCredentials()
std::shared_ptr< SIPCall > newIncomingCall(const std::string &from, const std::vector< libjami::MediaMap > &mediaList, const std::shared_ptr< SipTransport > &sipTr={}) override
Create incoming SIPCall.
bool changeArchivePassword(const std::string &password_old, const std::string &password_new)
std::shared_ptr< TransferManager > dataTransfer(const std::string &id="")
Retrieve linked transfer manager.
std::map< std::string, std::string > getNearbyPeers() const override
Get current discovered peers account id and display name.
bool exportArchive(const std::string &destinationPath, std::string_view scheme={}, const std::string &password={})
Export the archive to a file.
dhtnet::IceTransportOptions getIceOptions() const override
Create and return ICE options.
std::string getToUri(const std::string &username) const override
This method adds the correct scheme, hostname and append the ;transport= parameter at the end of the ...
void askForProfile(const std::string &conversationId, const std::string &deviceId, const std::string &memberUri)
void startAccountPublish()
Start Publish the Jami Account onto the Network.
void shutdownConnections()
This should be called before flushing the account.
static constexpr const std::pair< uint16_t, uint16_t > DHT_PORT_RANGE
Definition jamiaccount.h:99
bool setMessageDisplayed(const std::string &conversationUri, const std::string &messageId, int status) override
virtual bool isTlsEnabled() const override
Determine if TLS is enabled for this account.
SyncModule * syncModule()
std::vector< std::map< std::string, std::string > > getContacts(bool includeRemoved=false) const
void flush() override
This method is called to request removal of possible account traces on the system,...
std::shared_ptr< JamiAccount > shared()
const std::shared_ptr< AccountManager > & accountManager()
bool isMessageTreated(dht::Value::Id id)
MatchRank matches(std::string_view username, std::string_view hostname) const override
std::string getUserUri() const override
void doUnregister(bool forceShutdownConnections=false) override
Disconnect from the DHT.
bool acceptTrustRequest(const std::string &from, bool includeConversation=true)
bool cancelAddDevice(uint32_t op_token)
void sendProfile(const std::string &convId, const std::string &peerUri, const std::string &deviceId)
Send Profile via cached SIP connection.
std::string getFromUri() const override
ConversationModule * convModule(bool noCreation=false)
Used to get the instance of the ConversationModule class which is responsible for managing conversati...
bool revokeDevice(const std::string &device, std::string_view scheme={}, const std::string &password={})
bool isValidAccountDevice(const dht::crypto::Certificate &cert) const
std::filesystem::path profilePath() const
bool searchUser(const std::string &nameQuery)
const dht::crypto::Identity & identity() const
void sendInstantMessage(const std::string &convId, const std::map< std::string, std::string > &msg)
bool findCertificate(const std::string &id)
bool isPasswordValid(const std::string &password)
std::string getServerUri() const
In the current version, "srv" uri is obtained in the preformated way: hostname:port.
void connectivityChanged() override
Inform the account that the network status has changed.
bool handleMessage(const std::shared_ptr< dht::crypto::Certificate > &cert, const std::string &from, const std::pair< std::string, std::string > &message) override
void transferFile(const std::string &conversationId, const std::string &path, const std::string &deviceId, const std::string &fileId, const std::string &interactionId, size_t start=0, size_t end=0, const std::string &sha3Sum="", uint64_t lastWriteTime=0, std::function< void()> onFinished={})
std::string_view getAccountType() const override
void handleIncomingConversationCall(const std::string &callId, const std::string &destination)
Join incoming call to hosted conference.
std::vector< libjami::Message > getLastMessages(const uint64_t &base_timestamp) override
Get last messages (should be used to retrieve messages when launching the client)
std::map< std::string, bool > getTrackedBuddyPresence() const
Tells for each tracked account id if it has been seen online so far in the last DeviceAnnouncement::T...
bool setValidity(std::string_view scheme, const std::string &pwd, const dht::InfoHash &id, int64_t validity)
Change certificate's validity period.
void updateProfile(const std::string &displayName, const std::string &avatar, const std::string &fileType, int32_t flag) override
Update the profile vcard and send it to peers.
bool setPushNotificationToken(const std::string &pushDeviceToken="") override
bool confirmAddDevice(uint32_t op_token)
void editConfig(std::function< void(JamiAccountConfig &conf)> &&edit)
void removeContact(const std::string &uri, bool banned=true)
bool isMobile() const
The DRT component is composed on some special nodes, that are usually present but not connected.
bool sha3SumVerify() const
int32_t addDevice(const std::string &uriProvided)
Initiates the process of adding a new device to this account.
void sendMessage(const std::string &to, const std::string &deviceId, const std::map< std::string, std::string > &payloads, uint64_t id, bool retryOnTimeout=true, bool onlyConnected=false) override
bool setPushNotificationTopic(const std::string &topic) override
void saveConfig() const override
void setIsComposing(const std::string &conversationUri, bool isWriting) override
std::vector< std::map< std::string, std::string > > getTrustRequests() const
void forEachDevice(const dht::InfoHash &to, std::function< void(const std::shared_ptr< dht::crypto::PublicKey > &)> &&op, std::function< void(bool)> &&end={})
void loadConversation(const std::string &convId)
std::unique_ptr< AccountConfig > buildConfig() const override
bool setCertificateStatus(const std::string &cert_id, dhtnet::tls::TrustStore::PermissionStatus status)
std::weak_ptr< JamiAccount > weak()
void onTextMessage(const std::string &id, const std::string &from, const std::shared_ptr< dht::crypto::Certificate > &peerCert, const std::map< std::string, std::string > &payloads) override
void setActiveCodecs(const std::vector< unsigned > &list) override
Update both the codec order structure and the codec string used for SDP offer and configuration respe...
void clearProfileCache(const std::string &peerUri)
Clear sent profiles (because of a removed contact or new trust request)
static constexpr auto ACCOUNT_TYPE
Definition jamiaccount.h:98
void loadConfig() override
Load the settings in this account.
uint64_t sendTextMessage(const std::string &to, const std::string &deviceId, const std::map< std::string, std::string > &payloads, uint64_t refreshToken=0, bool onlyConnected=false) override
If supported, send a text message from this account.
std::weak_ptr< JamiAccount const > weak() const
std::shared_ptr< JamiAccount const > shared() const
std::vector< uint8_t > getPasswordKey(const std::string &password)
std::string_view currentDeviceId() const
std::map< std::string, std::string > getContactDetails(const std::string &uri) const
Obtain details about one account contact in serializable form.
virtual std::map< std::string, std::string > getVolatileAccountDetails() const override
Retrieve volatile details such as recent registration errors.
dhtnet::tls::CertificateStore & certStore() const
void trackBuddyPresence(const std::string &buddy_id, bool track)
Adds an account id to the list of accounts to track on the DHT for buddy presence.
Definition Address.h:25
FixedHash< 20 > h160
Definition FixedHash.h:494
h160 Address
An Ethereum address: 20 bytes.
Definition Address.h:29
RegistrationState
Contains all the Registration states for an account can be in.
dht::PkId DeviceId
std::pair< std::string, DeviceId > SipConnectionKey
Definition jamiaccount.h:88
void emitSignal(Args... args)
Definition ring_signal.h:64
static constexpr const char MIME_TYPE_IM_COMPOSING[]
Definition jamiaccount.h:90
static constexpr std::string_view ACCOUNT_TYPE_JAMI
std::chrono::steady_clock clock
Definition conference.h:186
static std::ostream & operator<<(std::ostream &os, const Account &acc)
Definition account.h:530
bool lookupName(const std::string &account, const std::string &nameserver, const std::string &name)
bool lookupAddress(const std::string &account, const std::string &nameserver, const std::string &address)
bool registerName(const std::string &account, const std::string &name, const std::string &scheme, const std::string &password)
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30
std::string deviceKey
Device push notification token.