db

package
v0.0.0-...-23d3fd2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyAgentVersion = fmt.Errorf("empty agent version")
	ErrEmptyProtocol     = fmt.Errorf("empty protocol")
	ErrEmptyProtocolsSet = fmt.Errorf("empty protocols set")
)
View Source
var KnownErrors = map[string]string{
	models.NetErrorIoTimeout:                  "i/o timeout",
	models.NetErrorNoRecentNetworkActivity:    "no recent network activity",
	models.NetErrorConnectionRefused:          "connection refused",
	models.NetErrorProtocolNotSupported:       "protocol not supported",
	models.NetErrorPeerIDMismatch:             "peer id mismatch",
	models.NetErrorNoRouteToHost:              "no route to host",
	models.NetErrorNetworkUnreachable:         "network is unreachable",
	models.NetErrorNoGoodAddresses:            "no good addresses",
	models.NetErrorContextDeadlineExceeded:    "context deadline exceeded",
	models.NetErrorNoPublicIP:                 "no public IP address",
	models.NetErrorMaxDialAttemptsExceeded:    "max dial attempts exceeded",
	models.NetErrorHostIsDown:                 "host is down",
	models.NetErrorStreamReset:                "stream reset",
	models.NetErrorNegotiateSecurityProtocol:  "failed to negotiate security protocol",
	models.NetErrorNegotiateStreamMultiplexer: "failed to negotiate stream multiplexer",
	models.NetErrorResourceLimitExceeded:      "resource limit exceeded",
	models.NetErrorWriteOnStream:              "Write on stream",
}

KnownErrors contains a list of known errors. Property key + string to match for

Functions

func NetError

func NetError(err error) string

NetError extracts the appropriate error type from the given error.

func Rollback

func Rollback(txn *sql.Tx)

Rollback calls rollback on the given transaction and logs the potential error.

Types

type Client

type Client interface {
	QueryBootstrapPeers(ctx context.Context, limit int) ([]peer.AddrInfo, error)
	InitCrawl(ctx context.Context) (*models.Crawl, error)
	UpdateCrawl(ctx context.Context, crawl *models.Crawl) error
	PersistCrawlProperties(ctx context.Context, crawl *models.Crawl, properties map[string]map[string]int) error
	PersistCrawlVisit(ctx context.Context, crawlID int, peerID peer.ID, maddrs []ma.Multiaddr, protocols []string, agentVersion string, connectDuration time.Duration, crawlDuration time.Duration, visitStartedAt time.Time, visitEndedAt time.Time, connectErrorStr string, crawlErrorStr string, isExposed null.Bool) (*InsertVisitResult, error)
	PersistNeighbors(ctx context.Context, crawl *models.Crawl, dbPeerID *int, peerID peer.ID, errorBits uint16, dbNeighborsIDs []int, neighbors []peer.ID) error
}

func InitJSONClient

func InitJSONClient(ctx context.Context, out string) (Client, error)

InitJSONClient .

type DBClient

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

func InitDBClient

func InitDBClient(ctx context.Context, conf *config.Root) (*DBClient, error)

InitDBClient establishes a database connection with the provided configuration and applies any pending migrations

func (*DBClient) Close

func (c *DBClient) Close() error

func (*DBClient) FetchDueOpenSessions

func (c *DBClient) FetchDueOpenSessions(ctx context.Context) (models.SessionsOpenSlice, error)

FetchDueOpenSessions fetches all open sessions from the database that are due.

func (*DBClient) FetchUnresolvedMultiAddresses

func (c *DBClient) FetchUnresolvedMultiAddresses(ctx context.Context, limit int) (models.MultiAddressSlice, error)

FetchUnresolvedMultiAddresses fetches all multi addresses that were not resolved yet.

func (*DBClient) GetOrCreateAgentVersionID

func (c *DBClient) GetOrCreateAgentVersionID(ctx context.Context, exec boil.ContextExecutor, agentVersion string) (*int, error)

func (*DBClient) GetOrCreateProtocol

func (c *DBClient) GetOrCreateProtocol(ctx context.Context, exec boil.ContextExecutor, protocol string) (*int, error)

func (*DBClient) GetOrCreateProtocolsSetID

func (c *DBClient) GetOrCreateProtocolsSetID(ctx context.Context, exec boil.ContextExecutor, protocols []string) (*int, error)

func (*DBClient) Handle

func (c *DBClient) Handle() *sql.DB

