Chuyển tập tin
THIS PAGE IS DEPRECATED: READ File transfer
Làm thế nào để sử dụng nó?
Android
Khi bạn đang nói chuyện với ai đó trên Android, bạn có khả năng gửi một bức ảnh trên thiết bị của mình hoặc chụp ảnh với các nút này:
Ghi chú
When you send a file, the other has to accept it. At this moment you will see 'awaiting peer':
Làm thế nào nó hoạt động?
Làm thế nào nó hoạt động
Khởi đầu
Jami là một ứng dụng phân tán và phải hoạt động mà không cần kết nối internet. Vì vậy, chuyển tập tin cũng vậy! Về cơ bản, chúng tôi sử dụng cùng một phương pháp để thực hiện chuyển tập tin và cuộc gọi, nhưng trong TCP. Để tóm tắt cách nó hoạt động, chúng tôi có thể tưởng tượng một tình huống mà Alice (A) muốn chuyển tập tin đến 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.
Bây giờ khi liên kết TCP hai chiều ở đây, bước tiếp theo sẽ là đàm phán một TLS 1.3 (thường là (TLS1.3) - DHE-FFDHE8192) - RSA-PSS-RSAE-SHA384) - AES-256-GCM khi tôi viết những dòng này) giữa Alice và Bob, sau đó Alice sẽ bắt đầu chuyển tập tin.
Phần đầu tiên sẽ là một tiêu đề nhỏ để mô tả nội dung của tệp.
Quá trình
Gửi tập tin
Phương pháp sau đây được sử dụng:
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 areDataTransfer
,IncomingFileTransfer
,OutgoingFileTransfer
andSubOutgoingFileTransfer
). This method will ask the linkedJamiAccount
to request a connection.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 aClientConnector
(which manage the connection for one device) and launch theprocess()
method.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
).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 thePeerConnection
object as an output and the transfer can start.When the TLS socket is ready, the callback
DataTransferFacade::Impl::onConnectionRequestReply
is called, and aOutgoingFileTransfer
is linked to thePeerConnection
as an input. ThisOutgoingFileTransfer
contains a list ofSubOutgoingFileTransfer
(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).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.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 theDhtPeerConnector::eventLoop()
and the resources will be released.
Nhận một tập tin
Tương tự cấu trúc được sử dụng để nhận các tệp, nhưng phương pháp thay đổi một chút:
Hạng
JamiAccount
được sử dụng để nhận tin nhắn từ DHT, bởi vì điều đầu tiên được nhận là yêu cầu DHT.Sau đó, thông điệp này được gửi đến
DhtPeerConnector: onRequestMessage()
thông qua eventLoop.DhtPeerConnector::Impl::answerToRequest
sẽ cố gắng kết nối với máy chủ TURN (nếu không kết nối) và khởi tạo giao thông ICE. Phương pháp này sẽ mở 2 kết nối điều khiển với máy chủ TURN (một để ủy quyền cho các đồng nghiệp IPv4, một cho các đồng nghiệp IPv6, do RFC 6156) nếu nó chưa mở và cho phép địa chỉ công cộng của đồng nghiệp kết nối. Sau đó, nếu SDP nhận được không chứa các ứng viên ICE, sẽ sử dụng TURN và tạo câu trả lời SDP để chờ cho đồng nghiệp. Nếu SDP chứa các ứng viên ICE, phương pháp sẽ cố gắng đàm phán liên kết (hoặc quay lại trên TURN) và sau đó trả lời SDP (với các ứng viên ICE hoặc không).Khi các liên kết đã sẵn sàng, giống như người gửi, một liên kết TLS được đàm phán và được trao cho
PeerConnection
được trao choIncomingFileTransfer
như một đầu vào.
Cần lại chuyển giao tập tin trước đó
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.
Để làm điều này, thiết bị sẽ gửi một json với kiểu mime: application/data-transfer-request+json
chứa conversation
(id của cuộc trò chuyện), interaction
(interaction liên quan), deviceId
thiết bị nhận tệp.
Người gửi bây giờ kiểm tra xem thiết bị là một thiết bị từ người đồng nghiệp được công bố và thiết bị là một thành viên của cuộc trò chuyện, và có thể gửi tập tin thông qua một chuyển giao tập tin cổ điển.
Người nhận bây giờ có thể chấp nhận chuyển tiếp đầu tiên, tải xuống tệp và xác minh rằng số lượng sha3sum là chính xác.
Chương trình
! [Chương trình: sơ đồ chính](phần/phần chuyển-phần chuyển-chương trình chính.png)
SDP được gửi qua 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).
Các thiết bị đa dạng
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.
Cách tiếp cận đầu tiên
Cách tiếp cận đầu tiên là gửi yêu cầu thông qua DHT đến tất cả các thiết bị và các thiết bị đầu tiên trả lời nhận được tập tin để chuyển giao.
Phương pháp hiện tại
Bây giờ, chúng tôi vẫn gửi yêu cầu đến tất cả các thiết bị. Sự khác biệt là tất cả các thiết bị sẽ có thông báo nhận một tệp và có thể chấp nhận / từ chối chuyển giao. Phần lớn mã cho điều đó là trong 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.
Trong data_transfer.cpp chúng tôi xác định lớp OptimisticMetaOutgoingInfo đại diện cho quan điểm lạc quan để hiển thị cho khách hàng. Nó lạc quan bởi vì nếu một liên lạc chấp nhận chuyển giao trên một thiết bị và từ chối trên các thiết bị khác, lớp này sẽ hiển thị chuyển giao tập tin đang diễn ra. Và nó sẽ chỉ hiển thị lỗi nếu tất cả các thiết bị từ chối chuyển giao.
Các lớp này được liên kết với SubOutgoingFileTransfer đại diện cho trạng thái chuyển giao với một thiết bị. Khách hàng sẽ có khả năng hiển thị một chuyển giao phụ thay vì lạc quan sau đó (xem danh sách TODO).
Sử dụng máy chủ TURN khác
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 turnserver -a -v -n -u người dùng: mật khẩu -r "trung"
Then, you can configure the TURN server in the advanced settings of the app.
Ghi chú
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).
Danh sách TODO
Use libtorrent?
Hiển thị trạng thái chuyển nhượng phụ cho các tệp ra ngoài