From 8ff06928093e875af45bed95dc60e79cb1bedd4c Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 31 Dec 2013 15:26:42 +0100 Subject: [PATCH] Network remote: send md5 hash along with library and files. --- ext/libclementine-remote/remotecontrolmessages.proto | 4 +++- src/networkremote/outgoingdatacreator.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ext/libclementine-remote/remotecontrolmessages.proto b/ext/libclementine-remote/remotecontrolmessages.proto index 5501402ca..2d0ee7433 100644 --- a/ext/libclementine-remote/remotecontrolmessages.proto +++ b/ext/libclementine-remote/remotecontrolmessages.proto @@ -257,6 +257,7 @@ message ResponseSongFileChunk { optional SongMetadata song_metadata = 6; // only sent with first chunk! optional bytes data = 7; optional int32 size = 8; + optional bytes file_hash = 9; } message ResponseLibraryChunk { @@ -264,6 +265,7 @@ message ResponseLibraryChunk { optional int32 chunk_count = 2; optional bytes data = 3; optional int32 size = 4; + optional bytes file_hash = 5; } message ResponseSongOffer { @@ -276,7 +278,7 @@ message RequestRateSong { // The message itself message Message { - optional int32 version = 1 [default=13]; + optional int32 version = 1 [default=14]; optional MsgType type = 2 [default=UNKNOWN]; // What data is in the message? optional RequestConnect request_connect = 21; diff --git a/src/networkremote/outgoingdatacreator.cpp b/src/networkremote/outgoingdatacreator.cpp index 0c1fab7e6..f17620cb1 100644 --- a/src/networkremote/outgoingdatacreator.cpp +++ b/src/networkremote/outgoingdatacreator.cpp @@ -641,6 +641,11 @@ void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song, // Open the file QFile file(song.url().toLocalFile()); + + // Get md5 for file + QByteArray md5 = Utilities::Md5File(file).toHex(); + qLog(Debug) << "md5 for file" << song.url().toLocalFile() << "=" << md5; + file.open(QIODevice::ReadOnly); QByteArray data; @@ -665,6 +670,7 @@ void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song, chunk->set_file_number(song_no); chunk->set_size(file.size()); chunk->set_data(data.data(), data.size()); + chunk->set_file_hash(md5.data(), md5.size()); // On the first chunk send the metadata, so the client knows // what file it receives. @@ -746,6 +752,11 @@ void OutgoingDataCreator::SendLibrary(RemoteClient *client) { // Open the file QFile file(temp_file_name); + + // Get the md5 hash + QByteArray md5 = Utilities::Md5File(file).toHex(); + qLog(Debug) << "Library md5" << md5; + file.open(QIODevice::ReadOnly); QByteArray data; @@ -766,6 +777,7 @@ void OutgoingDataCreator::SendLibrary(RemoteClient *client) { chunk->set_chunk_number(chunk_number); chunk->set_size(file.size()); chunk->set_data(data.data(), data.size()); + chunk->set_file_hash(md5.data(), md5.size()); // Send data directly to the client client->SendData(&msg);