package gostream
import "github.com/libp2p/go-libp2p/p2p/net/gostream"
Package gostream allows to replace the standard net stack in Go with [LibP2P](https://github.com/libp2p/libp2p) streams.
Given a libp2p.Host, gostream provides Dial() and Listen() methods which return implementations of net.Conn and net.Listener.
Instead of the regular "host:port" addressing, `gostream` uses a Peer ID, and rather than a raw TCP connection, gostream will use libp2p's net.Stream. This means your connections will take advantage of LibP2P's multi-routes, NAT transversal and stream multiplexing.
Note that LibP2P hosts cannot dial to themselves, so there is no possibility of using the same Host as server and as client.
Index ¶
- Variables
- func Dial(ctx context.Context, h host.Host, pid peer.ID, tag protocol.ID) (net.Conn, error)
- func Listen(h host.Host, tag protocol.ID, opts ...ListenerOption) (net.Listener, error)
- type ListenerOption
Variables ¶
var Network = "libp2p"
Network is the "net.Addr.Network()" name returned by addresses used by gostream connections. In turn, the "net.Addr.String()" will be a peer ID.
Functions ¶
func Dial ¶
Dial opens a stream to the destination address (which should parseable to a peer ID) using the given host and returns it as a standard net.Conn.
func Listen ¶
Listen provides a standard net.Listener ready to accept "connections". Under the hood, these connections are libp2p streams tagged with the given protocol.ID.
Types ¶
type ListenerOption ¶
type ListenerOption func(*listener) error
func IgnoreEOF ¶
func IgnoreEOF() ListenerOption
Source Files ¶
addr.go conn.go gostream.go listener.go
- Version
- v0.42.0 (latest)
- Published
- Jun 18, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 4 weeks ago –
Tools for package owners.