func (*DBClient) InitCrawl

func (c *DBClient) InitCrawl(ctx context.Context) (*models.Crawl, error)

InitCrawl inserts a crawl instance into the database in the state `started`. This is done to receive a database ID that all subsequent database entities can be linked to.

func (*DBClient) PersistCrawlProperties

func (c *DBClient) PersistCrawlProperties(ctx context.Context, crawl *models.Crawl, properties map[string]map[string]int) error

func (*DBClient) PersistCrawlVisit

func (c *DBClient) PersistCrawlVisit(
	ctx context.Context,
	crawlID int,
	peerID peer.ID,
	maddrs []ma.Multiaddr,
	protocols []string,
	agentVersion string,
	connectDuration time.Duration,
	crawlDuration time.Duration,
	visitStartedAt time.Time,
	visitEndedAt time.Time,
	connectErrorStr string,
	crawlErrorStr string,
	isExposed null.Bool,
) (*InsertVisitResult, error)

func (*DBClient) PersistDialVisit

func (c *DBClient) PersistDialVisit(
	peerID peer.ID,
	maddrs []ma.Multiaddr,
	dialDuration time.Duration,
	visitStartedAt time.Time,
	visitEndedAt time.Time,
	errorStr string,
) (*InsertVisitResult, error)

func (*DBClient) PersistNeighbors

func (c *DBClient) PersistNeighbors(ctx context.Context, crawl *models.Crawl, dbPeerID *int, peerID peer.ID, errorBits uint16, dbNeighborsIDs []int, neighbors []peer.ID) error

func (*DBClient) QueryBootstrapPeers

func (c *DBClient) QueryBootstrapPeers(ctx context.Context, limit int) ([]peer.AddrInfo, error)

func (*DBClient) UpdateCrawl

func (c *DBClient) UpdateCrawl(ctx context.Context, crawl *models.Crawl) error

UpdateCrawl takes the crawl model an updates it in the database.

func (*DBClient) UpsertPeer

func (c *DBClient) UpsertPeer(mh string, agentVersionID null.Int, protocolSetID null.Int, isExposed null.Bool) (int, error)

type InsertVisitResult

type InsertVisitResult struct {
	PID       peer.ID
	PeerID    *int
	VisitID   *int
	SessionID *int
}

func (*InsertVisitResult) Scan

func (ivr *InsertVisitResult) Scan(value interface{}) error

type JSONClient

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

func (*JSONClient) InitCrawl

func (c *JSONClient) InitCrawl(ctx context.Context) (*models.Crawl, error)

func (*JSONClient) PersistCrawlProperties

func (c *JSONClient) PersistCrawlProperties(ctx context.Context, crawl *models.Crawl, properties map[string]map[string]int) error

func (*JSONClient) PersistCrawlVisit

func (c *JSONClient) PersistCrawlVisit(ctx context.Context, crawlID int, peerID peer.ID, maddrs []ma.Multiaddr, protocols []string, agentVersion string, connectDuration time.Duration, crawlDuration time.Duration, visitStartedAt time.Time, visitEndedAt time.Time, connectErrorStr string, crawlErrorStr string, isExposed null.Bool) (*InsertVisitResult, error)

func (*JSONClient) PersistNeighbors

func (c *JSONClient) PersistNeighbors(ctx context.Context, crawl *models.Crawl, dbPeerID *int, peerID peer.ID, errorBits uint16, dbNeighborsIDs []int, neighbors []peer.ID) error

func (*JSONClient) QueryBootstrapPeers

func (c *JSONClient) QueryBootstrapPeers(ctx context.Context, limit int) ([]peer.AddrInfo, error)

func (*JSONClient) UpdateCrawl

func (c *JSONClient) UpdateCrawl(ctx context.Context, crawl *models.Crawl) error

type JSONNeighbors

type JSONNeighbors struct {
	PeerID      peer.ID
	NeighborIDs []peer.ID
	ErrorBits   string
}

type JSONVisit

type JSONVisit struct {
	PeerID          peer.ID
	Maddrs          []ma.Multiaddr
	Protocols       []string
	AgentVersion    string
	ConnectDuration string
	CrawlDuration   string
	VisitStartedAt  time.Time
	VisitEndedAt    time.Time
	ConnectErrorStr string
	CrawlErrorStr   string
	IsExposed       null.Bool
}

Jump to

Keyboard shortcuts

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