A kapcsolatkezelés

Ez a rész bemutatja, hogyan találhat és hozzáadhat egy kapcsolatot a DHT-től a klienshez. A névkiszolgáló használatát nem magyarázzuk itt. Ha erről további részleteket szeretne, olvassa el Névkiszolgáló-protokoll.

A hálózaton való jelenléte

Jelentse be a jelenlétét a DHT-n

A jelenlét elég egyszerű a DHT-en bejelenteni. Valójában ez csak egy érték, amely tartalmazza a készülék hashét (lásd az előző szakasz, Fiókkezelő) a kulcs ujjlenyomatával megfelelő hashen. Tehát, ha a bf5f1e21d3eb2c1246946aa49d5dcf3e5b9cb1b9 eszközzel 62fbdff0ce86f368c7d3c2682539e5ba9e06404f számlával rendelkezünk, a következő meghatározott érték kerül küldésre a DHT-en:

/**
 * 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)
};

(Ez az érték a dht_.put(h, VALUE, dht::DoneCallback{}, {}, true);, mint állandó beállítást). Ha a készülék bejelentett, a készülék jelen van. Jelenleg nincs módja a DHT-n törölni vagy módosítani egy értéket (ez akkor történik, amikor az OpenDHT támogatja az ECC-t). Tehát a jelenlét mindig késedelmes (közvető késedelmes: lejárási idő/2, így 2min30 most).

Ha van kapcsolat, hívja fel.

Most, hogy jelen vagyunk a hálózaton, itt az ideje, hogy megtudjuk, van-e valaki jelen a DHT-n. Az előző szakaszban egyszerűen megteheti a fordított folyamatot. Ahhoz, hogy megtudjuk, van-e valaki jelen a DHT-n (pl. bf5f1e21d3eb2c1246946aa49d5dcf3e5b9cb1b9), meg kell kapnunk a bf5f1e21d3eb2c1246946aa49d5dcf3e5b9cb1b9 értéket, és le kell kérnünk a DeviceAnnouncement-t ezen a hash-en. A rendszerfolyamat kapcsolódó kódja a jamiaccount.cpp fájlban található:

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());
});

És ennyi.

Ügyfél nézőpontja

<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>

Ezek a fő API-k (application programming interface – alkalmazásprogramozási felület) az ügyfelek számára. A subscribeBuddy figyelni fogja a DHT-t, hogy észlelje a jelenlét változásait, és newBuddyNotification üzenetet küld, amikor új állapotot észlel:

  • A kliensnek küldött állapot most 0=offline (nem található eszköz a DHT-n), 1=dht_jelenlét (legalább egy eszköz található a DHT-n), 2=csatlakozva (TCP és SIP csatornával, tehát készen áll az adatcsere).

  • A lineStatus (sorÁllapot) a társ által küldött bármely egyéni állapotot tartalmazni fog (pl. Ebédidő!)

A publish (közzététel) egy egyéni jegyzet közzétételére szolgál (az status (állapot) a Jami-fiókoknál figyelmen kívül marad, a jegyzet tartalmazza az egyéni állapotot).

Az RFC3863 az állapot küldésére szolgál SIP-kapcsolaton keresztül.

Késő kérés

Küldj kérelmet

TEENDŐ hajók kérése

Végül, miután a bizalomkérés elkészült, a kérelmet a következő hash-re tolhatjuk: InfoHash("beutazási doboz:" + eszközId)

A daemonban a következő kódot használjuk:

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

Kérés meghozatalára

TEENDŐ

(Tartás/Blokkolás/Tárolás)

Daemon API

A barát jelenlétének nyomon követésének összes módja a PresenceManagerben található, például:

<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>

A megbízás iránti kérelmek és kapcsolattartások kezelésére használt összes módszer és jel a ConfigurationManager-ben található, például:

<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>

Ha néhány példát szeretne, ezeket a módszereket a LRC-ben a contactmodel.cpp-ben használják.