文件转移

THIS PAGE IS DEPRECATED: READ File transfer

如何使用它?

动态系统

在安卓上与某人交谈时,您可以通过这些按发送照片或拍照:

对于安卓文件的使用者,请联系我们.

備註

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

对于这些问题,我们需要注意:

怎么办?

如何运行

引言

贾米是一个分布式应用程序,并且必须没有任何互联网连接.所以,文件传输也是如此!基本上,我们使用相同的方法来执行文件传输和通话,但在TCP中.要总结它如何工作,我们可以想象一个情况,Alice (A) 想将文件传输给Bob (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.

现在,双向TCP链接已经到达,下一步将是在Alice和Bob之间谈判一个TLS 1.3 (通常是 (TLS1.3) - ((DHE-FFDHE8192) - ((RSA-PSS-RSAE-SHA384) - ((AES-256-GCM) 当我写这些行) 然后Alice将开始传输文件.

首先,将是一个小标题描述文件内容.

过程

发送文件

使用以下方法:

  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. 然后,通过事件Loop,将此消息传递给」PeerConnector:onRequestMessage() `.

  3. DhtPeerConnector::Impl::answerToRequest将尝试连接到TURN服务器 (如果没有连接) 并启动ICE运输.该方法将向TURN服务器开放2个控制连接 (一个用于授权IPv4同行,另一个用于IPv6同行,由于RFC 6156) 如果它还没有开放并允许Peer公开地址连接.然后,如果收到的SDP不包含ICE候选人,将使用TURN并构建SDP答案等同行.如果SDP包含ICE候选人,该方法将试图谈判链接 (或退出TURN) 然后回答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是正确的.

方案

图片/文件转移-主图图.png)

通过DHT发送SDP
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向所有设备发送请求,然后答复的第一个设备将传输文件. 这对你的联系人不利,因为他们不会知道哪个设备将接收将获得传输.

目前的方法

现在,我们仍然向所有设备发送请求. 区别是所有设备都会收到文件的通知,并且可以接受/拒绝传输.

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 类,这些类型代表客户端显示的乐观视图.它是乐观的,因为如果一个联系人接受一个设备上的传输,而拒绝其他设备,这个类别将显示正在进行的文件传输.并且它只会显示错误,如果所有设备拒绝传输.

这个类别与 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).

整体清单

  1. Use libtorrent?

  2. 显示出发文件的子转移状态