Expose DNS common helpers in lns
This commit is contained in:
parent
a51657094b
commit
236501fd29
2 changed files with 126 additions and 0 deletions
74
lns.go
74
lns.go
|
|
@ -20,12 +20,36 @@ import (
|
|||
core "dappco.re/go/core"
|
||||
"dappco.re/go/lns/internal/nameutil"
|
||||
"dappco.re/go/lns/pkg/covenant"
|
||||
dnspkg "dappco.re/go/lns/pkg/dns"
|
||||
"dappco.re/go/lns/pkg/primitives"
|
||||
)
|
||||
|
||||
// ServiceName is the registered name for the LNS service group.
|
||||
const ServiceName = "lns"
|
||||
|
||||
// DNS common constants mirror pkg/dns so callers can stay in the top-level
|
||||
// lns package for the reference DNS metadata.
|
||||
const DEFAULT_TTL = dnspkg.DEFAULT_TTL
|
||||
|
||||
// DUMMY mirrors the DNS zero-length reference buffer used by pkg/dns.
|
||||
var DUMMY = dnspkg.DUMMY
|
||||
|
||||
// Type map bitmaps mirror pkg/dns common constants.
|
||||
var (
|
||||
TYPE_MAP_ROOT = dnspkg.TYPE_MAP_ROOT
|
||||
TYPE_MAP_EMPTY = dnspkg.TYPE_MAP_EMPTY
|
||||
TYPE_MAP_NS = dnspkg.TYPE_MAP_NS
|
||||
TYPE_MAP_TXT = dnspkg.TYPE_MAP_TXT
|
||||
TYPE_MAP_A = dnspkg.TYPE_MAP_A
|
||||
TYPE_MAP_AAAA = dnspkg.TYPE_MAP_AAAA
|
||||
)
|
||||
|
||||
// HSTypes mirrors the DNS hsTypes lookup table from pkg/dns.
|
||||
var HSTypes = dnspkg.HSTypes
|
||||
|
||||
// HSTypesByVal mirrors the DNS hsTypesByVal reverse lookup table from pkg/dns.
|
||||
var HSTypesByVal = dnspkg.HSTypesByVal
|
||||
|
||||
// Service is the LNS service that manages .lthn name resolution,
|
||||
// covenant processing, and name-chain state queries.
|
||||
//
|
||||
|
|
@ -134,6 +158,56 @@ func GetServiceName() string {
|
|||
return ServiceName
|
||||
}
|
||||
|
||||
// GetDefaultTTL returns the reference DNS TTL used for synthesized records.
|
||||
func GetDefaultTTL() int {
|
||||
return DEFAULT_TTL
|
||||
}
|
||||
|
||||
// GetDummy returns the zero-length DNS reference buffer.
|
||||
func GetDummy() []byte {
|
||||
return DUMMY
|
||||
}
|
||||
|
||||
// GetTypeMapRoot returns the reference type bitmap for the root zone.
|
||||
func GetTypeMapRoot() []byte {
|
||||
return TYPE_MAP_ROOT
|
||||
}
|
||||
|
||||
// GetTypeMapEmpty returns the reference type bitmap for an empty response.
|
||||
func GetTypeMapEmpty() []byte {
|
||||
return TYPE_MAP_EMPTY
|
||||
}
|
||||
|
||||
// GetTypeMapNS returns the reference type bitmap for NS responses.
|
||||
func GetTypeMapNS() []byte {
|
||||
return TYPE_MAP_NS
|
||||
}
|
||||
|
||||
// GetTypeMapTXT returns the reference type bitmap for TXT responses.
|
||||
func GetTypeMapTXT() []byte {
|
||||
return TYPE_MAP_TXT
|
||||
}
|
||||
|
||||
// GetTypeMapA returns the reference type bitmap for A responses.
|
||||
func GetTypeMapA() []byte {
|
||||
return TYPE_MAP_A
|
||||
}
|
||||
|
||||
// GetTypeMapAAAA returns the reference type bitmap for AAAA responses.
|
||||
func GetTypeMapAAAA() []byte {
|
||||
return TYPE_MAP_AAAA
|
||||
}
|
||||
|
||||
// GetHSTypes returns the DNS record-type lookup table.
|
||||
func GetHSTypes() map[string]dnspkg.HSType {
|
||||
return HSTypes
|
||||
}
|
||||
|
||||
// GetHSTypesByVal returns the reverse DNS record-type lookup table.
|
||||
func GetHSTypesByVal() map[dnspkg.HSType]string {
|
||||
return HSTypesByVal
|
||||
}
|
||||
|
||||
// OnStartup satisfies core.Startable so LNS participates in Core lifecycle
|
||||
// discovery without requiring any explicit setup.
|
||||
func (s *Service) OnStartup(context.Context) core.Result {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
package lns
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha3"
|
||||
"encoding/binary"
|
||||
"strings"
|
||||
|
|
@ -11,6 +12,7 @@ import (
|
|||
"golang.org/x/crypto/blake2b"
|
||||
|
||||
"dappco.re/go/lns/pkg/covenant"
|
||||
dnspkg "dappco.re/go/lns/pkg/dns"
|
||||
"dappco.re/go/lns/pkg/primitives"
|
||||
)
|
||||
|
||||
|
|
@ -575,6 +577,56 @@ func TestPackageConstantGetters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPackageDNSCommonGetters(t *testing.T) {
|
||||
if GetDefaultTTL() != DEFAULT_TTL {
|
||||
t.Fatalf("GetDefaultTTL() = %d, want %d", GetDefaultTTL(), DEFAULT_TTL)
|
||||
}
|
||||
|
||||
if !bytes.Equal(GetDummy(), DUMMY) {
|
||||
t.Fatal("GetDummy should alias DUMMY")
|
||||
}
|
||||
|
||||
if !bytes.Equal(GetTypeMapRoot(), TYPE_MAP_ROOT) {
|
||||
t.Fatal("GetTypeMapRoot should alias TYPE_MAP_ROOT")
|
||||
}
|
||||
|
||||
if !bytes.Equal(GetTypeMapEmpty(), TYPE_MAP_EMPTY) {
|
||||
t.Fatal("GetTypeMapEmpty should alias TYPE_MAP_EMPTY")
|
||||
}
|
||||
|
||||
if !bytes.Equal(GetTypeMapNS(), TYPE_MAP_NS) {
|
||||
t.Fatal("GetTypeMapNS should alias TYPE_MAP_NS")
|
||||
}
|
||||
|
||||
if !bytes.Equal(GetTypeMapTXT(), TYPE_MAP_TXT) {
|
||||
t.Fatal("GetTypeMapTXT should alias TYPE_MAP_TXT")
|
||||
}
|
||||
|
||||
if !bytes.Equal(GetTypeMapA(), TYPE_MAP_A) {
|
||||
t.Fatal("GetTypeMapA should alias TYPE_MAP_A")
|
||||
}
|
||||
|
||||
if !bytes.Equal(GetTypeMapAAAA(), TYPE_MAP_AAAA) {
|
||||
t.Fatal("GetTypeMapAAAA should alias TYPE_MAP_AAAA")
|
||||
}
|
||||
|
||||
if len(GetHSTypes()) != len(HSTypes) {
|
||||
t.Fatal("GetHSTypes should alias HSTypes")
|
||||
}
|
||||
|
||||
if len(GetHSTypesByVal()) != len(HSTypesByVal) {
|
||||
t.Fatal("GetHSTypesByVal should alias HSTypesByVal")
|
||||
}
|
||||
|
||||
if got := GetHSTypes()["DS"]; got != dnspkg.HSTypeDS {
|
||||
t.Fatalf("GetHSTypes()[\"DS\"] = %d, want %d", got, dnspkg.HSTypeDS)
|
||||
}
|
||||
|
||||
if got := GetHSTypesByVal()[dnspkg.HSTypeTXT]; got != "TXT" {
|
||||
t.Fatalf("GetHSTypesByVal()[TXT] = %q, want %q", got, "TXT")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageNameStateAliases(t *testing.T) {
|
||||
var state NameState
|
||||
var delta NameDelta
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue