From 54db8e3d5c09fedc82d8421529c81255760a5ac2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Dec 2022 15:05:14 +0100 Subject: Fix P2P with object storage --- server/lib/live/live-manager.ts | 4 ++-- server/lib/live/shared/muxing-session.ts | 2 ++ server/tests/shared/live.ts | 8 ++++++++ server/tests/shared/streaming-playlists.ts | 4 ++++ shared/server-commands/miscs/sql-command.ts | 13 +++++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 5e459f3c3..9ea983119 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts @@ -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() } diff --git a/server/lib/live/shared/muxing-session.ts b/server/lib/live/shared/muxing-session.ts index 6ec126955..25ecf1c64 100644 --- a/server/lib/live/shared/muxing-session.ts +++ b/server/lib/live/shared/muxing-session.ts @@ -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() }) diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts index 47e0dc481..1c868eb5b 100644 --- a/server/tests/shared/live.ts +++ b/server/tests/shared/live.ts @@ -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) + } } } } diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts index 5c62af812..75e135c4e 100644 --- a/server/tests/shared/streaming-playlists.ts +++ b/server/tests/shared/streaming-playlists.ts @@ -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 diff --git a/shared/server-commands/miscs/sql-command.ts b/shared/server-commands/miscs/sql-command.ts index dbc441aba..823fc9e38 100644 --- a/shared/server-commands/miscs/sql-command.ts +++ b/shared/server-commands/miscs/sql-command.ts @@ -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() -- cgit v1.2.3