Gestion des contacts

Cette section présentera comment trouver et ajouter un contact du DHT au client. L’utilisation d’un serveur de noms ne sera pas expliquée ici. Si vous souhaitez plus de détails à ce sujet, veuillez lire Nom du protocole serveur.

Présence sur le réseau

Annoncez la présence sur le DHT

La présence est assez simple à annoncer sur le DHT. En fait, c’est juste une valeur contenant le hash du dispositif (voir la section précédente, Gestion du compte) sur le hash correspondant à l’empreinte digitale de la clé. Donc, si nous avons le compte bf5f1e21d3eb2c1246946aa49d5dcf3e5b9cb1b9 avec le dispositif 62fbdff0ce86f368c7d3c2682539e5ba9e06404f, la valeur définie suivante sera envoyée sur le DHT:

/**
 * Device announcement stored on DHT.
 */
struct DeviceAnnouncement : public dht::SignedValue<DeviceAnnouncement>
{
private:
    using BaseClass = dht::SignedValue<DeviceAnnouncement>;

public:
    static const constexpr dht::ValueType& TYPE = dht::ValueType::USER_DATA;
    dht::InfoHash dev;
    std::shared_ptr<dht::crypto::PublicKey> pk;
    MSGPACK_DEFINE_MAP(dev, pk)
};

(Cette valeur peut être mise avec dht_.put(h, VALUE, dht::DoneCallback{}, {}, true);, comme une mise permanente). Si l’appareil est annoncé, l’appareil est présent. Pour l’instant, il n’y a aucun moyen de supprimer ou de modifier une valeur sur le DHT (cela arrivera lorsque OpenDHT prendra en charge ECC).

Appelez si un contact est présent

Maintenant, notre présence sur le réseau, il est temps de savoir si quelqu’un est présent sur le DHT. Avec la section précédente, il est facile de faire le processus inverse. Pour savoir si quelqu’un est présent sur le DHT (ex: bf5f1e21d3eb2c1246946aa49d5dcf3e5b9c1b9), nous devons obtenir la valeur à bf5f1e21d3eb2c1246946aa49d5dcf3e5b9cb1b9 et récupérer le DeviceAnnonce sur ce hash. Le code connexe dans le daemon ring est dans ccount.cpp:

auto shared = std::static_pointer_cast<RingAccount>(shared_from_this());
auto treatedDevices = std::make_shared<std::set<dht::InfoHash>>();
dht_.get<dht::crypto::RevocationList>(to, [to](dht::crypto::RevocationList&& crl){
    tls::CertificateStore::instance().pinRevocationList(to.toString(), std::move(crl));
    return true;
});
dht_.get<DeviceAnnouncement>(to, [shared,to,treatedDevices,op](DeviceAnnouncement&& dev) {
    if (dev.from != to)
        return true;
    if (treatedDevices->emplace(dev.dev).second)
        op(shared, dev.dev);
    return true;
}, [=](bool /*ok*/){
    {
        std::lock_guard<std::recursive_mutex> lock(shared->buddyInfoMtx);
        auto buddy_info_it = shared->trackedBuddies_.find(to);
        if (buddy_info_it != shared->trackedBuddies_.end()) {
            if (not treatedDevices->empty()) {
                for (auto& device_id : *treatedDevices)
                    shared->onTrackedBuddyOnline(buddy_info_it, device_id);
            } else
                shared->onTrackedBuddyOffline(buddy_info_it);
        }
    }
    RING_DBG("[Account %s] found %lu devices for %s",
                getAccountID().c_str(), treatedDevices->size(), to.to_c_str());
    if (end) end(shared, not treatedDevices->empty());
});

And that’s all.

Perspective Client

<method name="subscribeBuddy" tp:name-for-bindings="subscribeBuddy">
    <tp:docstring>
        Ask be be notified when 'uri' presence change
    </tp:docstring>
    <tp:added version="1.3.0"/>
    <arg type="s" name="accountID" direction="in">
        <tp:docstring>
            An account from which get request presence informations
        </tp:docstring>
    </arg>
    <arg type="s" name="uri" direction="in">
        <tp:docstring>
            A SIP uri to watch
        </tp:docstring>
    </arg>
    <arg type="b" name="flag" direction="in">
        <tp:docstring>
        </tp:docstring>
    </arg>
</method>

<signal name="newBuddyNotification" tp:name-for-bindings="newBuddyNotification">
    <tp:added version="1.3.0"/>
    <tp:docstring>
        Notify when a registered presence uri presence informations changes
    </tp:docstring>
    <arg type="s" name="accountID">
        <tp:docstring>
            The associated account
        </tp:docstring>
    </arg>
    <arg type="s" name="buddyUri">
        <tp:docstring>
            The registered URI
        </tp:docstring>
    </arg>
    <arg type="i" name="status">
        <tp:docstring>
            Is the URI present or not
        </tp:docstring>
    </arg>
    <arg type="s" name="lineStatus">
        <tp:docstring>
            A string containing informations from the user (human readable)
        </tp:docstring>
    </arg>
</signal>

<method name="publish" tp:name-for-bindings="publish">
    <tp:added version="1.3.0"/>
    <arg type="s" name="accountID" direction="in">
        <tp:docstring>
            The account from which the presence will be emitted
        </tp:docstring>
    </arg>
    <arg type="b" name="status" direction="in">
        <tp:docstring>
            Is this account present or not
        </tp:docstring>
    </arg>
    <arg type="s" name="note" direction="in">
        <tp:docstring>
            A message transmitted by the server to other users
        </tp:docstring>
    </arg>
