p2p/protocol/holepunch library
Package holepunch provides the holepunch service for libp2p.
The holepunch service provides direct connection establishment capabilities for libp2p nodes behind NATs/firewalls. It coordinates hole punching between peers to establish direct connections.
This is a port of the Go implementation from go-libp2p/p2p/protocol/holepunch to Dart, using native Dart idioms.
Classes
- AddrFilter
- Address filter for the holepuncher
- BasicAddrFilter
- Basic address filter implementation for the holepunch protocol
- BasicHolePunchTracer
- Basic tracer implementation for the holepunch protocol
- HolePuncher
- The holepuncher is run on the peer that's behind a NAT / Firewall. It observes new incoming connections via a relay that it has a reservation with, and initiates the DCUtR protocol with them. It then first tries to establish a direct connection, and if that fails, it initiates a hole punch.
- HolePunchOptions
- Options for the holepunch service
- HolePunchResult
- Result of initiating a hole punch
- HolePunchService
- HolePunchService is the interface for the holepunch service.
- HolePunchServiceImpl
- Implementation of the holepunch service
- HolePunchTracer
- Tracer for the holepuncher
- IncomingHolePunchResult
- Result of an incoming hole punch
- MetricsTracer
- Metrics tracer for the holepunch protocol
- NoopAddrFilter
- No-op address filter implementation for the holepunch protocol
Extensions
- HolePunchTracerExt on HolePunchTracer
- Extension for the HolePunchTracer
Constants
- dialTimeout → const Duration
- Dial timeout for hole punching
- maxMsgSize → const int
- Maximum message size for the holepunch protocol
- maxRetries → const int
- Maximum number of retries for hole punching
- protocolId → const String
- Protocol ID for the holepunch protocol
- serviceName → const String
- Service name for the holepunch protocol
- streamTimeout → const Duration
- Stream timeout for the holepunch protocol
Functions
-
addrsFromBytes(
List bytes) → List< MultiAddr> - Converts a list of byte arrays to a list of multiaddrs
-
addrsToBytes(
List< MultiAddr> addrs) → List<Uint8List> - Converts a list of multiaddrs to a list of byte arrays
-
encodeDelimitedMessage(
GeneratedMessage message) → Uint8List - Encodes a protocol buffer message with a varint length prefix for go-libp2p pbio compatibility.
-
getDirectConnection(
Host host, PeerId peerId) → Conn? - Gets a direct (non-relay) connection to a peer if one exists
-
holePunchAddrs(
List< MultiAddr> addrs) → List<MultiAddr> - Keeps the addresses a peer on another network can dial: no relay addresses, and no private or loopback addresses. As in go-libp2p, a hole punch uses public addresses only. A private address is reachable only on its own network, where the peers do not need a hole punch, and a dial to it from another network waits for the full dial timeout.
-
holePunchAttempts(
NATDeviceType udpNatType) → int - How many times to try a hole punch. Behind a symmetric NAT the peer cannot know the port to send to, so a punch works only when the peer's NAT is lenient; one attempt finds that out, and more attempts only spend data and time.
-
isRelayAddress(
MultiAddr addr) → bool - Checks if a multiaddr is a relay address
-
newHolePunchService(
Host host, IDService ids, List< MultiAddr> listenAddrs(), {HolePunchOptions? options}) → Future<HolePunchService> - Creates a new holepunch service.
-
removeRelayAddrs(
List< MultiAddr> addrs) → List<MultiAddr> - Removes relay addresses from a list of multiaddrs
Exceptions / Errors
- ClosedError
- Error thrown when the holepunch service is closed
- HolePunchActiveError
- Error thrown when another hole punching attempt is currently running