From 0b25e39cf809e1d8e369e87b9156669a938e6f55 Mon Sep 17 00:00:00 2001 From: Christian Hermann Date: Mon, 3 Jun 2019 21:53:44 +0200 Subject: [PATCH] Extend QueryLog Added - Duration - Cached - Server --- SimpleDnsCrypt/Models/QueryLogLine.cs | 50 ++++++++++++++++++++++++--- SimpleDnsCrypt/Views/MainView.xaml | 11 +++++- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/SimpleDnsCrypt/Models/QueryLogLine.cs b/SimpleDnsCrypt/Models/QueryLogLine.cs index f0166927..e4c1c2ef 100644 --- a/SimpleDnsCrypt/Models/QueryLogLine.cs +++ b/SimpleDnsCrypt/Models/QueryLogLine.cs @@ -1,4 +1,6 @@ -using System; +using Caliburn.Micro; +using SimpleDnsCrypt.Helper; +using System; namespace SimpleDnsCrypt.Models { @@ -23,26 +25,51 @@ public enum QueryLogReturnCode PARSE_ERROR, NXDOMAIN, RESPONSE_ERROR, - SERVER_ERROR + SERVER_ERROR, + CLOAK } public class QueryLogLine : LogLine { + private static readonly ILog Log = LogManagerHelper.Factory(); public DateTime Date { get; set; } public string Address { get; set; } public string Remote { get; set; } public QueryLogLineType Type { get; set; } public QueryLogReturnCode ReturnCode { get; set; } + public bool Cached { get; set; } + public string CachedText { + get + { + if (Cached) + { + return "cached"; + } + else + { + return "live"; + } + } + } + public long Duration { get; set; } + public string DurationText + { + get + { + return $"{Duration}ms"; + } + } + public string Server { get; set; } public QueryLogLine(string line) { try { //this only works with the ltsv log format: - //time:1516734518 host:::1 message:stackoverflow.com type:A + //time:1559589175 host:::1 message:www.test.de type:AAAA return:SYNTH cached:0 duration:0 server:freetsa.org var stringSeparators = new[] { "\t" }; var parts = line.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); - if (parts.Length != 5) return; + if (parts.Length != 8) return; if (parts[0].StartsWith("time:")) { Date = UnixTimeStampToDateTime(Convert.ToDouble(parts[0].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1])); @@ -75,9 +102,22 @@ public QueryLogLine(string line) { Type = QueryLogLineType.Unknown; } + if (parts[5].StartsWith("cached:")) + { + Cached = Convert.ToBoolean(Convert.ToInt16(parts[5].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim())); + } + if (parts[6].StartsWith("duration:")) + { + Duration = Convert.ToInt64(parts[6].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim()); + } + if (parts[7].StartsWith("server:")) + { + Server = parts[7].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); + } } - catch (Exception) + catch (Exception exception) { + Log.Error(exception); } } } diff --git a/SimpleDnsCrypt/Views/MainView.xaml b/SimpleDnsCrypt/Views/MainView.xaml index c7b99708..74fc96a5 100644 --- a/SimpleDnsCrypt/Views/MainView.xaml +++ b/SimpleDnsCrypt/Views/MainView.xaml @@ -959,8 +959,11 @@ - + + + + + + +