public Metainfo ToMetainfo(out byte[] bytes) { BencodedValue entries = Build(); bytes = Bencoder.Encode(entries); return(MetainfoFactory.FromBytes(bytes)); }
public static void SendMetadataRequest(this CoordinatorService glue, PeerHash peer, int piece) { BencodedValue bencoded = new BencodedValue { Dictionary = new[] { new BencodedEntry { Key = new BencodedValue { Text = new BencodedText("msg_type") }, Value = new BencodedValue { Number = new BencodedNumber(0) } }, new BencodedEntry { Key = new BencodedValue { Text = new BencodedText("piece") }, Value = new BencodedValue { Number = new BencodedNumber(piece) } } } }; glue.SendExtension(peer, MetadataPlugin.Name, Bencoder.Encode(bencoded)); }
public byte[] ToBytes() { BencodedValue entries = Build(); byte[] bytes = Bencoder.Encode(entries); return(bytes); }
public Extended GetHandshake() { BencodedValue encoded = more.Encode(metadata?.Size); byte[] binary = Bencoder.Encode(encoded); return(new Extended(0, binary)); }
public FileHash ToHash() { BencodedValue entries = Build(); byte[] bytes = Bencoder.Encode(entries); Metainfo metainfo = MetainfoFactory.FromBytes(bytes); FileHash hash = metainfo.Hash; return(hash); }
public static void SendPeers(this CoordinatorService glue, PeerHash peer, params NetworkAddress[] remotes) { BencodedValue bencoded = new BencodedValue { Dictionary = new[] { new BencodedEntry { Key = new BencodedValue { Text = new BencodedText("added") }, Value = new BencodedValue { Data = ToData(remotes) } } } }; glue.SendExtension(peer, PeersPlugin.Name, Bencoder.Encode(bencoded)); }
public static void SendMetadataPiece(this CoordinatorService glue, PeerHash peer, int piece, int total, byte[] data) { BencodedValue bencoded = new BencodedValue { Dictionary = new[] { new BencodedEntry { Key = new BencodedValue { Text = new BencodedText("msg_type") }, Value = new BencodedValue { Number = new BencodedNumber(1) } }, new BencodedEntry { Key = new BencodedValue { Text = new BencodedText("piece") }, Value = new BencodedValue { Number = new BencodedNumber(piece) } }, new BencodedEntry { Key = new BencodedValue { Text = new BencodedText("total_size") }, Value = new BencodedValue { Number = new BencodedNumber(total) } } } }; byte[] payload = Bencoder.Encode(bencoded); Bytes.Append(ref payload, data); glue.SendExtension(peer, MetadataPlugin.Name, payload); }