forked from DNS-OARC/ripeatlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resultset.go
116 lines (99 loc) · 3.25 KB
/
resultset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Author Jerry Lundström <jerry@dns-oarc.net>
// Copyright (c) 2017, OARC, Inc.
// All rights reserved.
//
// This file is part of ripeatlas.
//
// ripeatlas is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ripeatlas is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with ripeatlas. If not, see <http://www.gnu.org/licenses/>.
package dns
import (
"encoding/json"
"fmt"
)
type Resultset struct {
data struct {
Af int `json:"af"`
DstAddr string `json:"dst_addr"`
DstName string `json:"dst_name"`
Error json.RawMessage `json:"error"`
Lts int `json:"lts"`
Proto string `json:"proto"`
Qbuf string `json:"qbuf"`
Result json.RawMessage `json:"result"`
Retry int `json:"retry"`
Timestamp int `json:"timestamp"`
}
error *Error
result *Result
}
func (r *Resultset) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &r.data); err != nil {
return fmt.Errorf("%s for %s", err.Error(), string(b))
}
if r.data.Error != nil {
r.error = &Error{}
if err := json.Unmarshal(r.data.Error, r.error); err != nil {
return fmt.Errorf("Unable to process DNS error: %s", err.Error())
}
}
if r.data.Result != nil {
r.result = &Result{}
if err := json.Unmarshal(r.data.Result, r.result); err != nil {
return fmt.Errorf("Unable to process DNS result: %s", err.Error())
}
}
return nil
}
// IP version: "4" or "6" (optional).
func (r *Resultset) Af() int {
return r.data.Af
}
// IP address of the destination (optional).
func (r *Resultset) DstAddr() string {
return r.data.DstAddr
}
// Hostname of the destination (optional).
func (r *Resultset) DstName() string {
return r.data.DstName
}
// DNS error message, nil if not present.
func (r *Resultset) DnsError() *Error {
return r.error
}
// Last time synchronised. How long ago (in seconds) the clock of the probe
// was found to be in sync with that of a controller. The value -1 is used
// to indicate that the probe does not know whether it is in sync.
func (r *Resultset) Lts() int {
return r.data.Lts
}
// Protocol, "TCP" or "UDP".
func (r *Resultset) Proto() string {
return r.data.Proto
}
// Query payload buffer which was sent to the server, UU encoded (optional).
func (r *Resultset) Qbuf() string {
return r.data.Qbuf
}
// DNS response from the DNS server, nil if not present.
func (r *Resultset) Result() *Result {
return r.result
}
// Retry count (optional).
func (r *Resultset) Retry() int {
return r.data.Retry
}
// Start time, in Unix timestamp.
func (r *Resultset) Timestamp() int {
return r.data.Timestamp
}