summaryrefslogtreecommitdiff
path: root/src/Data/Torrent.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-29 23:22:25 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-29 23:22:25 +0400
commitf556bf196bf07308f024cc43c1a51dfd4c21188c (patch)
tree228de5a632e8b758d507df7ddabf7fd85d113694 /src/Data/Torrent.hs
parentd4ada1b8a392d67f2835935084c5f0f3ecef2ab5 (diff)
+ Scetch basic broadcasting.
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r--src/Data/Torrent.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 368ec77c..551a260c 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -356,6 +356,22 @@ isMultiFile :: ContentInfo -> Bool
356isMultiFile MultiFile {} = True 356isMultiFile MultiFile {} = True
357isMultiFile _ = False 357isMultiFile _ = False
358 358
359slice :: Int -> Int -> ByteString -> ByteString
360slice from to = B.take to . B.drop from
361
362-- | Extract validation hash by specified piece index.
363pieceHash :: ContentInfo -> Int -> ByteString
364pieceHash ci ix = slice offset size (ciPieces ci)
365 where
366 offset = ciPieceLength ci * ix
367 size = ciPieceLength ci
368
369-- | Validate piece with metainfo hash.
370checkPiece :: ContentInfo -> Int -> ByteString -> Bool
371checkPiece ci ix piece
372 = B.length piece == ciPieceLength ci
373 && hash piece == InfoHash (pieceHash ci ix)
374
359-- | Read and decode a .torrent file. 375-- | Read and decode a .torrent file.
360fromFile :: FilePath -> IO Torrent 376fromFile :: FilePath -> IO Torrent
361fromFile filepath = do 377fromFile filepath = do