import { noise } from '@chainsafe/libp2p-noise';
import { yamux } from '@chainsafe/libp2p-yamux';
import { delegatedHTTPRoutingDefaults } from '@helia/delegated-routing-client';
import { delegatedRoutingV1HttpApiClientContentRouting, delegatedRoutingV1HttpApiClientPeerRouting } from '@helia/delegated-routing-v1-http-api-client';
import { autoTLS } from '@ipshipyard/libp2p-auto-tls';
import { autoNAT } from '@libp2p/autonat';
import { bootstrap } from '@libp2p/bootstrap';
import { circuitRelayTransport, circuitRelayServer } from '@libp2p/circuit-relay-v2';
import { dcutr } from '@libp2p/dcutr';
import { http } from '@libp2p/http';
import { identify, identifyPush } from '@libp2p/identify';
import { kadDHT } from '@libp2p/kad-dht';
import { keychain } from '@libp2p/keychain';
import { mdns } from '@libp2p/mdns';
import { mplex } from '@libp2p/mplex';
import { ping } from '@libp2p/ping';
import { tcp } from '@libp2p/tcp';
import { tls } from '@libp2p/tls';
import { uPnPNAT } from '@libp2p/upnp-nat';
import { webRTC, webRTCDirect } from '@libp2p/webrtc';
import { webSockets } from '@libp2p/websockets';
import { userAgent } from 'libp2p/user-agent';
import { bootstrapConfig } from "./bootstrappers.js";
/**
 * Returns the default libp2p config used by Helia which can then be modified or
 * extended to suit individual applications.
 *
 * @example Adding an additional libp2p service
 *
 * ```ts
 * import { myService } from '@example/my-service'
 * import { createHelia, libp2pDefaults } from 'helia'
 *
 * // get a copy of the default libp2p config
 * const libp2p = libp2pDefaults()
 *
 * // add the custom service to the service map
 * libp2p.services.myService = myService()
 *
 * // create a Helia node with the custom libp2p config
 * const helia = await createHelia({
 *   libp2p
 * })
 *
 * //... use service
 * helia.libp2p.services.myService.serviceMethod()
 * ```
 */
export function libp2pDefaults(options = {}) {
    let agentVersion;
    if (options.name != null && options.version != null) {
        agentVersion = `${options.name}/${options.version} ${userAgent()}`;
    }
    return {
        privateKey: options.privateKey,
        dns: options.dns,
        nodeInfo: {
            userAgent: agentVersion
        },
        addresses: {
            listen: [
                '/ip4/0.0.0.0/tcp/0',
                '/ip4/0.0.0.0/tcp/0/ws',
                '/ip4/0.0.0.0/udp/0/webrtc-direct',
                '/ip6/::/tcp/0',
                '/ip6/::/tcp/0/ws',
                '/ip6/::/udp/0/webrtc-direct',
                '/p2p-circuit'
            ]
        },
        transports: [
            circuitRelayTransport(),
            tcp(),
            webRTC(),
            webRTCDirect(),
            webSockets()
        ],
        connectionEncrypters: [
            noise(),
            tls()
        ],
        streamMuxers: [
            yamux(),
            mplex()
        ],
        peerDiscovery: [
            mdns(),
            bootstrap(bootstrapConfig)
        ],
        services: {
            autoNAT: autoNAT(),
            autoTLS: autoTLS(),
            dcutr: dcutr(),
            delegatedPeerRouting: delegatedRoutingV1HttpApiClientPeerRouting(delegatedHTTPRoutingDefaults()),
            delegatedContentRouting: delegatedRoutingV1HttpApiClientContentRouting(delegatedHTTPRoutingDefaults()),
            dht: kadDHT(),
            identify: identify(),
            identifyPush: identifyPush(),
            keychain: keychain(options.keychain),
            ping: ping(),
            relay: circuitRelayServer(),
            upnp: uPnPNAT(),
            http: http()
        }
    };
}
//# sourceMappingURL=libp2p-defaults.js.map