Browse Source

Handle VPN record in case of empty RR set when looking for A/AAAA.

master
Bernd Fix 1 year ago
parent
commit
32e0edc6c8
2 changed files with 67 additions and 0 deletions
  1. +56
    -0
      src/gnunet/service/gns/block_handler.go
  2. +11
    -0
      src/gnunet/service/gns/module.go

+ 56
- 0
src/gnunet/service/gns/block_handler.go View File

@ -21,6 +21,7 @@ var (
ErrInvalidRecordBody = fmt.Errorf("Invalid resource record body")
ErrInvalidPKEY = fmt.Errorf("Invalid PKEY resource record")
ErrInvalidCNAME = fmt.Errorf("Invalid CNAME resource record")
ErrInvalidVPN = fmt.Errorf("Invalid VPN resource record")
ErrInvalidRecordMix = fmt.Errorf("Invalid mix of RR types in block")
ErrBlockHandler = fmt.Errorf("Internal block handler failure")
)
@ -33,6 +34,7 @@ var (
enums.GNS_TYPE_BOX: NewBoxHandler,
enums.GNS_TYPE_LEHO: NewLehoHandler,
enums.GNS_TYPE_DNS_CNAME: NewCnameHandler,
enums.GNS_TYPE_VPN: NewVpnHandler,
}
)
@ -519,3 +521,57 @@ func (h *CnameHandler) Records(kind RRTypeList) *GNSRecordSet {
func (h *CnameHandler) Name() string {
return "CNAME_Handler"
}
//----------------------------------------------------------------------
// VPN handler
//----------------------------------------------------------------------
// VpnHandler implementing the BlockHandler interface
type VpnHandler struct {
rec *message.GNSResourceRecord
}
// NewVpnHandler returns a new BlockHandler instance
func NewVpnHandler(rec *message.GNSResourceRecord, labels []string) (BlockHandler, error) {
if int(rec.Type) != enums.GNS_TYPE_VPN {
return nil, ErrInvalidRecordType
}
h := &VpnHandler{}
if err := h.AddRecord(rec, labels); err != nil {
return nil, err
}
return h, nil
}
// AddRecord inserts a VPN record into the handler.
func (h *VpnHandler) AddRecord(rec *message.GNSResourceRecord, labels []string) error {
if int(rec.Type) != enums.GNS_TYPE_VPN {
return ErrInvalidRecordType
}
if h.rec != nil {
return ErrInvalidVPN
}
h.rec = rec
return nil
}
// Coexist return a flag indicating how a resource record of a given type
// is to be treated (see BlockHandler interface)
func (h *VpnHandler) Coexist(cm util.CounterMap) bool {
// anything goes
return true
}
// Records returns a list of RR of the given type associated with this handler
func (h *VpnHandler) Records(kind RRTypeList) *GNSRecordSet {
rs := NewGNSRecordSet()
if kind.HasType(enums.GNS_TYPE_VPN) {
rs.AddRecord(h.rec)
}
return rs
}
// Name returns the human-readable name of the handler.
func (h *VpnHandler) Name() string {
return "VPN_Handler"
}

+ 11
- 0
src/gnunet/service/gns/module.go View File

@ -248,6 +248,17 @@ func (gns *GNSModule) ResolveRelative(labels []string, pkey *ed25519.PublicKey,
}
}
}
// if no records of the requested type (either A or AAAA) have been found,
// and we have a VPN record, return this instead.
if set.Count == 0 && (kind.HasType(enums.GNS_TYPE_DNS_A) || kind.HasType(enums.GNS_TYPE_DNS_AAAA)) {
// check for VPN record
if hdlr := hdlrs.GetHandler(enums.GNS_TYPE_VPN); hdlr != nil {
// add VPN record to result set
inst := hdlr.(*VpnHandler)
set.AddRecord(inst.rec)
}
}
return
}


Loading…
Cancel
Save