]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix P2P with object storage
authorChocobozzz <me@florianbigard.com>
Fri, 30 Dec 2022 14:05:14 +0000 (15:05 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 30 Dec 2022 14:05:14 +0000 (15:05 +0100)
server/lib/live/live-manager.ts
server/lib/live/shared/muxing-session.ts
server/tests/shared/live.ts
server/tests/shared/streaming-playlists.ts
shared/server-commands/miscs/sql-command.ts

index 5e459f3c39733a8ca21541c6d98d4093cf4fa036..9ea9831198435c4c90256f1eb4c5373e3195daf5 100644 (file)
@@ -483,12 +483,12 @@ class LiveManager {
     playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
     playlist.type = VideoStreamingPlaylistType.HLS
 
-    playlist.assignP2PMediaLoaderInfoHashes(video, allResolutions)
-
     playlist.storage = CONFIG.OBJECT_STORAGE.ENABLED
       ? VideoStorage.OBJECT_STORAGE
       : VideoStorage.FILE_SYSTEM
 
+    playlist.assignP2PMediaLoaderInfoHashes(video, allResolutions)
+
     return playlist.save()
   }
 
index 6ec1269556a6cfacc7d4d1deab37373cfa3660d6..25ecf1c64b4ba2300a29ed9939497896d485d07f 100644 (file)
@@ -262,6 +262,8 @@ class MuxingSession extends EventEmitter {
           const url = await storeHLSFileFromFilename(this.streamingPlaylist, this.streamingPlaylist.playlistFilename)
 
           this.streamingPlaylist.playlistUrl = url
+          this.streamingPlaylist.assignP2PMediaLoaderInfoHashes(this.videoLive.Video, this.allResolutions)
+
           await this.streamingPlaylist.save()
         } catch (err) {
           logger.error('Cannot upload live master file to object storage.', { err, ...this.lTags() })
index 47e0dc481e6f6b35e6cf51db1431eb6af4f0fe90..1c868eb5b807610003bc4116d1d69f9fa511a908 100644 (file)
@@ -6,6 +6,7 @@ import { join } from 'path'
 import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models'
 import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands'
 import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists'
+import { sha1 } from '@shared/extra-utils'
 
 async function checkLiveCleanup (options: {
   server: PeerTubeServer
@@ -101,6 +102,13 @@ async function testVideoResolutions (options: {
         segmentName,
         hlsPlaylist
       })
+
+      if (originServer.internalServerNumber === server.internalServerNumber) {
+        const infohash = sha1(`${2 + hlsPlaylist.playlistUrl}+V${i}`)
+        const dbInfohashes = await originServer.sql.getPlaylistInfohash(hlsPlaylist.id)
+
+        expect(dbInfohashes).to.include(infohash)
+      }
     }
   }
 }
index 5c62af812ead06679fa2dedd746cb6023a610f0f..75e135c4e5877d6a39c1600628ca5b92572cd837 100644 (file)
@@ -40,6 +40,8 @@ async function checkSegmentHash (options: {
   expect(sha256(segmentBody)).to.equal(shaBody[videoName][range])
 }
 
+// ---------------------------------------------------------------------------
+
 async function checkLiveSegmentHash (options: {
   server: PeerTubeServer
   baseUrlSegment: string
@@ -56,6 +58,8 @@ async function checkLiveSegmentHash (options: {
   expect(sha256(segmentBody)).to.equal(shaBody[segmentName])
 }
 
+// ---------------------------------------------------------------------------
+
 async function checkResolutionsInMasterPlaylist (options: {
   server: PeerTubeServer
   playlistUrl: string
index dbc441abab1e075114f2ccc431b82ac82036e06f..823fc9e388d6a7dcc0b3611da039c4d79824eb66 100644 (file)
@@ -86,6 +86,8 @@ export class SQLCommand extends AbstractCommand {
     return seq.query(query, options)
   }
 
+  // ---------------------------------------------------------------------------
+
   setPluginField (pluginName: string, field: string, value: string) {
     const seq = this.getSequelize()
 
@@ -102,6 +104,17 @@ export class SQLCommand extends AbstractCommand {
     return this.setPluginField(pluginName, 'latestVersion', newVersion)
   }
 
+  // ---------------------------------------------------------------------------
+
+  async getPlaylistInfohash (playlistId: number) {
+    const result = await this.selectQuery('SELECT "p2pMediaLoaderInfohashes" FROM "videoStreamingPlaylist" WHERE id = ' + playlistId)
+    if (!result || result.length === 0) return []
+
+    return result[0].p2pMediaLoaderInfohashes
+  }
+
+  // ---------------------------------------------------------------------------
+
   setActorFollowScores (newScore: number) {
     const seq = this.getSequelize()