2018-06-21 15:23:22 +02:00
|
|
|
// Type definitions for libp2p 0.20.4
|
|
|
|
// Project: https://github.com/libp2p/js-libp2p
|
|
|
|
// Definitions by: Jaco Greeff <https://github.com/jacogr>
|
|
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
|
|
|
2018-06-24 10:16:29 +02:00
|
|
|
/// <reference types="../interface-connection"/>
|
|
|
|
/// <reference types="../interface-transport"/>
|
|
|
|
/// <reference types="../peer-book"/>
|
|
|
|
/// <reference types="../peer-info"/>
|
|
|
|
|
|
|
|
declare namespace LibP2p {
|
|
|
|
// FIXME These need to be updated so they can be imported with references as above - for now, HACK it to work... WIP, WIP...
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
import { Libp2pKadDHT } from 'libp2p-kad-dht';
|
|
|
|
// @ts-ignore
|
|
|
|
import { LibP2pMdns } from 'libp2p-mdns';
|
|
|
|
// @ts-ignore
|
|
|
|
import { LibP2pMplex } from 'libp2p-mplex';
|
|
|
|
// @ts-ignore
|
|
|
|
import LibP2pRailing from 'libp2p-railing';
|
|
|
|
// @ts-ignore
|
|
|
|
import { LibP2pSecio } from 'libp2p-secio';
|
|
|
|
// @ts-ignore
|
|
|
|
import { LibP2pSpdy } from 'libp2p-spdy';
|
|
|
|
|
|
|
|
type CreateOptions = {
|
|
|
|
DHT: typeof Libp2pKadDHT,
|
|
|
|
connection: {
|
|
|
|
crypto: Array<LibP2pSecio>,
|
|
|
|
muxer: Array<LibP2pMplex | LibP2pSpdy>
|
|
|
|
},
|
|
|
|
discovery: Array<LibP2pRailing | LibP2pMdns>,
|
|
|
|
transport: LibP2pTransport[]
|
|
|
|
};
|
|
|
|
|
|
|
|
type Events = 'peer:connect' | 'peer:disconnect' | 'peer:discovery' | 'start' | 'stop';
|
|
|
|
}
|
|
|
|
|
|
|
|
declare class LibP2p {
|
|
|
|
constructor (peerInfo: PeerInfo, PeerBook: PeerBook, options: LibP2p.CreateOptions);
|
2018-06-21 15:23:22 +02:00
|
|
|
|
|
|
|
dial (peerInfo: PeerInfo, cb: (error: Error | null) => any): void;
|
2018-06-24 10:16:29 +02:00
|
|
|
dialProtocol (peerInfo: PeerInfo, protocol: string, cb: (error: Error | null, conn?: LibP2pConnection) => any): void;
|
|
|
|
handle (protocol: string, handler: (protocol: string, conn: LibP2pConnection) => any, matcher?: (protocol: string, requestedProtocol: string, cb: (error: Error | null, accept: boolean) => void) => any): void;
|
2018-06-21 15:23:22 +02:00
|
|
|
isStarted (): boolean;
|
2018-06-24 10:16:29 +02:00
|
|
|
on (event: LibP2p.Events, cb: (event: any) => any): void;
|
2018-06-21 15:23:22 +02:00
|
|
|
start (cb: (error: Error | null) => any): void;
|
|
|
|
stop (cb: (error: Error | null) => any): void;
|
|
|
|
}
|
|
|
|
|
2018-06-24 10:16:29 +02:00
|
|
|
declare module 'libp2p' {
|
|
|
|
export default LibP2p;
|
2018-06-22 15:43:18 +02:00
|
|
|
}
|