diff --git a/cmd/cdnsd/main.go b/cmd/cdnsd/main.go index 89a8c8e..caec5ef 100644 --- a/cmd/cdnsd/main.go +++ b/cmd/cdnsd/main.go @@ -98,9 +98,16 @@ func main() { // Start metrics listener if cfg.Metrics.ListenPort > 0 { - metricsListenAddr := fmt.Sprintf("%s:%d", cfg.Metrics.ListenAddress, cfg.Metrics.ListenPort) + metricsListenAddr := fmt.Sprintf( + "%s:%d", + cfg.Metrics.ListenAddress, + cfg.Metrics.ListenPort, + ) slog.Info( - fmt.Sprintf("starting listener for prometheus metrics connections on %s", metricsListenAddr), + fmt.Sprintf( + "starting listener for prometheus metrics connections on %s", + metricsListenAddr, + ), ) metricsMux := http.NewServeMux() metricsMux.Handle("/metrics", promhttp.Handler()) diff --git a/internal/config/config.go b/internal/config/config.go index 68c80ac..52a1c56 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -26,8 +26,8 @@ type Config struct { } type LoggingConfig struct { - Debug bool `yaml:"debug" envconfig:"LOGGING_DEBUG"` - QueryLog bool `yaml:"queryLog" envconfig:"LOGGING_QUERY_LOG"` + Debug bool `yaml:"debug" envconfig:"LOGGING_DEBUG"` + QueryLog bool `yaml:"queryLog" envconfig:"LOGGING_QUERY_LOG"` } type DnsConfig struct { @@ -136,7 +136,8 @@ func Load(configFile string) (*Config, error) { } } // Update intercept slot/hash if earlier than any other profiles so far - if interceptSlot == 0 || profileData.InterceptSlot < interceptSlot { + if interceptSlot == 0 || + profileData.InterceptSlot < interceptSlot { interceptSlot = profileData.InterceptSlot interceptHash = profileData.InterceptHash } @@ -145,7 +146,11 @@ func Load(configFile string) (*Config, error) { } } if !foundProfile { - return nil, fmt.Errorf("unknown profile: %s: available profiles: %s", profile, strings.Join(availableProfiles, ",")) + return nil, fmt.Errorf( + "unknown profile: %s: available profiles: %s", + profile, + strings.Join(availableProfiles, ","), + ) } } // Provide default intercept point from profile(s) diff --git a/internal/dns/dns.go b/internal/dns/dns.go index 63ee575..9ec18fc 100644 --- a/internal/dns/dns.go +++ b/internal/dns/dns.go @@ -109,7 +109,10 @@ func handleQuery(w dns.ResponseWriter, r *dns.Msg) { tmpRR, err := stateRecordToDnsRR(tmpRecord) if err != nil { slog.Error( - fmt.Sprintf("failed to convert state record to dns.RR: %s", err), + fmt.Sprintf( + "failed to convert state record to dns.RR: %s", + err, + ), ) return } @@ -367,7 +370,8 @@ func findNameserversForDomain( lookupDomainName := strings.Join(queryLabels[startLabelIdx:], ".") // Convert to canonical form for consistency lookupDomainName = dns.CanonicalName(lookupDomainName) - nsRecords, err := state.GetState().LookupRecords([]string{"NS"}, lookupDomainName) + nsRecords, err := state.GetState(). + LookupRecords([]string{"NS"}, lookupDomainName) if err != nil { return "", nil, err } @@ -375,12 +379,16 @@ func findNameserversForDomain( ret := map[string][]net.IP{} for _, nsRecord := range nsRecords { // Get matching A/AAAA records for NS entry - aRecords, err := state.GetState().LookupRecords([]string{"A", "AAAA"}, nsRecord.Rhs) + aRecords, err := state.GetState(). + LookupRecords([]string{"A", "AAAA"}, nsRecord.Rhs) if err != nil { return "", nil, err } for _, aRecord := range aRecords { - ret[nsRecord.Rhs] = append(ret[nsRecord.Rhs], net.ParseIP(aRecord.Rhs)) + ret[nsRecord.Rhs] = append( + ret[nsRecord.Rhs], + net.ParseIP(aRecord.Rhs), + ) } } return dns.Fqdn(lookupDomainName), ret, nil diff --git a/internal/indexer/datum.go b/internal/indexer/datum.go index 8bb2094..c2b74d6 100644 --- a/internal/indexer/datum.go +++ b/internal/indexer/datum.go @@ -27,22 +27,34 @@ func (d *DNSReferenceRefScriptDatum) UnmarshalCBOR(cborData []byte) error { return err } if tmpData.Constructor() != 3 { - return fmt.Errorf("unexpected outer constructor index: %d", tmpData.Constructor()) + return fmt.Errorf( + "unexpected outer constructor index: %d", + tmpData.Constructor(), + ) } tmpDataFields := tmpData.Fields() if len(tmpDataFields) != 1 { - return fmt.Errorf("unexpected inner field count: expected 1, got %d", len(tmpDataFields)) + return fmt.Errorf( + "unexpected inner field count: expected 1, got %d", + len(tmpDataFields), + ) } fieldInner, ok := tmpDataFields[0].(cbor.Constructor) if !ok { - return fmt.Errorf("unexpected data type %T for outer constructor field", tmpDataFields[0]) + return fmt.Errorf( + "unexpected data type %T for outer constructor field", + tmpDataFields[0], + ) } var tmpDataInner cbor.Constructor if _, err := cbor.Decode(fieldInner.Cbor(), &tmpDataInner); err != nil { return err } if tmpDataInner.Constructor() != 1 { - return fmt.Errorf("unexpected inner constructor index: %d", tmpDataInner.Constructor()) + return fmt.Errorf( + "unexpected inner constructor index: %d", + tmpDataInner.Constructor(), + ) } return cbor.DecodeGeneric(tmpDataInner.FieldsCbor(), d) } diff --git a/internal/indexer/indexer.go b/internal/indexer/indexer.go index 6e2876b..e16fa7d 100644 --- a/internal/indexer/indexer.go +++ b/internal/indexer/indexer.go @@ -235,7 +235,8 @@ func (i *Indexer) handleEvent(evt event.Event) error { } for _, watchedAddr := range i.watched { if watchedAddr.Discovery { - if outAddr.String() == watchedAddr.Address || outAddrPayment.String() == watchedAddr.Address { + if outAddr.String() == watchedAddr.Address || + outAddrPayment.String() == watchedAddr.Address { if err := i.handleEventOutputDiscovery(eventCtx, watchedAddr.PolicyId, txOutput); err != nil { return err } @@ -254,7 +255,12 @@ func (i *Indexer) handleEvent(evt event.Event) error { return nil } -func (i *Indexer) handleEventOutputDns(eventCtx input_chainsync.TransactionContext, tldName string, policyId string, txOutput ledger.TransactionOutput) error { +func (i *Indexer) handleEventOutputDns( + eventCtx input_chainsync.TransactionContext, + tldName string, + policyId string, + txOutput ledger.TransactionOutput, +) error { cfg := config.GetConfig() datum := txOutput.Datum() if datum != nil { @@ -364,7 +370,11 @@ func (i *Indexer) handleEventOutputDns(eventCtx input_chainsync.TransactionConte return nil } -func (i *Indexer) handleEventOutputDiscovery(eventCtx input_chainsync.TransactionContext, policyId string, txOutput ledger.TransactionOutput) error { +func (i *Indexer) handleEventOutputDiscovery( + eventCtx input_chainsync.TransactionContext, + policyId string, + txOutput ledger.TransactionOutput, +) error { cfg := config.GetConfig() datum := txOutput.Datum() if datum != nil { diff --git a/internal/state/state.go b/internal/state/state.go index edbaf73..7f81230 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -281,12 +281,21 @@ func (s *State) UpdateDomain( return err } -func (s *State) LookupRecords(recordTypes []string, recordName string) ([]DomainRecord, error) { +func (s *State) LookupRecords( + recordTypes []string, + recordName string, +) ([]DomainRecord, error) { ret := []DomainRecord{} recordName = strings.Trim(recordName, `.`) err := s.db.View(func(txn *badger.Txn) error { for _, recordType := range recordTypes { - keyPrefix := []byte(fmt.Sprintf("r_%s_%s_", strings.ToUpper(recordType), recordName)) + keyPrefix := []byte( + fmt.Sprintf( + "r_%s_%s_", + strings.ToUpper(recordType), + recordName, + ), + ) it := txn.NewIterator(badger.DefaultIteratorOptions) defer it.Close() for it.Seek(keyPrefix); it.ValidForPrefix(keyPrefix); it.Next() {