Documentation
¶
Index ¶
- func FirstTCPAddr(h *Host) string
- func GenerateIdentityB64() (string, error)
- func PrivateKeyFromB64(encoded string) (crypto.PrivKey, error)
- type BLEWebRTCUpgrader
- type Host
- func (h *Host) AttachDiscovery(mgr *discovery.Manager)
- func (h *Host) Close() error
- func (h *Host) ConnectByAddr(ctx context.Context, addrStr string) (PeerInfo, error)
- func (h *Host) FindByNickname(ctx context.Context, nickname string) (peer.AddrInfo, error)
- func (h *Host) NicknameFor(id peer.ID) string
- func (h *Host) RememberNickname(id peer.ID, nickname string)
- func (h *Host) StartDHTDiscovery(ctx context.Context, mgr *discovery.Manager)
- type PeerInfo
- type WebRTCConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstTCPAddr ¶
FirstTCPAddr returns the best TCP listen multiaddr of h (with peer ID appended). Prefers non-loopback addresses so the displayed address is reachable from other machines.
func GenerateIdentityB64 ¶
Types ¶
type BLEWebRTCUpgrader ¶ added in v0.3.0
type BLEWebRTCUpgrader struct {
TURNServers []config.TURNServer
// OnConnected is called when WebRTC data channel is ready.
// source is "ble→webrtc".
OnConnected func(peerUUID, peerNickname string, conn *WebRTCConn)
OnLog func(string)
// BLE send functions (wired by service layer)
SendOfferFn func(peerUUID, sdp string)
SendAnswerFn func(sdp string) // broadcast to all centrals
// contains filtered or unexported fields
}
BLEWebRTCUpgrader manages WebRTC connection upgrades triggered by BLE discovery. Flow:
Initiator (lower nickname alphabetically): BLE peer found → create offer → send via BLE → receive answer → connected Responder (higher nickname): BLE central subscribed → wait for offer → create answer → send via BLE → connected
func NewBLEWebRTCUpgrader ¶ added in v0.3.0
func NewBLEWebRTCUpgrader(myNickname string) *BLEWebRTCUpgrader
func (*BLEWebRTCUpgrader) OnBLEPeerFound ¶ added in v0.3.0
func (u *BLEWebRTCUpgrader) OnBLEPeerFound(ctx context.Context, peerNickname, peerUUID string)
OnBLEPeerFound is called when BLE discovers a peer. If we are the initiator, create and send an offer.
func (*BLEWebRTCUpgrader) OnSDPReceived ¶ added in v0.3.0
func (u *BLEWebRTCUpgrader) OnSDPReceived(ctx context.Context, peerUUID, sdp string, isOffer bool)
OnSDPReceived handles incoming SDP (offer or answer) from BLE.
type Host ¶
type Host struct {
Libp2p host.Host
Nickname string
OnConnected func(peer.ID)
OnDisconnected func(peer.ID)
OnLog func(string)
// contains filtered or unexported fields
}
func NewHostWithIdentity ¶
func (*Host) AttachDiscovery ¶
func (*Host) ConnectByAddr ¶
ConnectByAddr connects to a peer by full multiaddr string (e.g., /ip4/1.2.3.4/tcp/4001/p2p/QmXxx)
func (*Host) FindByNickname ¶ added in v0.2.8
FindByNickname searches the DHT for a peer advertising under the given nickname.
type WebRTCConn ¶ added in v0.2.11
type WebRTCConn struct {
OnClose func()
// contains filtered or unexported fields
}
WebRTCConn wraps a pion PeerConnection with a reliable data channel. It implements io.ReadWriteCloser so it can carry bdpeer protocol frames. io.Pipe is used for the read path so transfer.ReadFrame (io.ReadFull) works correctly.
func NewWebRTCAnswer ¶ added in v0.2.11
func NewWebRTCAnswer(ctx context.Context, offerSDP string, turnServers []config.TURNServer) (*WebRTCConn, string, error)
NewWebRTCAnswer creates a peer connection from a remote offer and returns an SDP answer.
func NewWebRTCOffer ¶ added in v0.2.11
func NewWebRTCOffer(ctx context.Context, turnServers []config.TURNServer) (*WebRTCConn, string, error)
NewWebRTCOffer creates a peer connection and returns an SDP offer string. Call SetAnswer with the remote answer to complete the handshake.
func (*WebRTCConn) Close ¶ added in v0.2.11
func (c *WebRTCConn) Close() error
func (*WebRTCConn) Connected ¶ added in v0.2.11
func (c *WebRTCConn) Connected() <-chan struct{}
Connected returns a channel that closes when the ICE connection is established.
func (*WebRTCConn) DataChannelOpen ¶ added in v0.4.0
func (c *WebRTCConn) DataChannelOpen() <-chan struct{}
DataChannelOpen returns a channel that closes when the data channel is open and ready for writes. This fires after ICE + DTLS + SCTP handshakes complete — i.e., strictly after Connected(). Callers that write to the conn must wait on this channel before attempting writes to avoid io.ErrClosedPipe.
func (*WebRTCConn) SetAnswer ¶ added in v0.2.11
func (c *WebRTCConn) SetAnswer(answerSDP string) error
SetAnswer completes the offer side handshake with the remote answer SDP.