From 3674acec375325863640c8f42e05f529e491002a Mon Sep 17 00:00:00 2001 From: "V.G. Bulavintsev" Date: Sat, 23 Feb 2019 20:38:14 +0100 Subject: [PATCH 1/2] Stop old entries from being pushed back by gossip --- .../MetadataStore/OrmBindings/channel_node.py | 3 +++ Tribler/Core/Modules/MetadataStore/store.py | 10 ++++++++++ .../MetadataStore/test_channel_download.py | 2 +- .../MetadataStore/test_channel_metadata.py | 4 ++-- .../Core/Modules/MetadataStore/test_store.py | 13 +++++++++++-- .../1551110113002.mdblob.lz4 | Bin 0 -> 286 bytes .../1551110113006.mdblob.lz4 | Bin 0 -> 544 bytes .../1551110113007.mdblob.lz4 | Bin 0 -> 211 bytes .../1551110113009.mdblob.lz4 | Bin 0 -> 226 bytes .../000000000002.mdblob.lz4 | Bin 283 -> 0 bytes .../000000000006.mdblob.lz4 | Bin 538 -> 0 bytes .../000000000007.mdblob.lz4 | Bin 211 -> 0 bytes .../000000000009.mdblob.lz4 | Bin 223 -> 0 bytes .../Core/data/sample_channel/channel.mdblob | Bin 244 -> 244 bytes .../Core/data/sample_channel/channel.torrent | 2 +- .../Core/data/sample_channel/channel_upd.mdblob | Bin 244 -> 244 bytes .../data/sample_channel/channel_upd.torrent | 2 +- 17 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113002.mdblob.lz4 create mode 100644 Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113006.mdblob.lz4 create mode 100644 Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113007.mdblob.lz4 create mode 100644 Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113009.mdblob.lz4 delete mode 100644 Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000002.mdblob.lz4 delete mode 100644 Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000006.mdblob.lz4 delete mode 100644 Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000007.mdblob.lz4 delete mode 100644 Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000009.mdblob.lz4 diff --git a/Tribler/Core/Modules/MetadataStore/OrmBindings/channel_node.py b/Tribler/Core/Modules/MetadataStore/OrmBindings/channel_node.py index cb84b9bf3cf..5dd7a5c0cbd 100644 --- a/Tribler/Core/Modules/MetadataStore/OrmBindings/channel_node.py +++ b/Tribler/Core/Modules/MetadataStore/OrmBindings/channel_node.py @@ -93,6 +93,9 @@ def __init__(self, *args, **kwargs): if "id_" not in kwargs: kwargs["id_"] = self._clock.tick() + if "timestamp" not in kwargs: + kwargs["timestamp"] = kwargs["id_"] + if not private_key_override and not skip_key_check: # No key/signature given, sign with our own key. if ("signature" not in kwargs) and \ diff --git a/Tribler/Core/Modules/MetadataStore/store.py b/Tribler/Core/Modules/MetadataStore/store.py index c8ed6b2dfba..16a2207a83f 100644 --- a/Tribler/Core/Modules/MetadataStore/store.py +++ b/Tribler/Core/Modules/MetadataStore/store.py @@ -228,6 +228,16 @@ def process_payload(self, payload): return None, DELETED_METADATA else: return None, NO_ACTION + + # Get the corresponding channel from local database to see if we really need to update our + # local copy of the channel by comparing local version number with payload's timestamp + # This check is necessary to prevent other peers pushing deleted entries into the + # channels we subscribed to + # If local channel version is 0, we are still in preview mode and willing to collect everything. + channel = self.ChannelMetadata.get(public_key=payload.public_key, id_=payload.origin_id) + if channel and (channel.local_version != 0) and payload.timestamp <= channel.local_version: + return None, NO_ACTION + elif payload.metadata_type == REGULAR_TORRENT: return self.TorrentMetadata.from_payload(payload), UNKNOWN_TORRENT elif payload.metadata_type == CHANNEL_TORRENT: diff --git a/Tribler/Test/Core/Modules/MetadataStore/test_channel_download.py b/Tribler/Test/Core/Modules/MetadataStore/test_channel_download.py index 717716f8080..2c04b24f461 100644 --- a/Tribler/Test/Core/Modules/MetadataStore/test_channel_download.py +++ b/Tribler/Test/Core/Modules/MetadataStore/test_channel_download.py @@ -56,5 +56,5 @@ def test_channel_update_and_download(self): # There should be 4 torrents + 1 channel torrent channel2 = self.session.lm.mds.ChannelMetadata.get_channel_with_id(payload.public_key) self.assertEqual(5, len(list(self.session.lm.mds.TorrentMetadata.select()))) - self.assertEqual(9, channel2.timestamp) + self.assertEqual(1551110113009, channel2.timestamp) self.assertEqual(channel2.timestamp, channel2.local_version) diff --git a/Tribler/Test/Core/Modules/MetadataStore/test_channel_metadata.py b/Tribler/Test/Core/Modules/MetadataStore/test_channel_metadata.py index 3d631803373..c2a631ea96f 100644 --- a/Tribler/Test/Core/Modules/MetadataStore/test_channel_metadata.py +++ b/Tribler/Test/Core/Modules/MetadataStore/test_channel_metadata.py @@ -137,9 +137,9 @@ def test_process_channel_metadata_payload(self): # Check that we always take the latest version channel_metadata.timestamp -= 1 - self.assertEqual(channel_metadata.timestamp, 6) + self.assertEqual(channel_metadata.timestamp, 1551110113006) channel_metadata = self.mds.ChannelMetadata.process_channel_metadata_payload(payload) - self.assertEqual(channel_metadata.timestamp, 7) + self.assertEqual(channel_metadata.timestamp, 1551110113007) self.assertEqual(len(self.mds.ChannelMetadata.select()), 1) @db_session diff --git a/Tribler/Test/Core/Modules/MetadataStore/test_store.py b/Tribler/Test/Core/Modules/MetadataStore/test_store.py index 69b00868995..6047346ea91 100644 --- a/Tribler/Test/Core/Modules/MetadataStore/test_store.py +++ b/Tribler/Test/Core/Modules/MetadataStore/test_store.py @@ -50,7 +50,6 @@ def tearDown(self): self.mds.shutdown() yield super(TestMetadataStore, self).tearDown() - def test_store_clock(self): my_key = default_eccrypto.generate_key(u"curve25519") mds2 = MetadataStore(os.path.join(self.session_base_dir, 'test.db'), self.session_base_dir, my_key) @@ -146,7 +145,7 @@ def test_process_channel_dir(self): self.assertFalse(channel.contents_list) self.mds.process_channel_dir(self.CHANNEL_DIR, channel.public_key) self.assertEqual(len(channel.contents_list), 3) - self.assertEqual(channel.timestamp, 7) + self.assertEqual(channel.timestamp, 1551110113007) self.assertEqual(channel.local_version, channel.timestamp) @db_session @@ -182,6 +181,16 @@ def get_payloads(entity_class): self.assertEqual(UNKNOWN_CHANNEL, result[1]) self.assertEqual(node_dict['metadata_type'], result[0].to_dict()['metadata_type']) + @db_session + def test_process_payload_reject_old(self): + # Check there is no action if the processed payload has a timestamp that is less than the + # local_version of the corresponding local channel. (I.e. remote peer trying to push back a deleted entry) + channel = self.mds.ChannelMetadata(title='bla', version=123, local_version=12) + torrent = self.mds.TorrentMetadata(title='blabla', timestamp=11, origin_id=channel.id_) + payload = torrent._payload_class(**torrent.to_dict()) + torrent.delete() + self.assertEqual((None, NO_ACTION), self.mds.process_payload(payload)) + @db_session def test_get_num_channels_nodes(self): self.mds.ChannelMetadata(title='testchan', id_=0) diff --git a/Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113002.mdblob.lz4 b/Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113002.mdblob.lz4 new file mode 100644 index 0000000000000000000000000000000000000000..9acd9e714f72b70d3e86c410936c392f33cc5fcb GIT binary patch literal 286 zcmV+(0pb1xB25@TK)??H008tq0W1IjShB#2oXtK1qL@gt^J9Y`v@QZ3$GjBD08F(C zYt^27<}kR3Is^JhFw*@Si0004LC0+*U000620uTW5 zQ~Zh*qWbc4O}ib%_pjVso9gQySpWb407RI80982Zod5s;9(7`MZgh1mF*PnQG%aLh zb8B>Oa4lhNWHvM|X>)G?000R?L@z{EL@z=_0000dXmoUNIxjDDZ*p>FZgeg_0PsUD zV{dIbHaRvqFJW$OZ*^{CWiA@^!0|nc>@$mxRORb!LqF)Mo|=}yxLh80<@JnHs(s~) k%vls0vJ5PvXx$Mvix9c@M3B)V0u@xqToJqE0ssI20LS!h9{>OV literal 0 HcmV?d00001 diff --git a/Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113006.mdblob.lz4 b/Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113006.mdblob.lz4 new file mode 100644 index 0000000000000000000000000000000000000000..2d467c192ee2fbf1d682b6fe6f8553ce50634e7c GIT binary patch literal 544 zcmV+*0^j`vB25@TK)?zC008tq0W1IjShB#2oXtK1qL@gt^J9Y`v@QZ3$GjBD08F(C zYt^27<}kR3Is^JhFw*@Si0004LC0+*W000620uTW3 zq>$}7Vt8Cqr*!C-2K!He8b*$61poj54YEK008kf_V*mgE9!_azXml=5W-e4{WiCu< zc4=;BE<|NvWM45bI52Pk000G6X=G(@0000aXmoUNIxjC`bTKYra${&|c4aPaa%Va= zIW{>jVQy}3b#7y2FFikng;C;0hv72xunrIuNh}>pC)V*75-&14R8Qxqnyz_Pp>r6= z({Kp9GPkV!FhUldf=M^;)>$_m?hwrYhyVZp4-Wx26zmNF0}lc62JAR8G&D3fGBq(U zGdD9aF)%hWH#Z~zA`lM<0P_g|5p-p9bRcDJbaHthH8wagH8ubM00nje0q`;a7W~MD zIpzd5h_b|mpX}QRt~U;c&1&=!8lro%wu+>RKYq;js0Ux1;L3arXOB*H21S}DoR}2t zA#CJ_DkdNVD@}gCMjn0v^Y_6v+TgwF+z1 zo_yvrx$c6~Vqblx5ooOwijhjsG!g3z>4mD{5FNJ#ESN7nKZS)+;zozzGW4(x5EMx) z9ZM(H@fQ*=GCNdH=ct;lc~+rw7{}9a2)r`4to$%S7M_AhH}BS2Hy-W~%>erFwRKvp zwayh_$xcQ4dCmdZo4rS6A0Nn~`NF55nA2w5nEB!YK#5Sd`8yd`FAKCO>T5hl6%*C_ Nf_(t5)B^wj003@@UgQ7( literal 0 HcmV?d00001 diff --git a/Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113009.mdblob.lz4 b/Tribler/Test/Core/data/sample_channel/58b2c08b9ccd3e03a29848b3f3638320/1551110113009.mdblob.lz4 new file mode 100644 index 0000000000000000000000000000000000000000..b570f409d667a4a0cf7b1e8461bcfa223e5c5a98 GIT binary patch literal 226 zcmV<803H7XB25@TK)}-g008tq0W1IjShB#2oXtK1qL@gt^J9Y`v@QZ3$GjBD08F(C zYt^27<}kR3Is^JhFw*@Si0004LC0+*b000620uTW5 z1u-!;Ha9dkFf}weGc`FkIW;miH6j2a1oQ|1@K68{bY*jNAZ2cJa(N&!Fg7_c00005 zc4=f~ZvX%Q09_7swiM2Xlx2Bt{X$2~d}otgT^KjAqn&5~&Sc}7_XuvenEJ89uc&Z> c1Y6!^150j3Hpv94risjx3N}Nr4gdfE0NJTgfdBvi literal 0 HcmV?d00001 diff --git a/Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000002.mdblob.lz4 b/Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000002.mdblob.lz4 deleted file mode 100644 index 3328257a00d734ff1d0e425f1d7c13988e20075f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 283 zcmV+$0p$J!B25@TK)?(E008kf0W1Iji9UyIJqhr;hrg8rYdu~jUsmXU#g{e+2=Km5 zpfHvy?O za4lhNWHvM|X>)G?000U@Z*6dLWpi_7WB>pFCunqZa5^t9bZ>HUWo~pXKLGGUE@N+P zIyN~rIWJ*uZf|vNV`aYcSP>)-0{&>}xxbtY3x@#^@PXiozAL+2!u-b>qc!y6UsH3z hzH#WcCi(9(Enns~z-90?s)cv1F5ETUpb7v00017YY}x<- diff --git a/Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000006.mdblob.lz4 b/Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000006.mdblob.lz4 deleted file mode 100644 index 609cd7635d329d75403182d0c495974a25a8f3e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 538 zcmV+#0_FV#B25@TK)?n8008kf0W1Iji9UyIJqhr;hrg8rYdu~jUsmXU#g{e+2=Km5 zpfHvy?$}7 zVt8Cqr*!C-2K!He8b*$61poj54YEK008kf_V*mgE9!_azXml=5W-e4{WiCuj zVQy}3b#7y22_9IyWT9T~w{1I&etdWAE@7ry9(NkRaqL^O*3VDXl-B4oniu@J1a6)9 zuAq!s)vU0ib(u<}pF9t8h+d}*hyVZp4-Wx27X%6c0RjN=1vD}=F*7kaG%`3fIWagi zH8eFaHW>gi02)jP0P_g|5p-p9bRcDJbaHthF*hfd~%#P&#=vdW}nqnip1lb`_(L;f=)%UM62w=zqnRHV6ptzD=Mo zmMZTg$36zh>x5gc=nSyfToVvfDvIP(XFViMBLYpNWH1RHSiEGRUhlVUJB)sOckC`< zrdu9&8o+VvTeH^BPt}yx=rfuZ{J8{fo%pVxj9S&Ku%mUEN~E7W4|0fJrwp1GnpiHX zlhz9;MN`n#EYfMub^~?v_7OId5f0@cnJ7fLr%Vt%tCBs<1qOu`$pm$8ggoAs_@|@s NR)p)cQw#tA007|NU5o$# diff --git a/Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000009.mdblob.lz4 b/Tribler/Test/Core/data/sample_channel/893e876d3d09f0bb87bf95036b3d5e26/000000000009.mdblob.lz4 deleted file mode 100644 index d45aab1689853f014541cbf5a11c8c9a98b6cb73..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 223 zcmV<503iPaB25@TK)}!d008kf0W1Iji9UyIJqhr;hrg8rYdu~jUsmXU#g{e+2=Km5 zpfHvy??=ctM zX8S=p0H!pig#RIsJ+a=@;i0X1QPl@E^*QMRY*$NBzJr^hJIY;NKDE%h l^=I0QDYlolOC)_!yX&6u(cbdSrjl!tqVriU+Awpm0RZTlO|bv~ delta 200 zcmeyu_=T~aaRLKFr(JulE$4^b?fa)PXWPc9#fQD9KRVrvgX6mNikr+4%jn-FNK;eJRWIRn0sy6{KI#vs{fpT zDUAt|umG|r)|)yM87iIi|D)ty@GvIrZRgk5v!`UeH{EXO@b0{&{_`l&-`4J>^WG}V f+}fOQ>%!OIN6gvZogZ{HtUG`3c99jQm@Ov&r6Ntc diff --git a/Tribler/Test/Core/data/sample_channel/channel.torrent b/Tribler/Test/Core/data/sample_channel/channel.torrent index 0e751ae3caf..6a1eb3a3881 100644 --- a/Tribler/Test/Core/data/sample_channel/channel.torrent +++ b/Tribler/Test/Core/data/sample_channel/channel.torrent @@ -1 +1 @@ -d13:creation datei1548884024e4:infod5:filesld6:lengthi538e4:pathl23:000000000006.mdblob.lz4eed6:lengthi283e4:pathl23:000000000002.mdblob.lz4eed6:lengthi211e4:pathl23:000000000007.mdblob.lz4eee4:name32:893e876d3d09f0bb87bf95036b3d5e2612:piece lengthi16384e6:pieces20: ' kٷ{{75ee \ No newline at end of file +d13:creation datei1551110113e4:infod5:filesld6:lengthi544e4:pathl24:1551110113006.mdblob.lz4eed6:lengthi211e4:pathl24:1551110113007.mdblob.lz4eed6:lengthi286e4:pathl24:1551110113002.mdblob.lz4eee4:name32:58b2c08b9ccd3e03a29848b3f363832012:piece lengthi16384e6:pieces20:'bgabJ'zYa6iee \ No newline at end of file diff --git a/Tribler/Test/Core/data/sample_channel/channel_upd.mdblob b/Tribler/Test/Core/data/sample_channel/channel_upd.mdblob index 5b252817503e977b572a6089ddd28f3e7242f11a..053079e91172dde474e92954ad625736084852f3 100644 GIT binary patch delta 200 zcmeyu_=T~aaRLKF#HIt?bI#f^FPh=8`Ezo!!WKOyx#N38PBQpx<;uP~ujZNY&Ua0h zlj3Wa31+Mn?waUz-bC;<&&$?T4+Uhmv+B%XzyOSys&Q-|>uiGiW}bEw?EbVlUf=kzi>A(QquUo(_bP-e l+LFCdF0)!_p4zie@zcD`zXNl%FU=`SUGTZnImUE569DcUP;dYM delta 200 zcmeyu_=T~aaRLKFr(JulE$4^b?fa)PXWPc9#fQD9KRVrvgX6mNikr+4mg+W*_YecUb*(spLL>Ke|!YR_UlfE zDUAt|umG|r)|)!~l*8GnW ff{rO`9DG*o>+X?L79P3(0%!lcVE diff --git a/Tribler/Test/Core/data/sample_channel/channel_upd.torrent b/Tribler/Test/Core/data/sample_channel/channel_upd.torrent index b72fc4d5a25..2a91d703d33 100644 --- a/Tribler/Test/Core/data/sample_channel/channel_upd.torrent +++ b/Tribler/Test/Core/data/sample_channel/channel_upd.torrent @@ -1 +1 @@ -d13:creation datei1548884024e4:infod5:filesld6:lengthi538e4:pathl23:000000000006.mdblob.lz4eed6:lengthi283e4:pathl23:000000000002.mdblob.lz4eed6:lengthi223e4:pathl23:000000000009.mdblob.lz4eed6:lengthi211e4:pathl23:000000000007.mdblob.lz4eee4:name32:893e876d3d09f0bb87bf95036b3d5e2612:piece lengthi16384e6:pieces20:ESzNI"ee \ No newline at end of file +d13:creation datei1551110113e4:infod5:filesld6:lengthi544e4:pathl24:1551110113006.mdblob.lz4eed6:lengthi226e4:pathl24:1551110113009.mdblob.lz4eed6:lengthi211e4:pathl24:1551110113007.mdblob.lz4eed6:lengthi286e4:pathl24:1551110113002.mdblob.lz4eee4:name32:58b2c08b9ccd3e03a29848b3f363832012:piece lengthi16384e6:pieces20:"86 ;GHFQѮMee \ No newline at end of file From b9f606aff76916b1f47b1ce7b1bab24b4e9b5e77 Mon Sep 17 00:00:00 2001 From: "V.G. Bulavintsev" Date: Tue, 26 Feb 2019 14:08:51 +0100 Subject: [PATCH 2/2] streamline process_payload and remove update_channel --- Tribler/Core/Modules/MetadataStore/store.py | 53 ++++++------------- .../Modules/restapi/downloads_endpoint.py | 5 +- .../Core/Modules/MetadataStore/test_store.py | 2 +- .../RestApi/test_downloads_endpoint.py | 2 +- 4 files changed, 20 insertions(+), 42 deletions(-) diff --git a/Tribler/Core/Modules/MetadataStore/store.py b/Tribler/Core/Modules/MetadataStore/store.py index 16a2207a83f..a4ecad2db9a 100644 --- a/Tribler/Core/Modules/MetadataStore/store.py +++ b/Tribler/Core/Modules/MetadataStore/store.py @@ -216,8 +216,6 @@ def process_squashed_mdblob(self, chunk_data): # Can't use db_session wrapper here, performance drops 10 times! Pony bug! def process_payload(self, payload): with db_session: - if self.ChannelNode.exists(signature=payload.signature): - return None, GOT_SAME_VERSION if payload.metadata_type == DELETED: # We only allow people to delete their own entries, thus PKs must match @@ -229,53 +227,32 @@ def process_payload(self, payload): else: return None, NO_ACTION + # Check if we already got an older version of the same node that we can update + # TODO: optimize this with a single UPSERT-style query + local_node = self.ChannelNode.get(public_key=payload.public_key, id_=payload.id_) + if local_node: + if local_node.timestamp < payload.timestamp: + local_node.set(**payload.to_dict()) + return local_node, UPDATED_OUR_VERSION + elif local_node.timestamp > payload.timestamp: + return local_node, GOT_NEWER_VERSION + return local_node, GOT_SAME_VERSION + # Get the corresponding channel from local database to see if we really need to update our - # local copy of the channel by comparing local version number with payload's timestamp + # local contents of the channel by comparing the channel's local_version with the payload's timestamp. # This check is necessary to prevent other peers pushing deleted entries into the - # channels we subscribed to + # channels we are subscribed to. # If local channel version is 0, we are still in preview mode and willing to collect everything. channel = self.ChannelMetadata.get(public_key=payload.public_key, id_=payload.origin_id) - if channel and (channel.local_version != 0) and payload.timestamp <= channel.local_version: + if channel and (channel.local_version != 0) and (payload.timestamp <= channel.local_version): return None, NO_ACTION - elif payload.metadata_type == REGULAR_TORRENT: return self.TorrentMetadata.from_payload(payload), UNKNOWN_TORRENT elif payload.metadata_type == CHANNEL_TORRENT: - return self.update_channel_info(payload) + return self.ChannelMetadata.from_payload(payload), UNKNOWN_CHANNEL return None, NO_ACTION - @db_session - def update_channel_info(self, payload): - """ - We received some channel metadata, possibly over the network. - Validate the signature, update the local metadata store and put in at the beginning of the download queue - if necessary. - :param payload: The channel metadata, in serialized form. - :returns (metadata, status): tuple consisting of possibly newer metadata and result status - """ - - channel = self.ChannelMetadata.get_channel_with_id(payload.public_key) - if channel: - if payload.timestamp > channel.timestamp: - # Update the channel that is already there. - self._logger.info("Updating channel metadata %s ts %s->%s", str(channel.public_key).encode("hex"), - str(channel.timestamp), str(payload.timestamp)) - channel.set(**ChannelMetadataPayload.to_dict(payload)) - status = UPDATED_OUR_VERSION - elif payload.timestamp == channel.timestamp: - status = GOT_SAME_VERSION - else: - status = GOT_NEWER_VERSION - - else: - status = UNKNOWN_CHANNEL - # Add new channel object to DB - channel = self.ChannelMetadata.from_payload(payload) - - #TODO: handle the case where the local version is the same as the new one and is not seeded - return channel, status - @db_session def get_my_channel(self): return self.ChannelMetadata.get_channel_with_id(self.my_key.pub().key_to_bin()[10:]) diff --git a/Tribler/Core/Modules/restapi/downloads_endpoint.py b/Tribler/Core/Modules/restapi/downloads_endpoint.py index f49a75357c5..96d6e82dc14 100644 --- a/Tribler/Core/Modules/restapi/downloads_endpoint.py +++ b/Tribler/Core/Modules/restapi/downloads_endpoint.py @@ -18,6 +18,7 @@ import Tribler.Core.Utilities.json_util as json from Tribler.Core.DownloadConfig import DownloadStartupConfig from Tribler.Core.Modules.MetadataStore.serialization import ChannelMetadataPayload +from Tribler.Core.Modules.MetadataStore.store import UNKNOWN_CHANNEL from Tribler.Core.Modules.restapi.util import return_handled_exception from Tribler.Core.Utilities.torrent_utils import get_info_from_handle from Tribler.Core.Utilities.utilities import unichar_string @@ -349,8 +350,8 @@ def on_error(error): return json.dumps({"error": "Metadata has invalid signature"}) with db_session: - channel, _ = self.session.lm.mds.process_payload(payload) - if channel and not channel.subscribed and channel.local_version < channel.timestamp: + channel, status = self.session.lm.mds.process_payload(payload) + if channel and not channel.subscribed and status == UNKNOWN_CHANNEL: channel.subscribed = True download, _ = self.session.lm.gigachannel_manager.download_channel(channel) else: diff --git a/Tribler/Test/Core/Modules/MetadataStore/test_store.py b/Tribler/Test/Core/Modules/MetadataStore/test_store.py index 6047346ea91..49e7b432897 100644 --- a/Tribler/Test/Core/Modules/MetadataStore/test_store.py +++ b/Tribler/Test/Core/Modules/MetadataStore/test_store.py @@ -158,7 +158,7 @@ def get_payloads(entity_class): _, node_payload, node_deleted_payload = get_payloads(self.mds.ChannelNode) - self.assertEqual((None, GOT_SAME_VERSION), self.mds.process_payload(node_payload)) + self.assertEqual((self.mds.ChannelNode[1], GOT_SAME_VERSION), self.mds.process_payload(node_payload)) self.assertEqual((None, DELETED_METADATA), self.mds.process_payload(node_deleted_payload)) # Do nothing in case it is unknown/abstract payload type, like ChannelNode self.assertEqual((None, NO_ACTION), self.mds.process_payload(node_payload)) diff --git a/Tribler/Test/Core/Modules/RestApi/test_downloads_endpoint.py b/Tribler/Test/Core/Modules/RestApi/test_downloads_endpoint.py index 5c88669a58b..f22875a4592 100644 --- a/Tribler/Test/Core/Modules/RestApi/test_downloads_endpoint.py +++ b/Tribler/Test/Core/Modules/RestApi/test_downloads_endpoint.py @@ -579,7 +579,7 @@ def verify_download(_): self.assertGreaterEqual(len(self.session.get_downloads()), 1) post_data = {'uri': 'file:%s' % os.path.join(TESTS_DIR, 'Core/data/sample_channel/channel.mdblob')} - expected_json = {'started': True, 'infohash': '6853d25535a1c7593e716dd6a69fc3dd7a7bfcc8'} + expected_json = {'started': True, 'infohash': '8e1cfb5b832e124b681497578c3715b63df01b50'} return self.do_request('downloads', expected_code=200, request_type='PUT', post_data=post_data, expected_json=expected_json).addCallback(verify_download)