go-libp2p: Go implementation of libp2p networking
A modular peer-to-peer networking stack for Go applications, providing transport protocols and network services.
Learn more about go-libp2p
go-libp2p is the Go implementation of the libp2p networking stack, a modular protocol suite originally developed for IPFS. It provides a collection of protocols and components for building peer-to-peer applications, including transport layers, connection multiplexing, and peer discovery mechanisms. The library follows a modular architecture where applications can select only the protocols they need while maintaining interoperability. It serves as the foundation for distributed systems like IPFS, Filecoin, and various blockchain networks.
Modular Architecture
Applications can compose only the networking protocols they need from a comprehensive suite of components. This approach reduces complexity while maintaining full interoperability with other libp2p implementations.
Protocol Agnostic
Supports multiple transport protocols including TCP, QUIC, and WebSockets with automatic protocol negotiation. The stack can adapt to different network conditions and requirements dynamically.
Production Ready
Used by major distributed systems including Kubo (IPFS), Filecoin's Lotus, and Ethereum's Prysm consensus client. Includes monitoring dashboards and comprehensive testing infrastructure for production deployments.
package main
import (
"context"
"fmt"
"log"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
)
func main() {
ctx := context.Background()
// Create a libp2p host with default settings
node, err := libp2p.New(
libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"),
)
if err != nil {
log.Fatal(err)
}
defer node.Close()
// Print the node's peer ID and listening addresses
fmt.Printf("Peer ID: %s\n", node.ID())
fmt.Println("Listening addresses:")
for _, addr := range node.Addrs() {
fmt.Printf(" %s/p2p/%s\n", addr, node.ID())
}
// Connect to another peer (example address)
targetAddr, _ := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/4001/p2p/QmSomePeerID")
peerInfo, _ := peer.AddrInfoFromP2pAddr(targetAddr)
err = node.Connect(ctx, *peerInfo)
if err != nil {
fmt.Printf("Failed to connect: %v\n", err)
} else {
fmt.Printf("Connected to peer: %s\n", peerInfo.ID)
}
// Keep the program running
select {}
}A relatively small release. The main changes are dependency updates and a couple of bug fixes. #3435 changes autonatv2 reachability logic, which shoul
- –fix(autonatv2): secondary addrs inherit reachability from primary by @lidel in
- –Update simnet by @MarcoPolo in
- –mod tidy test-plans package by @MarcoPolo in
- –fix(basic_host): `stream.Close()` blocks indefinitely on unresponsive peers by @lidel in
- –fix: handle error from mh.Sum in IDFromPublicKey by @MozirDmitriy in
v0.46.0: fix(webrtc): use debug level for pion errors by @lidel in
- –fix(webrtc): use debug level for pion errors by @lidel in
- –chore: update quic-go to v0.56.0 by @sukunrt in
- –fix(mdns): filter addresses to reduce packet size by @lidel in
- –chore: update quic-go to v0.57.1 by @sukunrt in
A small release that adjust some noisy logging levels and adds a method for dynamically change the slog Handler for better integration with applicatio
- –fix(websocket): use debug level for operational noise errors by @lidel in
- –chore: Update Drips ownedBy address in FUNDING.json by @p-shahi in
- –feat(gologshim): Add SetDefaultHandler by @lidel in
Related Repositories
Discover similar tools and frameworks used by developers
Foundry
A modular toolkit for Ethereum application development that includes compilation, testing, and deployment tools.
Bitcoin Core
Reference implementation of the Bitcoin protocol that connects to the peer-to-peer network for block validation.
Go Ethereum
Golang execution layer implementation of the Ethereum protocol, providing the geth client and developer tools.
Dogecoin Core
Open-source software for Dogecoin blockchain nodes with wallet and network participation.
Hyperledger Fabric
Modular enterprise blockchain framework with permissioned networks, pluggable consensus, and privacy controls.