Skip to content

Commit

Permalink
chore: golines (#200)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 authored Aug 31, 2024
1 parent 03fdc76 commit 070355e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
11 changes: 9 additions & 2 deletions cmd/cdnsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
13 changes: 9 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions internal/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -367,20 +370,25 @@ 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
}
if len(nsRecords) > 0 {
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
Expand Down
20 changes: 16 additions & 4 deletions internal/indexer/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 13 additions & 3 deletions internal/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 070355e

Please sign in to comment.