Μεταφορά αρχείων

THIS PAGE IS DEPRECATED: READ File transfer

Πώς να το χρησιμοποιήσω;

Android

Όταν μιλάτε με κάποιον στο Android, έχετε τη δυνατότητα να στείλετε μια φωτογραφία στην συσκευή σας ή να τραβήξετε μια φωτογραφία με αυτά τα κουμπιά:

! Android_file_button

Σημείωση

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

! Android_waiting_peer

Πώς λειτουργεί;

Πώς λειτουργεί

Εισαγωγή

Η Jami είναι μια διανεμημένη εφαρμογή και πρέπει να λειτουργεί χωρίς καμία σύνδεση στο διαδίκτυο. Έτσι, η μεταφορά αρχείων επίσης! Βασικά, χρησιμοποιούμε την ίδια μέθοδο για τη μεταφορά αρχείων και τις κλήσεις, αλλά στο 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 σύνδεσμο, το επόμενο βήμα θα είναι να διαπραγματευτεί ένα TLS 1.3 (γενικά ένα (TLS1.3)-(DHE-FFDHE8192)-(RSA-PSS-RSAE-SHA384)-(AES-256-GCM) όταν γράφω αυτές τις γραμμές) μεταξύ Alice και Bob, τότε 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](εικόνες/μεταφορά αρχείων-tlssocketendpoint-diagram.png)

Αποκάλυψη αρχείου

Η ίδια δομή χρησιμοποιείται για να λαμβάνονται αρχεία, αλλά η μέθοδος αλλάζει λίγο:

  1. Η τάξη JamiAccount χρησιμοποιείται για να λαμβάνει μηνύματα από το DHT, επειδή το πρώτο πράγμα που θα λάβει θα είναι το αίτημα DHT.

  2. Στη συνέχεια, αυτό το μήνυμα δίνεται στον DhtPeerConnector: onRequestMessage() μέσω του eventLoop.

  3. Ο DhtPeerConnector::Impl::answerToRequest θα προσπαθήσει να συνδεθεί με τον διακομιστή TURN (αν δεν είναι συνδεδεμένος) και να αρχίσει την μεταφορά ICE. Αυτή η μέθοδος θα ανοίξει 2 συνδέσεις ελέγχου σε έναν διακομιστή TURN (ένα για να εξουσιοδοτήσει τους IPv4 peers, ένα άλλο για τους IPv6 peers, λόγω RFC 6156) αν δεν είναι ήδη ανοιχτό και θα επιτρέψει στους Peer δημόσιους διευθύνσεις να συνδεθούν. Στη συνέχεια, αν το SDP δεν περιέχει υποψηφίους ICE, θα χρησιμοποιήσει το TURN και θα δημιουργήσει την απάντηση SDP για να περιμένει τον peer.

  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.

Για να γίνει αυτό, η συσκευή θα στείλει ένα json με το είδος μμ: application/data-transfer-request+json που περιέχει conversation (id της συζήτησης), interaction (σχετική αλληλεπίδραση), deviceId τη συσκευή που λαμβάνει το αρχείο.

Ο αποστολέας ελέγχει τώρα αν η συσκευή είναι συσκευή από τον ανακοίνωτο ομολόγο και ότι η συσκευή είναι μέλος της συζήτησης, και μπορεί να στείλει το αρχείο μέσω κλασικής μεταφοράς αρχείων.

Ο δέκτης μπορεί τώρα να αποδεχθεί την πρώτη εισερχόμενη μεταφορά, να κατεβάσει το αρχείο και να επαληθεύσει ότι το sha3sum είναι σωστό.

Σχέδιο

[Σχέδιο: κύριο διάγραμμα σχεδίου]

ΣΔΠ που αποστέλλεται μέσω του 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 σε όλες τις συσκευές και οι πρώτες συσκευές που απαντούν να μεταφέρουν το αρχείο.

Συγχρονή προσέγγιση

Τώρα, εξακολουθούμε να στέλνουμε αίτηση σε όλες τις συσκευές. Η διαφορά είναι ότι όλες οι συσκευές θα έχουν την ειδοποίηση για την παραλαβή ενός αρχείου και μπορούν να αποδεχτούν/αρνούν τη μεταφορά.

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 που αντιπροσωπεύουν την κατάσταση μιας μεταφοράς με μια συσκευή.

Χρησιμοποιώντας άλλο διακομιστή 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 turnserver -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. Δείξτε την κατάσταση των υπομεταφορών για τα αρχεία που βγαίνουν