</method>

sont les principales API pour les clients. subscribeBuddy écoutera la DHT pour détecter les changements de présence et newBuddyNotification sera envoyé chaque fois qu’un nouveau statut est détecté :

  • Le statut envoyé au client est maintenant 0=offline (aucun appareil trouvé dans la DHT), 1=dht_presence (au moins un appareil est trouvé dans la DHT), 2=connected (avec un canal TCP + SIP, donc prêt à échanger des données).

  • lineStatus contiendra tout statut personnalisé envoyé par le pair (par exemple Lunch Time!)

publish est utilisé pour publier une note personnalisée (status est ignoré pour les comptes Jami, la note contiendra le statut personnalisé).

RFC3863 est utilisé pour envoyer le statut sur la connexion SIP.

Demande en attente

Envoyez une demande

** demande d’engin de TODO**

Enfin, une fois la demande de confiance formée, nous pouvons pousser la demande vers le hash suivant: InfoHash("inbox:" + deviceId)

Le code suivant est utilisé dans le daemon:

dht_.putEncrypted(dht::InfoHash::get("inbox:"+dev.toString()), dev, dht::TrustRequest(DHT_TYPE_NS, payload));

Réception d’une demande

A FAIRE

(Acceptation/blocage/démission)

API du démon

Toutes les méthodes pour suivre la présence d’un ami se trouvent dans le PresenceManager tels que:

<signal name="newBuddyNotification" tp:name-for-bindings="newBuddyNotification">
    <tp:added version="1.3.0"/>
    <tp:docstring>
        Notify when a registered presence uri presence informations changes
    </tp:docstring>
    <arg type="s" name="accountID">
        <tp:docstring>
            The associated account
        </tp:docstring>
    </arg>
    <arg type="s" name="buddyUri">
        <tp:docstring>
            The registered URI
        </tp:docstring>
    </arg>
    <arg type="b" name="status">
        <tp:docstring>
            Is the URI present or not
        </tp:docstring>
    </arg>
    <arg type="s" name="lineStatus">
        <tp:docstring>
            A string containing informations from the user (human readable)
        </tp:docstring>
    </arg>
</signal>

Toutes les méthodes et signaux utilisés pour gérer les demandes de confiance et les contacts sont dans le ConfigurationManager tels que:

<method name="getTrustRequests" tp:name-for-bindings="getTrustRequests">
    <tp:added version="2.2.0"/>
    <arg type="s" name="accountID" direction="in">
    </arg>
    <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="VectorMapStringString"/>
    <arg type="aa{ss}" name="requests" direction="out" >
        <tp:docstring>
            A list of contact request details. Details:
            - from: account ID of sender
            - received: UNIX timestamp of reception date
            - payload: attached payload
        </tp:docstring>
    </arg>
</method>

<method name="acceptTrustRequest" tp:name-for-bindings="acceptTrustRequest">
    <tp:added version="2.2.0"/>
    <arg type="s" name="accountID" direction="in">
    </arg>
    <arg type="s" name="from" direction="in">
    </arg>
    <arg type="b" name="success" direction="out" tp:type="Boolean">
        <tp:docstring>
            True if the operation succeeded.
        </tp:docstring>
    </arg>
</method>

<method name="discardTrustRequest" tp:name-for-bindings="discardTrustRequest">
    <tp:added version="2.2.0"/>
    <arg type="s" name="accountID" direction="in">
    </arg>
    <arg type="s" name="from" direction="in">
    </arg>
    <arg type="b" name="success" direction="out" tp:type="Boolean">
        <tp:docstring>
            True if the operation succeeded.
        </tp:docstring>
    </arg>
</method>

<signal name="incomingTrustRequest" tp:name-for-bindings="incomingTrustRequest">
    <tp:added version="2.2.0"/>
    <tp:docstring>
        Notify clients that a new contact request has been received.
    </tp:docstring>
    <arg type="s" name="accountID">
    </arg>
    <arg type="s" name="from">
    </arg>
    <arg type="ay" name="payload">
    </arg>
    <arg type="t" name="receiveTime">
    </arg>
</signal>

<method name="sendTrustRequest" tp:name-for-bindings="sendTrustRequest">
    <tp:added version="2.2.0"/>
    <arg type="s" name="accountID" direction="in">
    </arg>
    <arg type="s" name="to" direction="in">
    </arg>
    <arg type="ay" name="payload" direction="in">
    </arg>
</method>

<method name="addContact" tp:name-for-bindings="addContact">
    <tp:added version="3.0.0"/>
    <arg type="s" name="accountID" direction="in">
    </arg>
    <arg type="s" name="uri" direction="in">
    </arg>
</method>

<method name="removeContact" tp:name-for-bindings="removeContact">
    <tp:added version="3.0.0"/>
    <arg type="s" name="accountID" direction="in">
    </arg>
    <arg type="s" name="uri" direction="in">
    </arg>
    <arg type="b" name="ban" direction="in" tp:type="Boolean">
        <tp:docstring>
            True if the the contact should be banned.
            If false, the contact is removed from the contact list (banned or not).
        </tp:docstring>
    </arg>
</method>

Si vous voulez des exemples, ces méthodes sont utilisées dans contactmodel.cpp dans LRC.