Skip to content

Commit

Permalink
fix ptr session issue resulting in invalid host message.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Apr 29, 2024
1 parent c03e8c7 commit db3e305
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions providers/ptr/ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"strings"
"time"

"github.com/hashicorp/go-retryablehttp"

"github.com/jonhadfield/ipscout/providers"

"github.com/miekg/dns"
Expand All @@ -32,8 +30,7 @@ const (
)

type Client struct {
Config Config
HTTPClient *retryablehttp.Client
session.Session
}

type Config struct {
Expand All @@ -46,10 +43,11 @@ type Config struct {
func NewProviderClient(c session.Session) (providers.ProviderClient, error) {
c.Logger.Debug("creating ptr client")

return &Client{
Config: Config{Session: c},
HTTPClient: c.HTTPClient,
}, nil
tc := Client{
c,
}

return &tc, nil
}

type Provider interface {
Expand All @@ -58,54 +56,54 @@ type Provider interface {
}

func (c *Client) Enabled() bool {
return c.Config.Providers.PTR.Enabled
return c.Session.Providers.PTR.Enabled
}

func (c *Client) GetConfig() *session.Session {
return &c.Config.Session
return &c.Session
}

func (c *Client) Initialise() error {
if c.Config.Cache == nil {
if c.Session.Cache == nil {
return errors.New("cache not set")
}

start := time.Now()
defer func() {
c.Config.Stats.Mu.Lock()
c.Config.Stats.InitialiseDuration[ProviderName] = time.Since(start)
c.Config.Stats.Mu.Unlock()
c.Session.Stats.Mu.Lock()
c.Session.Stats.InitialiseDuration[ProviderName] = time.Since(start)
c.Session.Stats.Mu.Unlock()
}()

c.Config.Logger.Debug("initialising ptr client")
c.Session.Logger.Debug("initialising ptr client")

return nil
}

func (c *Client) FindHost() ([]byte, error) {
start := time.Now()
defer func() {
c.Config.Stats.Mu.Lock()
c.Config.Stats.FindHostDuration[ProviderName] = time.Since(start)
c.Config.Stats.Mu.Unlock()
c.Session.Stats.Mu.Lock()
c.Session.Stats.FindHostDuration[ProviderName] = time.Since(start)
c.Session.Stats.Mu.Unlock()
}()

result, err := fetchData(c.Config.Session)
result, err := fetchData(c.Session)
if err != nil {
return nil, err
}

c.Config.Logger.Debug("ptr host match data", "size", len(result.Raw))
c.Session.Logger.Debug("ptr host match data", "size", len(result.Raw))

return result.Raw, nil
}

func (c *Client) CreateTable(data []byte) (*table.Writer, error) {
start := time.Now()
defer func() {
c.Config.Stats.Mu.Lock()
c.Config.Stats.CreateTableDuration[ProviderName] = time.Since(start)
c.Config.Stats.Mu.Unlock()
c.Session.Stats.Mu.Lock()
c.Session.Stats.CreateTableDuration[ProviderName] = time.Since(start)
c.Session.Stats.Mu.Unlock()
}()

var findHostData *Data
Expand Down Expand Up @@ -133,9 +131,9 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) {
tw.SetAutoIndex(false)
// tw.SetStyle(table.StyleColoredDark)
// tw.Style().Options.DrawBorder = true
tw.SetTitle("PTR | Host: %s", c.Config.Host.String())

c.Config.Logger.Debug("ptr table created", "host", c.Config.Host.String())
tw.SetTitle("PTR | Host: %s", c.Session.Host.String())
fmt.Printf("Host: %s\n", c.Session.Host)
c.Session.Logger.Debug("ptr table created", "host", c.Session.Host.String())

return &tw, nil
}
Expand Down

0 comments on commit db3e305

Please sign in to comment.