mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-15 11:53:12 +00:00
uses MultiHash as a type for piece hashes (instead alias)
This commit is contained in:
parent
cbaace39a9
commit
42b74cc11f
@ -1,4 +1,5 @@
|
||||
import pkg/libp2p/cid
|
||||
import pkg/libp2p/multihash
|
||||
import pkg/libp2p/protobuf/minprotobuf
|
||||
|
||||
import pkg/questionable/results
|
||||
@ -29,7 +30,7 @@ func decode*(_: type BitTorrentManifest, data: openArray[byte]): ?!BitTorrentMan
|
||||
pbInfo: ProtoBuffer
|
||||
length: uint64
|
||||
pieceLength: uint32
|
||||
pieces: seq[BitTorrentPiece]
|
||||
pieces: seq[MultiHash]
|
||||
piecesBytes: seq[seq[byte]]
|
||||
name: string
|
||||
cidBuf = newSeq[byte]()
|
||||
@ -49,7 +50,7 @@ func decode*(_: type BitTorrentManifest, data: openArray[byte]): ?!BitTorrentMan
|
||||
var pbPiece = initProtoBuffer(piece)
|
||||
var dataBuf = newSeq[byte]()
|
||||
if pbPiece.getField(1, dataBuf).isErr:
|
||||
return failure("Unable to decode `data` from BitTorrentPiece")
|
||||
return failure("Unable to decode piece `data` to MultiHash")
|
||||
without mhash =? MultiHash.init(dataBuf).mapFailure, err:
|
||||
return failure(err.msg)
|
||||
pieces.add(mhash)
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import pkg/libp2p/cid
|
||||
import pkg/libp2p/multihash
|
||||
import pkg/libp2p/protobuf/minprotobuf
|
||||
|
||||
import pkg/questionable/results
|
||||
|
||||
import ./manifest
|
||||
|
||||
proc write(pb: var ProtoBuffer, field: int, value: BitTorrentPiece) =
|
||||
proc write(pb: var ProtoBuffer, field: int, value: MultiHash) =
|
||||
var ipb = initProtoBuffer()
|
||||
ipb.write(1, value.data.buffer)
|
||||
ipb.finish()
|
||||
|
||||
@ -11,11 +11,10 @@ import ../../codextypes
|
||||
import ../bencoding
|
||||
|
||||
type
|
||||
BitTorrentPiece* = MultiHash
|
||||
BitTorrentInfo* = ref object
|
||||
length* {.serialize.}: uint64
|
||||
pieceLength* {.serialize.}: uint32
|
||||
pieces* {.serialize.}: seq[BitTorrentPiece]
|
||||
pieces* {.serialize.}: seq[MultiHash]
|
||||
name* {.serialize.}: ?string
|
||||
|
||||
BitTorrentManifest* = ref object
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user