@@ -14,17 +14,11 @@ import (
1414 input_chainsync "github.com/blinklabs-io/snek/input/chainsync"
1515 output_embedded "github.com/blinklabs-io/snek/output/embedded"
1616 "github.com/blinklabs-io/snek/pipeline"
17- "github.com/miekg/dns"
1817)
1918
2019type Domain struct {
21- name string
22- records map [string ]map [string ][]DomainRecord
23- }
24-
25- type DomainRecord struct {
26- Name string
27- Value string
20+ Name string
21+ Nameservers map [string ]string
2822}
2923
3024type Indexer struct {
@@ -120,63 +114,31 @@ func (i *Indexer) handleEvent(evt event.Event) error {
120114 }
121115 datumFields := datum .Value ().(cbor.Constructor ).Fields ()
122116 domainName := string (datumFields [0 ].(cbor.ByteString ).Bytes ()) + `.`
117+ // Create empty domain record
118+ // This will also clobber any previous definition of the domain
119+ i .domains [domainName ] = Domain {
120+ Name : domainName ,
121+ Nameservers : make (map [string ]string ),
122+ }
123123 for _ , record := range datumFields [1 ].([]any ) {
124124 recordConstructor := record .(cbor.Constructor )
125125 nameServer := string (recordConstructor .Fields ()[0 ].(cbor.ByteString ).Bytes ()) + `.`
126126 ipAddress := string (recordConstructor .Fields ()[1 ].(cbor.ByteString ).Bytes ())
127- // Create NS record for domain
128- i .addRecord (domainName , domainName , "NS" , nameServer )
129- // Create A record for name server
130- i .addRecord (domainName , nameServer , "A" , ipAddress )
127+ i .domains [domainName ].Nameservers [nameServer ] = ipAddress
131128 }
132129 logger .Infof ("found updated registration for domain: %s" , domainName )
133130 }
134131 }
135132 return nil
136133}
137134
138- func (i * Indexer ) LookupRecords (name string , recordType string ) []DomainRecord {
139- for domainName , domain := range i .domains {
140- if dns .IsSubDomain (domainName , name ) {
141- if records , ok := domain .records [name ]; ok {
142- if record , ok := records [recordType ]; ok {
143- return record
144- } else {
145- return nil
146- }
147- } else {
148- return nil
149- }
150- }
135+ func (i * Indexer ) LookupDomain (name string ) * Domain {
136+ if domain , ok := i .domains [name ]; ok {
137+ return & domain
151138 }
152139 return nil
153140}
154141
155- func (i * Indexer ) addRecord (domainName string , recordName string , recordType string , value string ) {
156- // Create initial domain record
157- if _ , ok := i .domains [domainName ]; ! ok {
158- i .domains [domainName ] = Domain {
159- name : domainName ,
160- records : make (map [string ]map [string ][]DomainRecord ),
161- }
162- }
163- // Create initial list for record type
164- if _ , ok := i .domains [domainName ].records [recordName ]; ! ok {
165- i .domains [domainName ].records [recordName ] = make (map [string ][]DomainRecord )
166- if _ , ok := i .domains [domainName ].records [recordName ][recordType ]; ! ok {
167- i .domains [domainName ].records [recordName ][recordType ] = make ([]DomainRecord , 0 )
168- }
169- }
170- // Create record
171- i .domains [domainName ].records [recordName ][recordType ] = append (
172- i .domains [domainName ].records [recordName ][recordType ],
173- DomainRecord {
174- Name : recordName ,
175- Value : value ,
176- },
177- )
178- }
179-
180142// GetIndexer returns the global indexer instance
181143func GetIndexer () * Indexer {
182144 return globalIndexer
0 commit comments