pnet

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pnet 提供 dep2p 中私有网络的接口。

Index

Constants

View Source
const EnvKey = "LIBP2P_FORCE_PNET"

EnvKey 定义了一个环境变量名称,用于强制在 dep2p 中使用私有网络(PNet) 当此环境变量的值设置为 "1" 时,ForcePrivateNetwork 变量将被设置为 true

Variables

View Source
var ErrNotInPrivateNetwork = NewError("未配置私有网络,但环境要求必须使用私有网络")

ErrNotInPrivateNetwork 当 dep2p 在设置了 ForcePrivateNetwork 但没有 PNet Protector 的情况下尝试拨号时返回此错误

View Source
var ForcePrivateNetwork = false

ForcePrivateNetwork 是一个布尔变量,用于强制在 dep2p 中使用私有网络 将此变量设置为 true 或将 LIBP2P_FORCE_PNET 环境变量设置为 true 将使 dep2p 要求使用私有网络保护器 如果未提供网络保护器且此变量设置为 true,dep2p 将拒绝连接

Functions

func IsPNetError

func IsPNetError(err error) bool

IsPNetError 检查给定的错误是否为 PNet 错误 参数:

  • err: error 需要检查的错误对象

返回值:

  • bool: 如果是 PNet 错误则返回 true,否则返回 false

func NewError

func NewError(err string) error

NewError 创建一个新的 Error 实例 参数:

  • err: string 错误信息字符串

返回值:

  • error: 包装后的 PNet 错误

Types

type Error

type Error interface {
	// IsPNetError 检查是否为 PNet 错误
	IsPNetError() bool
}

Error 是一个接口类型,用于简化 PNet 错误的检测

type PSK

type PSK []byte

PSK 使私有网络实现在 dep2p 中透明化。 它用于确保对等点只能与使用相同 PSK 的其他对等点建立连接。

func DecodeV1PSK

func DecodeV1PSK(in io.Reader) (PSK, error)

DecodeV1PSK 解码 Multicodec 编码的 V1 PSK 参数:

  • in: io.Reader 包含编码 PSK 数据的输入流

返回值:

  • PSK: 解码后的 PSK 密钥
  • error: 如果解码过程中发生错误,返回错误信息

Jump to

Keyboard shortcuts

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