crawler

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Crawler

type Crawler interface {
	// Run 从startingPeers开始爬取DHT,根据是否成功联系到对等节点调用handleSuccess或handleFail
	// 参数:
	//   - ctx: context.Context 上下文
	//   - startingPeers: []*peer.AddrInfo 起始对等节点列表
	//   - handleSuccess: HandleQueryResult 查询成功的回调函数
	//   - handleFail: HandleQueryFail 查询失败的回调函数
	Run(ctx context.Context, startingPeers []*peer.AddrInfo, handleSuccess HandleQueryResult, handleFail HandleQueryFail)
}

Crawler 连接到DHT中的主机以跟踪对等节点的路由表

type DefaultCrawler

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

DefaultCrawler 提供Crawler接口的默认实现

func NewDefaultCrawler

func NewDefaultCrawler(host host.Host, opts ...Option) (*DefaultCrawler, error)

NewDefaultCrawler 创建一个新的DefaultCrawler 参数:

  • host: host.Host libp2p主机
  • opts: ...Option 配置选项

返回值:

  • *DefaultCrawler 爬虫实例
  • error 错误信息

func (*DefaultCrawler) Run

func (c *DefaultCrawler) Run(ctx context.Context, startingPeers []*peer.AddrInfo, handleSuccess HandleQueryResult, handleFail HandleQueryFail)

Run 从初始种子startingPeers开始爬取DHT对等节点 参数:

  • ctx: context.Context 上下文
  • startingPeers: []*peer.AddrInfo 起始对等节点列表
  • handleSuccess: HandleQueryResult 查询成功的回调函数
  • handleFail: HandleQueryFail 查询失败的回调函数

type HandleQueryFail

type HandleQueryFail func(p peer.ID, err error)

HandleQueryFail 查询对等节点失败时的回调函数类型

type HandleQueryResult

type HandleQueryResult func(p peer.ID, rtPeers []*peer.AddrInfo)

HandleQueryResult 查询对等节点成功时的回调函数类型

type Option

type Option func(*options) error

Option DHT爬虫选项类型

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

WithConnectTimeout 定义对等连接超时的时间 参数:

  • timeout: time.Duration 超时时间

返回值:

  • Option 选项函数

func WithDialAddrExtendDuration

func WithDialAddrExtendDuration(ext time.Duration) Option

WithDialAddrExtendDuration 设置对等存储中已拨号地址的TTL延长时间。 如果未设置,默认为30分钟。 参数:

  • ext: time.Duration 延长时间

返回值:

  • Option 选项函数

func WithMsgTimeout

func WithMsgTimeout(timeout time.Duration) Option

WithMsgTimeout 定义单个DHT消息在被视为失败之前允许花费的时间 参数:

  • timeout: time.Duration 超时时间

返回值:

  • Option 选项函数

func WithParallelism

func WithParallelism(parallelism int) Option

WithParallelism 定义可以并行发出的查询数量 参数:

  • parallelism: int 并行度

返回值:

  • Option 选项函数

func WithProtocols

func WithProtocols(protocols []protocol.ID) Option

WithProtocols 定义爬虫用于与其他节点通信的有序协议集 参数:

  • protocols: []protocol.ID 协议ID列表

返回值:

  • Option 选项函数

Jump to

Keyboard shortcuts

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