Browse Source

Added handling of shadow records.

Bernd Fix 2 months ago
parent
commit
24d4c6127e

+ 5
- 0
src/gnunet/enums/gns.go View File

@@ -4,6 +4,11 @@ package enums
4 4
 var (
5 5
 	GNS_MAX_BLOCK_SIZE = (63 * 1024) // Maximum size of a value that can be stored in a GNS block.
6 6
 
7
+	// GNS record flags
8
+	GNS_FLAG_PRIVATE = 2
9
+	GNS_FLAGS_EXPREL = 8
10
+	GNS_FLAG_SHADOW  = 16
11
+
7 12
 	// GNS record types
8 13
 	GNS_TYPE_ANY                   = 0     // Record type indicating any record/'*'
9 14
 	GNS_TYPE_DNS_A                 = 1     // [RFC1035] IPv4 Address record

+ 37
- 4
src/gnunet/service/gns/block_handler.go View File

@@ -74,12 +74,16 @@ type BlockHandler interface {
74 74
 // The BlockHandlerList maintains a map of actually instantiated handlers
75 75
 // (indexed by record type) and a list of record types (with occurrence
76 76
 // count) in the block.
77
+// The instance is also responsible for any required post-processing like
78
+// filtering out expired records (and eventually "activating" associated
79
+// shadow records collect from the same block).
77 80
 //----------------------------------------------------------------------
78 81
 
79 82
 // BlockHandlerList is a list of block handlers instantiated.
80 83
 type BlockHandlerList struct {
81
-	list   map[int]BlockHandler // list of handler instances
82
-	counts util.CounterMap      // count number of RRs by type
84
+	list    map[int]BlockHandler         // list of handler instances
85
+	counts  util.CounterMap              // count number of RRs by type
86
+	shadows []*message.GNSResourceRecord // list of shadow records
83 87
 }
84 88
 
85 89
 // NewBlockHandlerList instantiates an a list of active block handlers
@@ -87,8 +91,9 @@ type BlockHandlerList struct {
87 91
 func NewBlockHandlerList(records []*message.GNSResourceRecord, labels []string) (*BlockHandlerList, error) {
88 92
 	// initialize block handler list
89 93
 	hl := &BlockHandlerList{
90
-		list:   make(map[int]BlockHandler),
91
-		counts: make(util.CounterMap),
94
+		list:    make(map[int]BlockHandler),
95
+		counts:  make(util.CounterMap),
96
+		shadows: make([]*message.GNSResourceRecord, 0),
92 97
 	}
93 98
 
94 99
 	// Traverse record list and build list of handler instances
@@ -97,6 +102,12 @@ func NewBlockHandlerList(records []*message.GNSResourceRecord, labels []string)
97 102
 		rrType := int(rec.Type)
98 103
 		hl.counts.Add(rrType)
99 104
 
105
+		// check for SHADOW record.
106
+		if (int(rec.Flags) & enums.GNS_FLAG_SHADOW) != 0 {
107
+			// add to list of shadows
108
+			hl.shadows = append(hl.shadows, rec)
109
+		}
110
+
100 111
 		// check for custom handler type
101 112
 		if creat, ok := customHandler[rrType]; ok {
102 113
 			// check if a handler for given type already exists
@@ -143,6 +154,28 @@ func (hl *BlockHandlerList) GetHandler(t int) BlockHandler {
143 154
 	return nil
144 155
 }
145 156
 
157
+// FinalizeRecord post-processes records: Filtering out expired records (and
158
+// replacing them with a shadow record if available).
159
+func (hl *BlockHandlerList) FinalizeRecord(rec *message.GNSResourceRecord) *message.GNSResourceRecord {
160
+	// filter out shadow records...
161
+	if (int(rec.Flags) & enums.GNS_FLAG_SHADOW) != 0 {
162
+		return nil
163
+	}
164
+	// check for expired record
165
+	if rec.Expires.Expired() {
166
+		// do we have an associated shadow record?
167
+		for _, shadow := range hl.shadows {
168
+			if shadow.Type == rec.Type && !shadow.Expires.Expired() {
169
+				// deliver un-expired shadow record instead.
170
+				return shadow
171
+			}
172
+		}
173
+		// expired and un-shadowed record is dropped
174
+		return nil
175
+	}
176
+	return rec
177
+}
178
+
146 179
 //----------------------------------------------------------------------
147 180
 // PKEY handler: Only one PKEY as sole record in a block
148 181
 //----------------------------------------------------------------------

+ 3
- 1
src/gnunet/service/gns/module.go View File

@@ -243,7 +243,9 @@ func (gns *GNSModule) ResolveRelative(labels []string, pkey *ed25519.PublicKey,
243 243
 		// is this the record type we are looking for?
244 244
 		if kind.HasType(int(rec.Type)) {
245 245
 			// add it to the result
246
-			set.AddRecord(rec)
246
+			if rec = hdlrs.FinalizeRecord(rec); rec != nil {
247
+				set.AddRecord(rec)
248
+			}
247 249
 		}
248 250
 	}
249 251
 	return

Loading…
Cancel
Save