private static DictionaryServiceData ConvertToDhtResults(DhtGetResult[] dgrs) { DictionaryServiceData results = new DictionaryServiceData(); foreach (DhtGetResult dgr in dgrs) { var resultEntry = new DictionaryServiceDataEntry(dgr.value); resultEntry.MetaInfo["ttl"] = dgr.ttl; resultEntry.MetaInfo["age"] = dgr.age; results.ResultEntries.Add(resultEntry); } return results; }
public BrunetDhtEntry(byte[] key, Brunet.DistributedServices.DhtGetResult dgr) : this(key, dgr.value, dgr.age, dgr.ttl) { }
/// <summary> /// Gets the first data item of the given name and possibly gets the /// indicated pieces from DHT. /// </summary> /// <param name="getPieces">Whether to get pieces if the data at the /// specified DHT name is a FragmentationInfo</param> public DhtGetResult GetOneDatum(byte[] key, bool getPieces, OneDatumMode mode) { DhtGetResult[] results = _dht.Get(key); DhtGetResult ret; if (results.Length == 0) { ret = null; } else { DhtGetResult dgr; if (mode == OneDatumMode.FirstOne) { dgr = results[0]; } else if (mode == OneDatumMode.LastOne) { dgr = results[results.Length - 1]; } else { throw new NotImplementedException( "This OneDatumMode not implemented."); } DictionaryData dd = null; try { dd = DictionaryData.CreateDictionaryData(dgr.value); } catch (Exception ex) { // Not an error in this case. Log with verbose level. Logger.WriteLineIf(LogLevel.Verbose, _log_props, ex); } if (dd != null && dd is FragmentationInfo) { FragmentationInfo frag_info = dd as FragmentationInfo; BrunetDhtEntry bde = null; try { bde = GetFragments(frag_info) as BrunetDhtEntry; RegularData rd = (RegularData)DictionaryData.CreateDictionaryData( bde.Value); //Only 1 entry (if any) in this array ret = new DhtGetResult(rd.PayLoad, bde.Age, bde.Ttl); } catch (Exception ex) { Logger.WriteLineIf(LogLevel.Error, _log_props, string.Format("Can't get fragments."), ex); ret = null; } } else { ret = dgr; } } return ret; }
/// <summary> /// Use this in the case of success /// </summary> public GetFragsStoppedEventArgs(DhtGetResult[] fragments) : base(null) { this.Fragments = fragments; }