Przekazanie plików
THIS PAGE IS DEPRECATED: READ File transfer
Jak go użyć?
Android
Kiedy rozmawiasz z kimś na Androida, masz możliwość wysłania zdjęcia na urządzenie lub robienia zdjęcia za pomocą tych przycisków:
Informacja
When you send a file, the other has to accept it. At this moment you will see «awaiting peer»:
/ (Android_waiting_peer)
Jak to działa?
Jak to działa
Wprowadzenie
Jami jest rozproszoną aplikacją i musi działać bez żadnego połączenia internetowego. Więc transfer plików również! zasadniczo używamy tej samej metody do przeprowadzania transferu plików i połączeń, ale w TCP. Aby podsumować, jak to działa, możemy wyobrazić sobie sytuację, w której Alice (A) chce przenieść plik do Boba (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.
Teraz, gdy jest tu dwukierunkowy link TCP, następnym krokiem będzie negocjacja TLS 1.3 (zwykle (TLS1.3) - DHE-FFDHE8192) - RSA-PSS-RSAE-SHA384) - AES-256-GCM) między Alice a Bob, a potem Alice rozpocznie przenoszenie pliku.
Pierwsza część będzie małą nagłówką opisaną w treści pliku.
Proces
Wysyłanie pliku
Wykorzystuje się następującą 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.
Otrzymanie pliku
W przypadku przyjmowania plików używa się tej samej struktury, ale metoda się nieco zmienia:
Klasy
JamiAccount
są używane do otrzymywania wiadomości od DHT, ponieważ pierwszą rzeczą otrzymaną będzie wniosek DHT.Następnie przekazuje się to wiadomość do
DhtPeerConnector: onRequestMessage()
za pośrednictwem eventLoop.DhtPeerConnector::Impl::answerToRequest
będzie próbował połączyć się z serwerem TURN (jeśli nie jest połączony) i inicjować transport ICE. Ta metoda otworzy 2 połączenia kontrolne do serwera TURN (jedna do autoryzowania IPv4 peers, druga dla IPv6 peers, z powodu RFC 6156) jeśli nie jest już otwarta i umożliwi połączenie publicznych adresów Peer. Następnie, jeśli otrzymany SDP nie zawiera kandydatów ICE, użyje TURN i wypracuje odpowiedź SDP, aby poczekać na peer. Jeśli SDP zawiera kandydatów ICE, metoda będzie próbować negocjować połączenie (lub odwrócić się na TURN) i następnie odpowiedzieć na SDP (z kandydatami ICE czy nie).Po gotowości linków, podobnie jak odesłaniec, link TLS jest negocjowany i przekazany
PeerConnection
, przekazanyIncomingFileTransfer
jako wejście.
Powtórne żądanie poprzedniego przesyłania plików
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.
W celu tego urządzenie wysyła json z typem mime: application/data-transfer-request+json
zawierający conversation
(id rozmowy), interaction
(związane interakcje), deviceId
urządzenie otrzymujące plik.
Odesłaniec sprawdza, czy urządzenie jest urządzeniem ogłoszonego rówieśnika i czy urządzenie jest członkiem rozmowy, i może wysłać plik za pośrednictwem klasycznego przesyłania plików.
Odbiorca może teraz zaakceptować pierwszy przychodzący przekaz, pobrać plik i sprawdzić, czy sha3sum jest prawidłowy.
Wymóg
[Diagram: główny schemat diagram](obrazy/pływ plików-przekaz-główny schemat-diagram.png)
SDP wysłany przez 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).
Wykorzystywane w różnych urządzeniach
Użytkownik może powiązać swoje konto z kilkoma urządzeniami. Musimy więc zaimplementować transfer, gdy użytkownik wysyła plik do kontaktu, który ma wiele urządzeń powiązanych z tym kontem.
Pierwszy podejście
Pierwszym sposobem było wysłanie wniosku przez DHT do wszystkich urządzeń, a pierwsze urządzenia, które odpowiadają, otrzymują plik do przesyłania.
Obecny podejście
Wciąż wysyłamy wniosek do wszystkich urządzeń. Różnica jest taka, że wszystkie urządzenia będą miały powiadomienie o otrzymaniu pliku i mogą zaakceptować/odmówić przekazanie.
Teraz (od https://review.jami.net/c/jami-daemon/+/9327), gdy użytkownik wysyła plik, zażąda PeerConnection ze wszystkimi urządzeniami równorzędnymi. Dla wszystkich połączeń dołączamy nowy strumień wejściowy, aby mieć możliwość zaakceptowania/odrzucenia/anulowania każdego transferu osobno.
W data_transfer.cpp definiujemy klasę OptimisticMetaOutgoingInfo reprezentującą optymistyczny widok do pokazania klientowi. Jest optymistyczny, ponieważ jeśli kontakt przyjmuje transfer na jednym urządzeniu i odrzuca na innych, ta klasa wykaże trwający transfer plików.
Ta klasa jest powiązana z SubOutgoingFileTransfer które reprezentują stan przekazu z jednym urządzeniem. Klienci będą mogli wyświetlić subtransfer zamiast optymistycznego później (patrz lista TODO).
Korzystając z innego serwera 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 użytkownik: hasło -r „królestwo”
Następnie można skonfigurować serwer TURN w ustawieniach zaawansowanych aplikacji.
Informacja
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
Używać libtorrent?
Wyświetlać status podprzekazu dla plików wyjściowych