public BEncodeValue getValue(BEncodeString value) { BEncodeValue result = null; foreach (KeyValuePair<BEncodeString, BEncodeValue> pair in data) { if (pair.Key.ToString() == value.ToString()) { result = pair.Value; } } return result; }
private BEncodeString decodeString() { char numeric = (char)reader.ReadByte(); BEncodeString value; string totalNumbers = ""; int counter = 0; if (char.IsDigit(numeric)) { totalNumbers += numeric; while ((reader.PeekChar() != ':')) { char num = (char)reader.ReadByte(); if (char.IsDigit(num)) { totalNumbers += num; } else { throw new BEncodeException("char encountered in string legth"); } } } else { throw new BEncodeException("char encountered in string legth"); } reader.ReadByte(); int numberOfChars = Convert.ToInt32(totalNumbers); byte[] dats = new byte[numberOfChars]; while (counter < numberOfChars) { dats[counter] = reader.ReadByte(); counter += 1; } value = new BEncodeString(dats); return value; }
public static List<Peer> uncompact(BEncodeString list) { List<Peer> result = new List<Peer>(); byte[] bytes = list.getBytes(); if (bytes.Length % 6 == 0) { int counter = 0; int index = 0; byte[] actualPeer = new byte[6]; bool final = false; while (true) { if (counter < bytes.Length) { if ((counter % 6 == 0 && counter != 0) || final) { index = 0; int i = 3; byte[] byteIp = new byte[4]; byte[] bytePort = new byte[2]; byteIp[0] = actualPeer[3]; byteIp[1] = actualPeer[2]; byteIp[2] = actualPeer[1]; byteIp[3] = actualPeer[0]; bytePort[0] = actualPeer[5]; bytePort[1] = actualPeer[4]; Peer peer = new Peer(IPConverter.Int32ToIP(BitConverter.ToUInt32(byteIp, 0)), BitConverter.ToUInt16(bytePort, 0)); result.Add(peer); actualPeer = new byte[6]; actualPeer[index] = bytes[counter]; counter++; index++; } else { actualPeer[index] = bytes[counter]; if (counter == bytes.Length - 1) { final = true; } else { counter++; } index++; } } else { break; } } } else { throw new TrackerResponseException("peer length in bytes different of 6 multiplier"); } return result; }
public void Add(BEncodeString key, BEncodeDictionary value) { data.Add(key, value); }
public void Add(BEncodeString key, BEncodeList value) { data.Add(key, value); }
public void Add(BEncodeString key, BEncodeInteger value) { data.Add(key, value); }
public void Add(BEncodeString value) { data.Add(value); }