Skip to content

Commit

Permalink
Extend QueryLog
Browse files Browse the repository at this point in the history
Added
- Duration
- Cached
- Server
  • Loading branch information
bitbeans committed Jun 3, 2019
1 parent 9e60cfa commit 0b25e39
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
50 changes: 45 additions & 5 deletions SimpleDnsCrypt/Models/QueryLogLine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Caliburn.Micro;
using SimpleDnsCrypt.Helper;
using System;

namespace SimpleDnsCrypt.Models
{
Expand All @@ -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]));
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion SimpleDnsCrypt/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,11 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130" />
<ColumnDefinition Width="40" />
<ColumnDefinition Width="70" />
<ColumnDefinition Width="90" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="160" />
<ColumnDefinition Width="40" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Expand All @@ -974,6 +977,12 @@
Foreground="#FF575757" />
<TextBlock Grid.Column="4" Text="{Binding Remote}"
Foreground="#FF575757" />
<TextBlock Grid.Column="5" Text="{Binding CachedText}"
Foreground="#FF575757" />
<TextBlock Grid.Column="6" Text="{Binding DurationText}"
Foreground="#FF575757" />
<TextBlock Grid.Column="7" Text="{Binding Server}"
Foreground="#FF575757" />
</Grid>
</DataTemplate>
</customControls:LoggingListView.ItemTemplate>
Expand Down

0 comments on commit 0b25e39

Please sign in to comment.