Allow using go-ibp2p with fewer mandatory dependencies
At the moment, simply importing go-libp2p (or a project that uses it, such as spegel) pulls in a VERY large set of indirect dependencies. These dependencies are all used even if only a single transport is enabled with libp2p.ChainOptions(libp2p.NoTransports, libp2p.Transport(tcp.NewTCPTransport))
For example, even if only tcp is used, dependencies for all available transports are pulled in due to all transports being referenced in DefaultTransports variable:
Even if DefaultPrivateTransports and DefaultTransports are modified to avoid importing unwanted transports, it is impossible to avoid pulling in github.com/quic-go/quic-go as the quicreuse transport is baked deeply into the base and config packages:
- https://github.com/libp2p/go-libp2p/blob/e5b7bf00c16698ae661d3e587a4cc8bfa5738666/options.go#L102
- https://github.com/libp2p/go-libp2p/blob/e5b7bf00c16698ae661d3e587a4cc8bfa5738666/libp2p_test.go#L200-L211
- https://github.com/libp2p/go-libp2p/blob/e5b7bf00c16698ae661d3e587a4cc8bfa5738666/config/config.go#L391-L422
Eliminating unused transports (other than quic) saves ~8MB off the size of a simple binary that uses go-libp2p. Eliminating quic when not used would further reduce the size by ~1.6MB.
Ideally the transport abstractions would not leak into the Options and Configs (and tests for same), and the base package would not pull in all transports by default.
Source: libp2p/go-libp2p