1
- using System ;
1
+ using Caliburn . Micro ;
2
+ using SimpleDnsCrypt . Helper ;
3
+ using System ;
2
4
3
5
namespace SimpleDnsCrypt . Models
4
6
{
@@ -23,26 +25,51 @@ public enum QueryLogReturnCode
23
25
PARSE_ERROR ,
24
26
NXDOMAIN ,
25
27
RESPONSE_ERROR ,
26
- SERVER_ERROR
28
+ SERVER_ERROR ,
29
+ CLOAK
27
30
}
28
31
29
32
public class QueryLogLine : LogLine
30
33
{
34
+ private static readonly ILog Log = LogManagerHelper . Factory ( ) ;
31
35
public DateTime Date { get ; set ; }
32
36
public string Address { get ; set ; }
33
37
public string Remote { get ; set ; }
34
38
public QueryLogLineType Type { get ; set ; }
35
39
public QueryLogReturnCode ReturnCode { get ; set ; }
40
+ public bool Cached { get ; set ; }
41
+ public string CachedText {
42
+ get
43
+ {
44
+ if ( Cached )
45
+ {
46
+ return "cached" ;
47
+ }
48
+ else
49
+ {
50
+ return "live" ;
51
+ }
52
+ }
53
+ }
54
+ public long Duration { get ; set ; }
55
+ public string DurationText
56
+ {
57
+ get
58
+ {
59
+ return $ "{ Duration } ms";
60
+ }
61
+ }
62
+ public string Server { get ; set ; }
36
63
37
64
public QueryLogLine ( string line )
38
65
{
39
66
try
40
67
{
41
68
//this only works with the ltsv log format:
42
- //time:1516734518 host:::1 message:stackoverflow.com type:A
69
+ //time:1559589175 host:::1 message:www.test.de type:AAAA return:SYNTH cached:0 duration:0 server:freetsa.org
43
70
var stringSeparators = new [ ] { "\t " } ;
44
71
var parts = line . Split ( stringSeparators , StringSplitOptions . RemoveEmptyEntries ) ;
45
- if ( parts . Length != 5 ) return ;
72
+ if ( parts . Length != 8 ) return ;
46
73
if ( parts [ 0 ] . StartsWith ( "time:" ) )
47
74
{
48
75
Date = UnixTimeStampToDateTime ( Convert . ToDouble ( parts [ 0 ] . Split ( new [ ] { ":" } , StringSplitOptions . RemoveEmptyEntries ) [ 1 ] ) ) ;
@@ -75,9 +102,22 @@ public QueryLogLine(string line)
75
102
{
76
103
Type = QueryLogLineType . Unknown ;
77
104
}
105
+ if ( parts [ 5 ] . StartsWith ( "cached:" ) )
106
+ {
107
+ Cached = Convert . ToBoolean ( Convert . ToInt16 ( parts [ 5 ] . Split ( new [ ] { ":" } , StringSplitOptions . RemoveEmptyEntries ) [ 1 ] . Trim ( ) ) ) ;
108
+ }
109
+ if ( parts [ 6 ] . StartsWith ( "duration:" ) )
110
+ {
111
+ Duration = Convert . ToInt64 ( parts [ 6 ] . Split ( new [ ] { ":" } , StringSplitOptions . RemoveEmptyEntries ) [ 1 ] . Trim ( ) ) ;
112
+ }
113
+ if ( parts [ 7 ] . StartsWith ( "server:" ) )
114
+ {
115
+ Server = parts [ 7 ] . Split ( new [ ] { ":" } , StringSplitOptions . RemoveEmptyEntries ) [ 1 ] . Trim ( ) ;
116
+ }
78
117
}
79
- catch ( Exception )
118
+ catch ( Exception exception )
80
119
{
120
+ Log . Error ( exception ) ;
81
121
}
82
122
}
83
123
}
0 commit comments