Transfer de fişiere
THIS PAGE IS DEPRECATED: READ File transfer
Cum să-l folosesc?
Android
Când vorbești cu cineva pe Android, ai posibilitatea de a trimite o imagine pe dispozitivul tău sau de a face o fotografie cu aceste butoane:
! [buttonuri de fișiere Android_c0674c9c7a8fed/Android_file_button.png)
Notă
When you send a file, the other has to accept it. At this moment you will see «awaiting peer»:
Cum funcţionează?
Cum funcţionează
Introducere
Jami este o aplicație distribuită și trebuie să funcționeze fără nicio conectivitate la internet. Deci, transferul de fișiere, de asemenea!
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.
Acum că linkul TCP bidirecțional este aici, următorul pas va fi să negociez un TLS 1.3 (în general un (TLS1.3) - ((DHE-FFDHE8192) - ((RSA-PSS-RSAE-SHA384) - ((AES-256-GCM) când scriu aceste linii) între Alice și Bob, apoi Alice va începe să transfere fișierul.
Prima parte va fi o mică intitulare pentru a descrie conținutul fișierului.
Procesul
Trimite un fişier
Se utilizează următoarea metodă:
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.
Primirea unui dosar
Aceeași structură este folosită pentru a primi fișiere, dar metoda se schimbă puțin:
Clasa
JamiAccount
este utilizată pentru a primi mesaje de la DHT, deoarece primul lucru primit va fi cererea DHT.Apoi, acest mesaj este transmis
DhtPeerConnector: onRequestMessage()
prin eventLoop.DhtPeerConnector::Impl::answerToRequest
va încerca să se conecteze la serverul TURN (dacă nu este conectat) și să inițieze transportul ICE. Această metodă va deschide 2 conexiuni de control la un server TURN (unul pentru a autoriza colegii IPv4, altul pentru colegii IPv6, datorită RFC 6156) dacă nu este deja deschis și va permite adreselor publice peer să se conecteze. Apoi, dacă SDP primită nu conține candidați ICE, va folosi TURN și va crea răspunsul SDP pentru a aștepta peerul. Dacă SDP conține candidați ICE, metoda va încerca să negocieze legătura (sau să se retragă pe TURN) și apoi să răspundă la SDP (cu candidați ICE sau nu).Odată ce link-urile sunt gata, ca și expeditorul, un link TLS este negociat și dat
PeerConnection
datIncomingFileTransfer
ca intrare.
Re- solicită un transfer de fișiere anterior
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.
Pentru a face acest lucru, dispozitivul va trimite un json cu tipul de mime: application/data-transfer-request+json
care conține conversation
(id conversației), interaction
(interacție legată), deviceId
dispozitivul care primește fișierul.
Însă trimiteul verifică dacă dispozitivul este un dispozitiv de la partenerul anunțat și dacă dispozitivul este membru al conversației și poate trimite fișierul printr-un transfer de fișiere clasic.
Receptorul poate accepta acum primul transfer de intrare, descărca fișierul și verifica că sha3sum este corect.
Schema
SDP trimis prin 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).
Dispozitive multiple
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.
Primul abordare
Prima abordare a fost să trimiteți o cerere prin DHT către toate dispozitivele și primele dispozitive care răspund primesc fișierul de transfer.
Abordarea actuală
Acum, încă trimitem o cerere la toate dispozitivele. Diferența este că toate dispozitivele vor avea notificarea pentru primirea unui fișier și pot accepta/refuza transferul.
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.
În data_transfer.cpp definim clasa OptimisticMetaOutgoingInfo care reprezintă viziunea optimistă de arătat clientului. Este optimistă deoarece dacă un contact acceptă un transfer pe un dispozitiv și refuză pe altele, această clasă va arăta transferul de fișiere în curs. Și va arăta o eroare doar dacă toate dispozitivele refuză transferul.
Această clasă este legată de SubOutgoingFileTransfer care reprezintă starea unui transfer cu un singur dispozitiv. Clienții vor avea posibilitatea de a arăta un sub-transfer în schimb optimistic mai târziu (vezi lista TODO).
Utilizând un alt 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 utilizator: parola -r „realm”
Then, you can configure the TURN server in the advanced settings of the app.
Notă
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?
Află starea subtransferurilor pentru fișierele ieșite