ファイル転送

THIS PAGE IS DEPRECATED: READ File transfer

どうやって使うか?

Android

Androidで誰かと話しているとき,デバイスに写真を送信したり,

ダウンロード/アップলোড/d68472b2c2c7bfcc616b0c674c9c7a8fed/Android_file_buttons.png)

注釈

When you send a file, the other has to accept it. At this moment you will see 'awaiting peer':

オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・オンライン・ オンライン・オンライン・オンライン・ オンライン・オンライン・オンライン・ オンライン・ オンライン・ オンライン・オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・ オンライン・・・・・・ オンライン・ オンライン・・・・ オンライン・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・

どうなるの?

機能する仕組み

紹介

ファイル転送も同様です.基本的に,ファイル転送と通話を行うのに同じ方法を使用しますが,TCPではです.どのように機能するかをまとめると,アリス (A) がボブ (B) にファイル転送したいという状況を想像できます.

First, Alice will request a connection to Bob. To do that, Jami is using ICE (RFC 6544), a protocol used to negotiate links between peers. Alice will send, into an encrypted packet via the DHT the IP address of its device. So, when Bob receives the IP addresses of Alice, they will be able to negotiate a transport where Bob will be able to send packets to Alice. The negotiation can be successful, but if it fails, a TURN server will be used (the one configured into the settings) to perform the transfer. If the negotiation succeeds, Bob will send its IP addresses to Alice to perform the negotiation in the other direction. Note that the link is still not secure, so Bob will send the IP addresses through the DHT network in an encrypted message. If the second negotiation fails, the TURN will be used as a fallback.

この2方向の TCP リンクがここにあるので 次のステップは,Alice と Bob の間で TLS 1.3 (通常は (TLS1.3) - (DHE-FFDHE8192) - (RSA-PSS-RSAE-SHA384) - (AES-256-GCM) を交渉することになります.

ファイル内容を記述する小さなヘッダーが最初の部分になります. ボブが転送を承認した後,ファイル全体が送信されます.

プロセス

ファイルを送信する

次の方法を使用します.

  1. A client will call DataTransferFacade::sendFile(). DataTransferFacade is the class corresponding to the API exposed for the clients. It is used to manage a view of the file transfers (the corresponding classes are DataTransfer, IncomingFileTransfer, OutgoingFileTransfer and SubOutgoingFileTransfer). This method will ask the linked JamiAccount to request a connection. Diagram: DataTransfer class diagram

  2. The method DhtPeerConnector: requestConnection() is triggered and creates a connection between all connected devices of the peer (found on the DHT). DhtPeerConnector is used to manage the main event loop which manage connections. When a device is found, the event loop will create a ClientConnector (which manage the connection for one device) and launch the process() method.

  3. This method is used to initialize the ICE transport and put a PeerConnectionMsg (which contains the SDP message, see below) on the DHT and waits for a response (DhtPeerConnector::Impl::onResponseMsg).

  4. Then a response is received from the DHT, which contains public addresses of the peer device. We can now negotiate a TLS link (directly via ICE, or via TURN as a fallback). This TlsSocketEndpoint is given to the PeerConnection object as an output and the transfer can start.

  5. When the TLS socket is ready, the callback DataTransferFacade::Impl::onConnectionRequestReply is called, and a OutgoingFileTransfer is linked to the PeerConnection as an input. This OutgoingFileTransfer contains a list of SubOutgoingFileTransfer (one per device) where each sub transfer is a transfer to one device. We do that to be able to furnish the most optimistic view of the transfer (if a contact as 3 devices, where the contact cancel the transfer on one device, but accepted the transfer on the two others, the most advanced transfer will be shown).

  6. The SubOutgoingFileTransfer will first transfer the header of the file, wait the peer acceptance (A "GO\n" message on the socket) and then will send the file.

  7. If a cancel is received from the peer or the client or if the file transfer finish, the connection will be closed via a CANCEL message on the DhtPeerConnector::eventLoop() and the resources will be released.

画像/ファイル転送-tlssocketendpoint-diagram.png)

ファイルを受け取る

ファイルを受け取るのに同じ構造が使用されますが,方法は少し変わります.

  1. JamiAccount クラスで DHTからのメッセージが受信されます.最初に受信されるものは DHT 要求です.

  2. DhtPeerConnector: onRequestMessage() にこのメッセージが送られます.

  3. DhtPeerConnector::Impl::answerToRequestは,TURNサーバーに接続し,ICE輸送を初期化します.この方法は,TURNサーバーに2つの制御接続を開きます. (RFC 6156によるIPv6ピアへのアクセス) がまだ開いていない場合,Peeer公開アドレスが接続できます.その後,受信されたSDPにはICE候補者が含まれていない場合,TURNを使用して,SDPの答えを作成してピアを待つ.SDPにはICE候補者が含まれている場合,この方法はリンクを交渉し,SDPに返信します (またはICE候補者または否).

  4. リンクが準備ができると,送信者のように TLS リンクが交渉され, PeerConnection に入力として IncomingFileTransfer に与えられます.ファイルのヘッダが来られ,クライアントは転送を承認またはキャンセルすることができます.

