p2p

package
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectHost

func ConnectHost(thisHost host.Host, relayHostAddr string) error

当前节点作为客户端连接到指定地址节点 /ip4/{ip}/tcp/{port}/p2p/{peerid}

func ReadBytesFromStream

func ReadBytesFromStream(stream network.Stream) ([]byte, error)

读流

func WriteBytesToStream

func WriteBytesToStream(stream network.Stream, dataBytes []byte) error

写流

Types

type FileDataModel

type FileDataModel struct {
	Success     bool
	Message     string
	ContentType string
	Data        []byte
	Gzip        bool
}

type P2pRelayHost

type P2pRelayHost struct {
	Host host.Host
}

func NewP2pRelayHost

func NewP2pRelayHost(key string, port string) (*P2pRelayHost, error)

新建中继P2P节点

func (*P2pRelayHost) ConnectRelayHost

func (p *P2pRelayHost) ConnectRelayHost(relayHostAddr string) error

当前节点作为客户端连接到中继节点 /ip4/{ip}/tcp/{port}/p2p/{peerid}

func (*P2pRelayHost) HostInfo

func (p *P2pRelayHost) HostInfo() string

节点信息

func (*P2pRelayHost) Regist

func (p *P2pRelayHost) Regist(targetHostAddr string, uri string, dataBytes []byte) ([]byte, error)

【注册】向目标节点发起请求并返回响应结果,地址通常为 /ip4/{ip}/tcp/{port}/p2p/{peerid} 或 /p2p/{relayPeerid}/p2p-circuit/p2p/{peerid} 或 /p2p/{peerid}

func (*P2pRelayHost) Request

func (p *P2pRelayHost) Request(c *fasthttp.RequestCtx, targetHostAddr string, uri string, dataBytes []byte) (int64, error)

【请求】向目标节点发起请求并返回响应结果,地址通常为 /ip4/{ip}/tcp/{port}/p2p/{peerid} 或 /p2p/{relayPeerid}/p2p-circuit/p2p/{peerid} 或 /p2p/{peerid}

func (*P2pRelayHost) SetStreamHandler

func (p *P2pRelayHost) SetStreamHandler(uri string, handler network.StreamHandler)

设定处理器

Jump to

Keyboard shortcuts

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