blindhost

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPollerInterval is the default interval at which
	// the poller will poll the server.
	DefaultPollerInterval = 1 * time.Second
)

Variables

View Source
var (
	// ErrInvalidAddress is returned when the blind host address cannot
	// be parsed as a valid address.
	ErrInvalidAddress = errors.New("invalid address")

	// ErrMissingScheme is returned when the blind host address is missing the scheme.
	ErrMissingScheme = errors.New("missing scheme")

	// ErrMissingHost is returned when the blind host address is missing the host.
	ErrMissingHost = errors.New("missing host")

	// ErrAddHost is returned when the client failed to add a host.
	ErrAddHost = errors.New("failed to add host")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client is a client that can interact with the blind host server to add hosts and retrieve interactions.

func NewClient

func NewClient(addr string, opts ...ClientOpt) (*Client, error)

NewClient creates a new Client, ready to use, with the given address and options.

func (*Client) AddHost

func (c *Client) AddHost(ctx context.Context, id HostIdentifier) (err error)

AddHost adds a new interaction host to the blind host server.

func (*Client) GetAllInteractions

func (c *Client) GetAllInteractions(ctx context.Context, id HostIdentifier) (interactions []Interaction, err error)

GetAllInteractions retrieves all the interactions detected for the interaction host with the given HostIdentifier.

func (*Client) GetInteractions

func (c *Client) GetInteractions(ctx context.Context, id HostIdentifier) (interactions []Interaction, err error)

GetInteractions retrieves the new interactions (since last retrieval) detected for the interaction host with the given HostIdentifier.

type ClientOpt

type ClientOpt func(*Client)

ClientOpt is an option to modify a Client.

func WithClient

func WithClient(httpClient *http.Client) ClientOpt

WithClient is a ClientOpt that sets the given *http.Client as the inner client of the Client. If not provided, the default client is the http.DefaultClient.

type HostIdentifier

type HostIdentifier uuid.UUID

HostIdentifier is a unique identifier for an interaction host.

func RandomHostIdentifier

func RandomHostIdentifier() HostIdentifier

RandomHostIdentifier generates a random host identifier by using the Google's UUIDv4 generation library (github.com/google/uuid).

func (HostIdentifier) HostBaseURL

func (h HostIdentifier) HostBaseURL(base string) string

HostBaseURL calculates the base URL of the interaction host, given a base URL.

func (HostIdentifier) HostReqURL

func (h HostIdentifier) HostReqURL(scheme, base, uid string) string

HostReqURL calculates the request URL of the interaction host, given a base URL and a unique identifier. This can be used to uniquely identify each interaction with the interaction host.

func (HostIdentifier) ID

func (h HostIdentifier) ID() string

ID returns the first 8 characters of the interaction host identifier, considered as the id.

func (HostIdentifier) PrivateKey

func (h HostIdentifier) PrivateKey() string

PrivateKey returns the interaction host identifier (UUIDv4) as a string.

type Interaction

type Interaction struct {
	ID            string    `json:"id"`
	Timestamp     time.Time `json:"timestamp"`
	Protocol      string    `json:"protocol"`
	Type          string    `json:"type"`
	RemoteAddress string    `json:"remoteAddress"`
	RawRequest    string    `json:"rawRequest"`
	RawResponse   string    `json:"rawResponse"`
	NRequest      string    `json:"nRequest"`
}

Interaction holds all the information that represents an interaction between an HTTP client and the blind host server.

type Poller

type Poller struct {
	// contains filtered or unexported fields
}

Poller is a poller that polls the server for new interactions every DefaultPollerInterval and keeps them in memory.

func NewPoller

func NewPoller(c *Client, opts ...PollerOpt) (*Poller, error)

NewPoller creates a new poller. It is recommended to use this function instead of creating a poller manually.

The poller will poll the server every DefaultPollerInterval by default.

Use the PollerOpt functions to change the default behaviour.

func (*Poller) BruteSearch

func (p *Poller) BruteSearch(substr string) *Interaction

BruteSearch is like [Search], but searches in all interactions, not just the ones that were polled and kept in memory.

func (*Poller) Close

func (p *Poller) Close()

Close stops the poller. Either use this function or manage a cancellable context yourself.

func (*Poller) Search

func (p *Poller) Search(substr string) *Interaction

Search searches for any interaction that contains the given [substr] in the interaction's request. E.g. in headers, like: Host: [substr]-[id].bh.com.

type PollerOpt

type PollerOpt func(*Poller)

PollerOpt is a function that can be used to change the default behaviour of a poller.

func WithContext

func WithContext(ctx context.Context) PollerOpt

WithContext sets the context of the poller.

func WithHostIdentifier

func WithHostIdentifier(hid HostIdentifier) PollerOpt

WithHostIdentifier sets the host identifier of the poller.

func WithInterval

func WithInterval(dur time.Duration) PollerOpt

WithInterval sets the interval at which the poller will poll the server.

func WithRegistrationDisabled

func WithRegistrationDisabled() PollerOpt

WithRegistrationDisabled disables the poller's host registration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL