Browse Source

Filter DNS results by requested RR types.

Bernd Fix 3 months ago
parent
commit
5cbcd1c86f
1 changed files with 24 additions and 20 deletions
  1. 24
    20
      src/gnunet/service/gns/dns.go

+ 24
- 20
src/gnunet/service/gns/dns.go View File

@@ -63,7 +63,7 @@ func queryDNS(id int, name string, server net.IP, kind RRTypeList, res chan *GNS
63 63
 	}
64 64
 	m.Question[0] = dns.Question{
65 65
 		dns.Fqdn(name),
66
-		dns.TypeANY, // TODO: replace with 'kind' values
66
+		dns.TypeANY,
67 67
 		dns.ClassINET,
68 68
 	}
69 69
 
@@ -91,27 +91,30 @@ func queryDNS(id int, name string, server net.IP, kind RRTypeList, res chan *GNS
91 91
 		}
92 92
 		set := NewGNSRecordSet()
93 93
 		for _, record := range in.Answer {
94
-			// create a new GNS resource record
95
-			rr := new(message.GNSResourceRecord)
96
-			rr.Expires = util.AbsoluteTimeNever()
97
-			rr.Flags = 0
98
-			rr.Type = uint32(record.Header().Rrtype)
99
-			rr.Size = uint32(record.Header().Rdlength)
100
-			rr.Data = make([]byte, rr.Size)
94
+			// check if answer record is of requested type
95
+			if kind.HasType(int(record.Header().Rrtype)) {
96
+				// create a new GNS resource record
97
+				rr := new(message.GNSResourceRecord)
98
+				rr.Expires = util.AbsoluteTimeNever()
99
+				rr.Flags = 0
100
+				rr.Type = uint32(record.Header().Rrtype)
101
+				rr.Size = uint32(record.Header().Rdlength)
102
+				rr.Data = make([]byte, rr.Size)
101 103
 
102
-			// get wire-format of resource record
103
-			buf := make([]byte, 2048)
104
-			n, err := dns.PackRR(record, buf, 0, nil, false)
105
-			if err != nil {
106
-				logger.Printf(logger.WARN, "[dns][%d] Failed to get RR data for %s\n", id, err.Error())
107
-				continue
108
-			}
109
-			if n < int(rr.Size) {
110
-				logger.Printf(logger.WARN, "[dns][%d] Nit enough data in RR (%d != %d)\n", id, n, rr.Size)
111
-				continue
104
+				// get wire-format of resource record
105
+				buf := make([]byte, 2048)
106
+				n, err := dns.PackRR(record, buf, 0, nil, false)
107
+				if err != nil {
108
+					logger.Printf(logger.WARN, "[dns][%d] Failed to get RR data for %s\n", id, err.Error())
109
+					continue
110
+				}
111
+				if n < int(rr.Size) {
112
+					logger.Printf(logger.WARN, "[dns][%d] Nit enough data in RR (%d != %d)\n", id, n, rr.Size)
113
+					continue
114
+				}
115
+				copy(rr.Data, buf[n-int(rr.Size):])
116
+				set.AddRecord(rr)
112 117
 			}
113
-			copy(rr.Data, buf[n-int(rr.Size):])
114
-			set.AddRecord(rr)
115 118
 		}
116 119
 		logger.Printf(logger.WARN, "[dns][%d] %d resource records extracted from response (%d/5).\n", id, set.Count, retry+1)
117 120
 		res <- set
@@ -159,6 +162,7 @@ func (gns *GNSModule) ResolveDNS(name string, servers []string, kind RRTypeList,
159 162
 				switch int(rec.Type) {
160 163
 				case enums.GNS_TYPE_DNS_AAAA:
161 164
 					addr = net.IP(rec.Data)
165
+					// we prefer IPv6
162 166
 					break rec_loop
163 167
 				case enums.GNS_TYPE_DNS_A:
164 168
 					addr = net.IP(rec.Data)

Loading…
Cancel
Save