import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxerFactory, Upgrader as UpgraderInterface, UpgraderOptions, ConnectionLimits, SecureConnectionOptions, ClearableSignal } from '@libp2p/interface';
import type { ConnectionManager, Registrar } from '@libp2p/interface-internal';
interface CreateConnectionOptions {
    cryptoProtocol: string;
    direction: 'inbound' | 'outbound';
    maConn: MultiaddrConnection;
    upgradedConn: MultiaddrConnection;
    remotePeer: PeerId;
    muxerFactory?: StreamMuxerFactory;
    limits?: ConnectionLimits;
}
interface OnStreamOptions {
    connection: Connection;
    stream: Stream;
    protocol: string;
}
export interface CryptoResult extends SecuredConnection<MultiaddrConnection> {
    protocol: string;
}
export interface UpgraderInit {
    connectionEncrypters: ConnectionEncrypter[];
    streamMuxers: StreamMuxerFactory[];
    /**
     * An amount of ms by which an inbound connection upgrade must complete
     *
     * @default 3000
     */
    inboundUpgradeTimeout?: number;
    /**
     * When a new incoming stream is opened on a multiplexed connection, protocol
     * negotiation on that stream must complete within this many ms
     *
     * @default 2000
     */
    inboundStreamProtocolNegotiationTimeout?: number;
    /**
     * When a new incoming stream is opened on a multiplexed connection, protocol
     * negotiation on that stream must complete within this many ms
     *
     * @default 2000
     */
    outboundStreamProtocolNegotiationTimeout?: number;
}
export interface UpgraderComponents {
    peerId: PeerId;
    metrics?: Metrics;
    connectionManager: ConnectionManager;
    connectionGater: ConnectionGater;
    connectionProtector?: ConnectionProtector;
    registrar: Registrar;
    peerStore: PeerStore;
    events: TypedEventTarget<Libp2pEvents>;
    logger: ComponentLogger;
}
type ConnectionDeniedType = keyof Pick<ConnectionGater, 'denyOutboundConnection' | 'denyInboundEncryptedConnection' | 'denyOutboundEncryptedConnection' | 'denyInboundUpgradedConnection' | 'denyOutboundUpgradedConnection'>;
export declare class Upgrader implements UpgraderInterface {
    private readonly components;
    private readonly connectionEncrypters;
    private readonly streamMuxers;
    private readonly inboundUpgradeTimeout;
    private readonly inboundStreamProtocolNegotiationTimeout;
    private readonly outboundStreamProtocolNegotiationTimeout;
    private readonly events;
    private readonly metrics;
    constructor(components: UpgraderComponents, init: UpgraderInit);
    readonly [Symbol.toStringTag] = "@libp2p/upgrader";
    shouldBlockConnection(connectionType: 'denyInboundConnection', maConn: MultiaddrConnection): Promise<void>;
    shouldBlockConnection(connectionType: ConnectionDeniedType, remotePeer: PeerId, maConn: MultiaddrConnection): Promise<void>;
    createInboundAbortSignal(signal: AbortSignal): ClearableSignal;
    /**
     * Upgrades an inbound connection
     */
    upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<void>;
    /**
     * Upgrades an outbound connection
     */
    upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<Connection>;
    private _performUpgrade;
    /**
     * A convenience method for generating a new `Connection`
     */
    _createConnection(opts: CreateConnectionOptions): Connection;
    /**
     * Routes incoming streams to the correct handler
     */
    _onStream(opts: OnStreamOptions): void;
    /**
     * Attempts to encrypt the incoming `connection` with the provided `cryptos`
     */
    _encryptInbound(connection: MultiaddrConnection, options?: AbortOptions): Promise<CryptoResult>;
    /**
     * Attempts to encrypt the given `connection` with the provided connection encrypters.
     * The first `ConnectionEncrypter` module to succeed will be used
     */
    _encryptOutbound(connection: MultiaddrConnection, options: SecureConnectionOptions): Promise<CryptoResult>;
    /**
     * Selects one of the given muxers via multistream-select. That
     * muxer will be used for all future streams on the connection.
     */
    _multiplexOutbound(connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>, options: AbortOptions): Promise<{
        stream: MultiaddrConnection;
        muxerFactory?: StreamMuxerFactory;
    }>;
    /**
     * Registers support for one of the given muxers via multistream-select. The
     * selected muxer will be used for all future streams on the connection.
     */
    _multiplexInbound(connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>, options: AbortOptions): Promise<{
        stream: MultiaddrConnection;
        muxerFactory?: StreamMuxerFactory;
    }>;
    getConnectionEncrypters(): Map<string, ConnectionEncrypter<unknown>>;
    getStreamMuxers(): Map<string, StreamMuxerFactory>;
}
export {};
//# sourceMappingURL=upgrader.d.ts.map