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 ¶
HandleQueryFail 查询对等节点失败时的回调函数类型
type HandleQueryResult ¶
HandleQueryResult 查询对等节点成功时的回调函数类型
type Option ¶
type Option func(*options) error
Option DHT爬虫选项类型
func WithConnectTimeout ¶
WithConnectTimeout 定义对等连接超时的时间 参数:
- timeout: time.Duration 超时时间
返回值:
- Option 选项函数
func WithDialAddrExtendDuration ¶
WithDialAddrExtendDuration 设置对等存储中已拨号地址的TTL延长时间。 如果未设置,默认为30分钟。 参数:
- ext: time.Duration 延长时间
返回值:
- Option 选项函数
func WithMsgTimeout ¶
WithMsgTimeout 定义单个DHT消息在被视为失败之前允许花费的时间 参数:
- timeout: time.Duration 超时时间
返回值:
- Option 选项函数
func WithProtocols ¶
WithProtocols 定义爬虫用于与其他节点通信的有序协议集 参数:
- protocols: []protocol.ID 协议ID列表
返回值:
- Option 选项函数
Click to show internal directories.
Click to hide internal directories.