diff options
Diffstat (limited to 'client/src/assets/player/p2p-media-loader')
-rw-r--r-- | client/src/assets/player/p2p-media-loader/segment-validator.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts index 8f4922daa..72c32f9e0 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts | |||
@@ -3,18 +3,25 @@ import { basename } from 'path' | |||
3 | 3 | ||
4 | function segmentValidatorFactory (segmentsSha256Url: string) { | 4 | function segmentValidatorFactory (segmentsSha256Url: string) { |
5 | const segmentsJSON = fetchSha256Segments(segmentsSha256Url) | 5 | const segmentsJSON = fetchSha256Segments(segmentsSha256Url) |
6 | const regex = /bytes=(\d+)-(\d+)/ | ||
6 | 7 | ||
7 | return async function segmentValidator (segment: Segment) { | 8 | return async function segmentValidator (segment: Segment) { |
8 | const segmentName = basename(segment.url) | 9 | const filename = basename(segment.url) |
10 | const captured = regex.exec(segment.range) | ||
9 | 11 | ||
10 | const hashShouldBe = (await segmentsJSON)[segmentName] | 12 | const range = captured[1] + '-' + captured[2] |
13 | |||
14 | const hashShouldBe = (await segmentsJSON)[filename][range] | ||
11 | if (hashShouldBe === undefined) { | 15 | if (hashShouldBe === undefined) { |
12 | throw new Error(`Unknown segment name ${segmentName} in segment validator`) | 16 | throw new Error(`Unknown segment name ${filename}/${range} in segment validator`) |
13 | } | 17 | } |
14 | 18 | ||
15 | const calculatedSha = bufferToEx(await sha256(segment.data)) | 19 | const calculatedSha = bufferToEx(await sha256(segment.data)) |
16 | if (calculatedSha !== hashShouldBe) { | 20 | if (calculatedSha !== hashShouldBe) { |
17 | throw new Error(`Hashes does not correspond for segment ${segmentName} (expected: ${hashShouldBe} instead of ${calculatedSha})`) | 21 | throw new Error( |
22 | `Hashes does not correspond for segment ${filename}/${range}` + | ||
23 | `(expected: ${hashShouldBe} instead of ${calculatedSha})` | ||
24 | ) | ||
18 | } | 25 | } |
19 | } | 26 | } |
20 | } | 27 | } |