public void Test1() { /*tInt = new SharpTorrent.BitTorrentProtocol.BeEncode.String(); tInt.Set(-13); Console.WriteLine(tInt.ToString()); tInt = new SharpTorrent.BitTorrentProtocol.BeEncode.String("-13"); Console.WriteLine(tInt.ToString()); tInt = new SharpTorrent.BitTorrentProtocol.BeEncode.String("Hola pueblo"); Console.WriteLine(tInt.ToString());*/ Dictionary dic = new Dictionary(); List lista = new List(3); lista.Add(new SharpTorrent.BitTorrentProtocol.BeEncode.String("Preciosa")); lista.Add(new SharpTorrent.BitTorrentProtocol.BeEncode.String("amable")); lista.Add(new Integer(10)); dic.Add("miriam", lista); byte[] bee = dic.BeEncode(); Console.ReadLine(); }
private BeEncode.Dictionary ParseDictionary(byte [] buffer) { Dictionary pDictionary = new Dictionary(); string dictionaryKey; BeType dictionaryElement; int infoBegining = 0; if ((buffer[actualTokenPos] != (char)'d') || (buffer[actualTokenPos + 1] == (char)'e')) throw new BePaserException("There is not a valid Dictionary at position " + actualTokenPos.ToString()); // Remove the 'd' actualTokenPos++; while (buffer[actualTokenPos] != (char)'e') { // First the dictionary key dictionaryKey = ParseString(buffer).StringValue; // The info Key has an special treat if (dictionaryKey.CompareTo("info") == 0) { infoBegining = actualTokenPos; } // Now the dictionary element switch (buffer[actualTokenPos]) { case (byte)'d': dictionaryElement = ParseDictionary(buffer); break; case (byte)'l': dictionaryElement = ParseList(buffer); break; case (byte)'i': dictionaryElement = ParseInteger(buffer); break; default: dictionaryElement = ParseString(buffer); break; } // We have the KEY and the ELEMENT pDictionary.Add(dictionaryKey, dictionaryElement); if (dictionaryKey.CompareTo("info") == 0) { int end = actualTokenPos; byte[] temp = new byte[end - infoBegining]; for (int i = 0; i < end - infoBegining; i++) temp[i] = buffer[infoBegining + i]; pDictionary.Add("infoToHash", temp); } } // Remove the 'e' actualTokenPos++; return pDictionary; }
private void ProcessTrackerResponse() { // The tracker response is a Dictionary if (trackerResponse != null) { // Create the dictionary try { Console.WriteLine(Conversions.ConvertByteArrayToString(trackerResponse)); response = new Dictionary(trackerResponse); // Is there a failure reason ?? if (response.ContainsKey("failure reason")) { trackerFailure = true; trackerFailureReason = response["failure reason"].ToString(); } else { // We have data from the Tracker // Get the interval requestInterval = ((BeEncode.Integer)response["interval"]).IntegerValue; } } catch (DictionaryException de) { /// TODO (log error) ; } catch (IntegerException ie) { /// TODO (log error) ; } // We have a new Tracker response, notify!!! if (onNewTrackerResponse != null) onNewTrackerResponse(); } // Progam the timer to future requests even if not yet completed. Only once //if (timer == null) // timer = new Timer(new TimerCallback(TimeToNewRequest), null, requestInterval, requestInterval); }
public Tracker() { urlTracker = string.Empty; response = new Dictionary(); infoHash = null; peerID = null; ip = string.Empty; port = 0; uploaded = downloaded = left = 0; status = TrackerEvents.empty; requestInterval = 0; trackerResponse = null; timer = null; }