Navigate:
go-libp2p
~$GOLI0.1%

go-libp2p: Go implementation of libp2p networking

A modular peer-to-peer networking stack for Go applications, providing transport protocols and network services.

LIVE RANKINGS • 10:11 PM • STEADY
OVERALL
#360
75
CRYPTO
#21
13
30 DAY RANKING TREND
ovr#360
·Crypt#21
STARS
6.7K
FORKS
1.2K
7D STARS
+5
7D FORKS
+5
Tags:
See Repo:
Share:

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.

go-libp2p

1

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.

2

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.

3

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 {}
}


vv0.47.0

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
vv0.46.0

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
vv0.45.0

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


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers