Beispiel #1
0
        public void TestPutAndGetFragments()
        {
            MockBrunetDht     mock_dht  = new MockBrunetDht();
            BrunetDht         dht       = new BrunetDht(mock_dht);
            FragmentationInfo frag_info = new FragmentationInfo();

            byte[] b_key = MakeByteArray(20);
            string key   = Encoding.UTF8.GetString(b_key);

            frag_info.BaseKey = Encoding.UTF8.GetString(b_key);
            Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                               string.Format("key : {0}", Base32.Encode(b_key)));
            byte[]         expected = MakeByteArray(1024 * 10);
            int            ttl      = 1000;
            BrunetDhtEntry bde      = new BrunetDhtEntry(key, expected, ttl);

            dht.PutFragments(bde, frag_info);
            Hashtable ht = mock_dht.HTStorage;

            Assert.AreEqual(11, ht.Count);
            ////
            byte[]            serialized_fragInfo = ((DhtGetResult[])dht.Get(key))[0].value;
            FragmentationInfo frag_info_actual    =
                DictionaryData.CreateDictionaryData(serialized_fragInfo) as FragmentationInfo;

            Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                               string.Format("BaseKey: {0}", Base32.Encode(Encoding.UTF8.GetBytes(frag_info_actual.BaseKey))));
            BrunetDhtEntry actual = dht.GetFragments(frag_info) as BrunetDhtEntry;
            MemBlock       mb     = MemBlock.Reference(actual.Value);
            MemBlock       mb_exp = MemBlock.Reference(expected);

            Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                               mb.ToBase32String().Substring(0, 50));
            Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                               mb_exp.ToBase32String().Substring(0, 50));
            Assert.AreEqual(mb_exp, mb);
        }
Beispiel #2
0
 public void TestPutAndGetFragments()
 {
     MockBrunetDht mock_dht = new MockBrunetDht();
       BrunetDht dht = new BrunetDht(mock_dht);
       FragmentationInfo frag_info = new FragmentationInfo();
       byte[] b_key = MakeByteArray(20);
       string key = Encoding.UTF8.GetString(b_key);
       frag_info.BaseKey = Encoding.UTF8.GetString(b_key);
       Logger.WriteLineIf(LogLevel.Verbose, _log_props,
       string.Format("key : {0}", Base32.Encode(b_key)));
       byte[] expected = MakeByteArray(1024 * 10);
       int ttl = 1000;
       BrunetDhtEntry bde = new BrunetDhtEntry(key, expected, ttl);
       dht.PutFragments(bde, frag_info);
       Hashtable ht = mock_dht.HTStorage;
       Assert.AreEqual(11, ht.Count);
       ////
       byte[] serialized_fragInfo = ((DhtGetResult[])dht.Get(key))[0].value;
       FragmentationInfo frag_info_actual =
     DictionaryData.CreateDictionaryData(serialized_fragInfo) as FragmentationInfo;
       Logger.WriteLineIf(LogLevel.Verbose, _log_props,
       string.Format("BaseKey: {0}", Base32.Encode(Encoding.UTF8.GetBytes(frag_info_actual.BaseKey))));
       BrunetDhtEntry actual = dht.GetFragments(frag_info) as BrunetDhtEntry;
       MemBlock mb = MemBlock.Reference(actual.Value);
       MemBlock mb_exp = MemBlock.Reference(expected);
       Logger.WriteLineIf(LogLevel.Verbose, _log_props,
       mb.ToBase32String().Substring(0, 50));
       Logger.WriteLineIf(LogLevel.Verbose, _log_props,
       mb_exp.ToBase32String().Substring(0, 50));
       Assert.AreEqual(mb_exp, mb);
 }