ファイル転送を再申請する

As specified in Other mime types, the data-transfer interactions are now synced and stored into conversations. So, a device can easily detects if a file was downloaded or not. If not, it can asks all members in the conversation to transmits the file again.

このために,デバイスは,mime型の json を送信します: アプリケーション/データ転送要求+json ヽ (会話 id) を含む, インタラクション (関連インタラクション), デバイスId ファイルを受け取るデバイス.

送信者は,デバイスが発表されたピアからのデバイスであり,デバイスが会話のメンバーであることを確認し,従来のファイル転送を通じてファイルを送信することができます.

受信者は最初の受信転送を受け取り,ファイルをダウンロードして sha3sumが正しいかどうかを確認できます.

計画

図書:主図図

SDPはDHTで送信されました
0d04b932
7c33834e7cf944bf0e367b47
H6e6ca682 1 TCP 2130706431 2607:fad8:4:6:9eb6:d0ff:dead:c0de 50693 typ host tcptype passive
H6e6ca682 1 TCP 2130706431 2607:fad8:4:6:9eb6:d0ff:dead:c0de 9 typ host tcptype active
H42c1b577 1 TCP 2130706431 fe80::9eb6:d0ff:fee7:1412 50693 typ host tcptype passive
H42c1b577 1 TCP 2130706431 fe80::9eb6:d0ff:fee7:1412 9 typ host tcptype active
Hc0a8007e 1 TCP 2130706431 192.168.0.123 42751 typ host tcptype passive
Hc0a8007e 1 TCP 2130706431 192.168.0.123 9 typ host tcptype active
Sc0a8007e 1 TCP 1694498815 X.X.X.X 42751 typ srflx tcptype passive
Z.Z.Z.Z:YYYY
A.A.A.A:YYYY

Where 0d04b932 is the ufrag and 7c33834e7cf944bf0e367b47 the password of the ICE session. 2130706431 and 1694498815 are the priority of the candidates. 192.168.0.126 42751 typ host tcptype passive is a passive host candidate and 1694498815 X.X.X.X 42751 typ srflx tcptype passive a passive host reflecting the public IP address (mapped via UPnP for example).

多重装置

A user can link its account to several devices. So, we need to implement the transfer when a user send a file to a contact who have multiple devices linked to this account.

最初のアプローチ

最初のアプローチは,DHTを通じてすべてのデバイスに要求を送信し,応答する最初のデバイスはファイル転送をします.これはあなたの連絡先にとって悪い,なぜならどのデバイスが受信するか,転送を受け取るかわからないからです.

現在のアプローチ

ファイルを受け取る通知がすべてのデバイスに与えられ,転送を受け入れ/拒否することができます.そのコードの主要な部分は data_transfer.cppです.

Now (since https://review.jami.net/c/jami-daemon/+/9327), when a user send a file, it will request a PeerConnection with all peer devices. And for all connections, we attach a new input stream to have the ability to accept/refuse/cancel each transfer separately.

data_transfer.cpp では,クライアントに表示される楽観的なビューを表す OptimisticMetaOutgoingInfo クラスを定義します. それは楽観的なものです. 連絡先が1つのデバイスで転送を承認し,他のデバイスで拒否した場合,このクラスは進行中のファイル転送を表示します. そしてすべてのデバイスが転送を拒否した場合のみエラーを表示します.

このクラスは,一つのデバイスで転送の状態を表す SubOutgoingFileTransfer にリンクされています.クライアントは,後で楽観的な代わりにサブ転送を表示することができます (TODOリストを参照).

別のTURNサーバを使用する

Actually the default TURN server is turn.jami.net. But you can host your own TURN server. For example by running a coTURN server.

sudoターンサーバー -a -v -n -u ユーザー:パスワード -r "領域"

Then, you can configure the TURN server in the advanced settings of the app.

注釈

This needs some technical knowledge. Moreover, the TURN server should see the same IP address of your node as the destination node, or the peer connection will fail (because the authorization will be incorrect).

TODOリスト

  1. Use libtorrent?

  2. 出発ファイルへのサブ転送状態を表示