aboutsummaryrefslogtreecommitdiff
path: root/src/metainfo.zig
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-11-11 22:17:31 +0000
committerMartin Ashby <martin@ashbysoft.com>2023-11-11 22:17:31 +0000
commite3c5be0a33e66b124ff261479cffa9f95ce53dc0 (patch)
tree9d07b95a511d878862f380aa822ff3aff2a4fe95 /src/metainfo.zig
parente51c15cc478b6c89e9100017eebfdf88aff95cca (diff)
downloadzbt-e3c5be0a33e66b124ff261479cffa9f95ce53dc0.tar.gz
zbt-e3c5be0a33e66b124ff261479cffa9f95ce53dc0.tar.bz2
zbt-e3c5be0a33e66b124ff261479cffa9f95ce53dc0.tar.xz
zbt-e3c5be0a33e66b124ff261479cffa9f95ce53dc0.zip
Make request to tracker, get and parse response to find peers list
Diffstat (limited to 'src/metainfo.zig')
-rw-r--r--src/metainfo.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/metainfo.zig b/src/metainfo.zig
index 29cc655..cd00438 100644
--- a/src/metainfo.zig
+++ b/src/metainfo.zig
@@ -63,9 +63,13 @@ pub const Info = struct {
const pri = pr.asInt(u1) catch return error.Malformatted;
priv = pri == 1;
}
+ // Validation....
+ const ps = pp.asString() catch return error.Malformatted;
+ if (ps.len % 20 != 0) return error.Malformatted;
+
return .{
.piece_length = pl.asInt(u64) catch return error.Malformatted,
- .pieces = pp.asString() catch return error.Malformatted,
+ .pieces = ps,
.files = try files.toOwnedSlice(),
.private = priv,
};
@@ -112,6 +116,11 @@ pub const Info = struct {
try b.bencode(w);
return sha1.finalResult();
}
+ pub fn pieceHash(self: Info, ix: usize) ?[]const u8 {
+ const start = 20 * ix;
+ if (start >= self.pieces.len) return null;
+ return self.pieces[start .. start + 20];
+ }
};
info: Info,