net

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstTCPAddr

func FirstTCPAddr(h *Host) string

FirstTCPAddr returns the first TCP listen multiaddr of h (with peer ID appended).

func GenerateIdentityB64

func GenerateIdentityB64() (string, error)

func PrivateKeyFromB64

func PrivateKeyFromB64(encoded string) (crypto.PrivKey, error)

Types

type Host

type Host struct {
	Libp2p       host.Host
	Nickname     string
	OnFrame      func(peer.ID, proto.Frame)
	OnFileStream func(peer.ID, proto.Frame, io.Reader)
	OnConnected  func(peer.ID)
	OnLog        func(string)
	// contains filtered or unexported fields
}

func NewHost

func NewHost(ctx context.Context, nickname string) (*Host, error)

func NewHostWithIdentity

func NewHostWithIdentity(ctx context.Context, nickname string, priv crypto.PrivKey) (*Host, error)

func (*Host) AttachDiscovery

func (h *Host) AttachDiscovery(mgr *discovery.Manager)

func (*Host) Close

func (h *Host) Close() error

func (*Host) ConnectByAddr

func (h *Host) ConnectByAddr(ctx context.Context, addrStr string) (PeerInfo, error)

ConnectByAddr connects to a peer by full multiaddr string (e.g., /ip4/1.2.3.4/tcp/4001/p2p/QmXxx)

func (*Host) NicknameFor

func (h *Host) NicknameFor(id peer.ID) string

func (*Host) RememberNickname

func (h *Host) RememberNickname(id peer.ID, nickname string)

func (*Host) SendFrame

func (h *Host) SendFrame(ctx context.Context, peerID peer.ID, frame proto.Frame) error

SendFrame opens a stream to peerID and sends one frame.

func (*Host) StartDHTDiscovery

func (h *Host) StartDHTDiscovery(ctx context.Context, mgr *discovery.Manager)

StartDHTDiscovery advertises on the DHT and periodically finds peers.

func (*Host) StartStreamHandler

func (h *Host) StartStreamHandler()

StartStreamHandler registers the /bdpeer/1.0.0 stream handler.

type PeerInfo

type PeerInfo struct {
	ID       peer.ID
	Nickname string
	Addrs    []multiaddr.Multiaddr
	Source   string
}

Jump to

Keyboard shortcuts

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