]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix infohash with object storage
authorChocobozzz <me@florianbigard.com>
Tue, 7 Sep 2021 13:16:26 +0000 (15:16 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 7 Sep 2021 13:16:26 +0000 (15:16 +0200)
server/lib/job-queue/handlers/move-to-object-storage.ts
server/tests/api/videos/video-hls.ts
shared/extra-utils/requests/requests.ts
shared/extra-utils/server/index.ts
shared/extra-utils/server/tracker.ts [new file with mode: 0644]

index 0bebc0fc2473e3dcdf16f1b5899670db747093c3..4beca3d75d21194336ec64b800cda60c34090163 100644 (file)
@@ -4,6 +4,7 @@ import { join } from 'path'
 import { logger } from '@server/helpers/logger'
 import { updateTorrentUrls } from '@server/helpers/webtorrent'
 import { CONFIG } from '@server/initializers/config'
+import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants'
 import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage'
 import { getHLSDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths'
 import { moveToNextState } from '@server/lib/video-state'
@@ -84,6 +85,9 @@ async function doAfterLastJob (video: MVideoWithAllFiles, isNewVideo: boolean) {
 
     playlist.storage = VideoStorage.OBJECT_STORAGE
 
+    playlist.assignP2PMediaLoaderInfoHashes(video, playlist.VideoFiles)
+    playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
+
     await playlist.save()
   }
 
index 4685bf3b613801275e5abda2bc100a9ad9ab6a7a..91124725fa87dca76a4040acd5ba50934c1af90a 100644 (file)
@@ -14,6 +14,7 @@ import {
   createMultipleServers,
   doubleFollow,
   expectStartWith,
+  hlsInfohashExist,
   makeRawRequest,
   ObjectStorageCommand,
   PeerTubeServer,
@@ -88,9 +89,15 @@ async function checkHlsPlaylist (options: {
 
       const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl })
 
+      let i = 0
       for (const resolution of resolutions) {
         expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
         expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
+
+        const url = 'http://' + videoDetails.account.host
+        await hlsInfohashExist(url, hlsPlaylist.playlistUrl, i)
+
+        i++
       }
     }
 
index 60a08b13c74c30bebc36d0bf93ea2932b907c706..5bbf7f3bf57124caf93c8278e646ef5f0da491da 100644 (file)
@@ -29,9 +29,12 @@ function makeRawRequest (url: string, expectedStatus?: HttpStatusCode, range?: s
 
 function makeGetRequest (options: CommonRequestParams & {
   query?: any
+  rawQuery?: string
 }) {
   const req = request(options.url).get(options.path)
-                                  .query(options.query)
+
+  if (options.query) req.query(options.query)
+  if (options.rawQuery) req.query(options.rawQuery)
 
   return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
 }
index 92ff7a0f9b3367bf12e7536770f5e4d3382e50f4..76a2099da6ca11064c6fd3e08f770d76d2ede3fd 100644 (file)
@@ -14,3 +14,4 @@ export * from './server'
 export * from './servers-command'
 export * from './servers'
 export * from './stats-command'
+export * from './tracker'
diff --git a/shared/extra-utils/server/tracker.ts b/shared/extra-utils/server/tracker.ts
new file mode 100644 (file)
index 0000000..f04e8f8
--- /dev/null
@@ -0,0 +1,27 @@
+import { expect } from 'chai'
+import { sha1 } from '@server/helpers/core-utils'
+import { makeGetRequest } from '../requests'
+
+async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) {
+  const path = '/tracker/announce'
+
+  const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`)
+
+  // From bittorrent-tracker
+  const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) {
+    return '%' + char.charCodeAt(0).toString(16).toUpperCase()
+  })
+
+  const res = await makeGetRequest({
+    url: serverUrl,
+    path,
+    rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`,
+    expectedStatus: 200
+  })
+
+  expect(res.text).to.not.contain('failure')
+}
+
+export {
+  hlsInfohashExist
+}