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 {}
}Bug fixes and dependency updates including autonatv2 reachability improvements and host connection handling.
- –Fixed autonatv2: secondary addrs inherit reachability from primary
- –Fixed basic_host: stream.Close() blocks indefinitely on unresponsive peers
- –Fixed handle error from mh.Sum in IDFromPublicKey
- –Update simnet
Updated QUIC dependencies and fixed WebRTC logging and mDNS packet size issues.
- –Fixed webrtc: use debug level for pion errors
- –Updated quic-go to v0.57.1
- –Fixed mdns: filter addresses to reduce packet size
A small release that adjust some noisy logging levels and adds a method for dynamically change the slog Handler for better integration with applications.
- –Fixed websocket: use debug level for operational noise errors
- –Added SetDefaultHandler for gologshim
- –Update Drips ownedBy address in FUNDING.json
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.