Trasferimento di file
THIS PAGE IS DEPRECATED: READ File transfer
Come usarlo?
Android
Quando parli con qualcuno su Android, hai la possibilità di inviare una foto sul tuo dispositivo o scattare una foto con questi pulsanti:
! [botoni di file di Android]
Nota
When you send a file, the other has to accept it. At this moment you will see “awaiting peer”:
Come funziona?
Come funziona
Introduzione
Jami è un’applicazione distribuita e deve funzionare senza alcuna connessione internet. Quindi, anche il trasferimento di file! in pratica, usiamo lo stesso metodo per eseguire il trasferimento di file e le chiamate, ma in TCP. Per riassumere come funziona, possiamo immaginare una situazione in cui Alice (A) vuole trasferire un file 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.
Ora che il collegamento TCP bidirezionale è qui, il passo successivo sarà quello di negoziare un TLS 1.3 (generalmente un (TLS1.3)-DHE-FFDHE8192)-RSA-PSS-RSAE-SHA384)-AES-256-GCM) quando scrivo queste righe) tra Alice e Bob, poi Alice inizierà a trasferire il file.
La prima parte sarà un piccolo intestazione per descrivere il contenuto del file.
Processo
Invio di un file
Si utilizza il seguente metodo:
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.
Ricezione di un file
La stessa struttura viene utilizzata per ricevere file, ma il metodo cambia un po”:
La classe
JamiAccount
viene utilizzata per ricevere i messaggi dal DHT, perché la prima cosa ricevuta sarà la richiesta DHT.In seguito, questo messaggio viene trasmesso a
DhtPeerConnector: onRequestMessage()
attraverso l’eventLoop.Il
DhtPeerConnector::Impl::answerToRequest
cercherà di connettersi al server TURN (se non collegato) e inizializzarà il trasporto ICE. Questo metodo aprirà 2 connessioni di controllo a un server TURN (uno per autorizzare i colleghi IPv4, un altro per i colleghi IPv6, a causa di RFC 6156) se non è già aperto e consentirà agli indirizzi pubblici Peer di connettersi. Quindi, se l’SDP ricevuto non contiene candidati ICE, utilizzerà il TURN e elaborerà la risposta SDP per aspettare il collegamento. Se l’SDP contiene i candidati ICE, il metodo cercherà di negoziare il collegamento (o di tornare indietro sul TURN) e quindi rispondere allo SDP (con i candidati ICE o meno).Una volta che i collegamenti sono pronti, come il mittente, un collegamento TLS viene negoziato e dato alla
PeerConnection
dato allaIncomingFileTransfer
come input.
Richiedere un trasferimento di file precedente
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.
Per questo, il dispositivo invierà un json con il tipo di mime: applicazione/chiesta di trasferimento dati+json
contenente conversazione
(id della conversazione), interazione
(interazione correlata), deviceId
il dispositivo che riceve il file.
Il mittente verifica ora se il dispositivo è un dispositivo del pari annunciato e che il dispositivo è un membro della conversazione, e può inviare il file tramite un trasferimento di file classico.
Il ricevitore può ora accettare il primo trasferimento in entrata, scaricare il file e verificare che la sha3sum sia corretta.
Schema
! [Diagramma: schema principale]
SDP inviato attraverso il 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).
Dispositivi multi
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.
Primo approccio
Il primo approccio era quello di inviare una richiesta attraverso il DHT a tutti i dispositivi e i primi dispositivi che rispondono ottengono il file da trasferire.
Approccio attuale
Ora, inviamo ancora una richiesta a tutti i dispositivi. La differenza è che tutti i dispositivi avranno la notifica per ricevere un file e possono accettare / rifiutare il trasferimento.
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.
In data_transfer.cpp definiamo la classe OptimisticMetaOutgoingInfo che rappresenta la vista ottimista da mostrare al cliente. È ottimista perché se un contatto accetta un trasferimento su un dispositivo e rifiuta su altri, questa classe mostrerà il trasferimento di file in corso. E mostrerà un errore solo se tutti i dispositivi rifiutano il trasferimento.
Questa classe è collegata a SubOutgoingFileTransfer che rappresentano lo stato di un trasferimento con un dispositivo. I clienti avranno la possibilità di mostrare un trasferimento sotto in seguito (vedi lista TODO).
Utilizzando un altro server 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 utente:password -r "realm"
Then, you can configure the TURN server in the advanced settings of the app.
Nota
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).
Lista TODO
Use libtorrent?
Mostra lo stato dei trasferimenti di sotto-connessione per i file in uscita