private byte[] GenerateExtentionDict() { var extensionDict = new Dictionary <byte[], object>(); var supportedExtensions = new Dictionary <byte[], object>(); supportedExtensions.Set("ut_metadata", 2); extensionDict.Set("m", supportedExtensions); // metadata_size is unnecessary if we are requesting. If we're providing metadata, we should add this. // extensionDict.Set("metadata_size", 0); extensionDict.Set("p", Client.myPort); extensionDict.Set("v", "Ditto 0.1.0"); return(Bencoding.Encode(extensionDict)); }
void sendPing(IPEndPoint destination, byte[] token) { var dict = Bencoding.Dict(); dict.Set("t", token); dict.Set("y", "q"); dict.Set("q", "ping"); dict.Set("ro", 1); var args = Bencoding.Dict(); args.Set("id", nodeId); dict.Set("a", args); var encoded = Bencoding.Encode(dict); socket.SendTo(encoded, destination); }
void sendGetPeers(IPEndPoint destination, byte[] token, byte[] infohash) { var dict = Bencoding.Dict(); dict.Set("t", token); dict.Set("y", "q"); dict.Set("q", "get_peers"); dict.Set("ro", 1); var args = Bencoding.Dict(); args.Set("id", nodeId); args.Set("info_hash", infohash); dict.Set("a", args); var encoded = Bencoding.Encode(dict); socket.SendTo(encoded, destination); }
static byte[] serialize(object value) { return(Bencoding.Encode(value)); }