p2pbuilder

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package p2pbuilder 装配 P2P Coordinator:tunnel agent 信令、lifecycle 与 debug 端点。

Package p2pbuilder 装配 P2P Coordinator:tunnel agent 信令、lifecycle 与 debug 端点。

Index

Constants

View Source
const Name = "p2p"

Variables

This section is empty.

Functions

func New

func New(p Params) (p2p.Coordinator, error)

New 创建 P2P 节点:AfterStart 经 tunnel agent 注册信令并 Listen;BeforeStop 释放资源。

Types

type Node

type Node struct {
	Agent       *tunnelagent.Agent
	Coordinator p2p.Coordinator
	Client      *p2p.Client
	// contains filtered or unexported fields
}

Node 是一次性装配出的 P2P 节点句柄,内含 agent + coordinator + client。

func Standalone

func Standalone(ctx context.Context, opts StandaloneOptions) (*Node, error)

Standalone 一行装配可用的 P2P 节点:建 tunnel agent、连接 gateway、 启动信令与 coordinator,并返回带池化/自动重连的 Client。

适合脚本、测试与独立进程;接入 DI/supervisor 时请用 New。 使用完毕调用 Node.Close 释放资源。

func (*Node) Close

func (n *Node) Close() error

Close 释放 Node 持有的全部资源。

type Params

type Params struct {
	LC     lifecycle.Lifecycle
	Config *p2p.Config
	Agent  *tunnelagent.Agent
	PeerID string
	// Metric 可选;非 nil 时上报 P2P 建连指标。
	Metric metrics.Metric
	// ListenOnStart 为 true 时在 AfterStart 自动 Listen(agent 入站 P2P)。
	ListenOnStart bool
}

Params DI 装配参数。

type StandaloneOptions

type StandaloneOptions struct {
	// GatewayAddr tunnel gateway 地址(必填)。
	GatewayAddr string
	// PeerID 本节点 P2P 标识(必填)。
	PeerID string
	// AuthToken tunnel/P2P 鉴权 token。
	AuthToken string
	// ServiceName agent 注册名,默认 "p2p-<PeerID>"。
	ServiceName string
	// Config P2P 配置,nil 时用 DefaultConfig。
	Config *p2p.Config
	// ListenOnStart 为 true 时启动后自动 Listen(接受入站 P2P)。
	ListenOnStart bool
	// Metric 可选指标上报。
	Metric metrics.Metric
}

StandaloneOptions 一次性装配 P2P 节点所需的参数(自建 tunnel agent)。

Jump to

Keyboard shortcuts

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