|
85 | 85 | * stats.bwPullStream |
86 | 86 | * stats.repo |
87 | 87 | * swarm.addrs |
88 | | -* [swarm.connect](#swarmconnect) TODO: add docs |
| 88 | +* [swarm.connect](#swarmconnect) |
89 | 89 | * swarm.disconnect |
90 | 90 | * swarm.localAddrs |
91 | | -* [swarm.peers](#swarmpeers) TODO: add docs |
| 91 | +* [swarm.peers](#swarmpeers) |
92 | 92 | * [version](#version) TODO: add docs |
93 | 93 |
|
94 | 94 | Note: All API methods are documented using Promises/async/await but they also accept a callback as their last parameter. |
@@ -755,3 +755,102 @@ Unsubscribe all handlers: |
755 | 755 | ```js |
756 | 756 | await ipfs.pubsub.unsubscribe('my-pubsub-topic') |
757 | 757 | ``` |
| 758 | + |
| 759 | +## swarm.connect |
| 760 | + |
| 761 | +Open a connection to a given address. |
| 762 | + |
| 763 | +### `swarm.connect(addr, [options]): Promise<String[]>` |
| 764 | + |
| 765 | +#### Parameters |
| 766 | + |
| 767 | +* `addr` - Multiaddr address(es) of IPFS node(s) to connect to. |
| 768 | + * Type: `String`|`String[]` |
| 769 | +* `options` (optional) |
| 770 | + * Type: `Object` |
| 771 | + * Default: `null` |
| 772 | +* `options.signal` (optional) - A signal that can be used to abort the request |
| 773 | + * Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) |
| 774 | + * Default: `null` |
| 775 | + |
| 776 | +#### Returns |
| 777 | + |
| 778 | +List of connection status messages for each peer connection attempted. |
| 779 | + |
| 780 | +* Type: `Promise<String[]>` |
| 781 | + |
| 782 | +#### Examples |
| 783 | + |
| 784 | +```js |
| 785 | +const res = await ipfs.swarm.connect('/ip4/127.0.0.1/tcp/4101/ipfs/Qmeg3LQNGuiwpinKe69YBbADV2PpqGcGtcgLeaNjoxuUdV') |
| 786 | +console.log(res) |
| 787 | +/* |
| 788 | +[ |
| 789 | + 'connect Qmeg3LQNGuiwpinKe69YBbADV2PpqGcGtcgLeaNjoxuUdV success' |
| 790 | +] |
| 791 | +*/ |
| 792 | +``` |
| 793 | + |
| 794 | +## swarm.peers |
| 795 | + |
| 796 | +List peers with open connections. |
| 797 | + |
| 798 | +### `swarm.peers([options]): Promise<Object[]>` |
| 799 | + |
| 800 | +#### Parameters |
| 801 | + |
| 802 | +* `options` (optional) |
| 803 | + * Type: `Object` |
| 804 | + * Default: `null` |
| 805 | +* `options.direction` (optional) - Return direction information for each peer (inbound/outbound). |
| 806 | + * Type: `Boolean` |
| 807 | + * Default: `false` |
| 808 | +* `options.signal` (optional) - A signal that can be used to abort the request |
| 809 | + * Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) |
| 810 | + * Default: `null` |
| 811 | +* `options.latency` (optional) - Return latency information for each peer. |
| 812 | + * Type: `Boolean` |
| 813 | + * Default: `false` |
| 814 | +* `options.streams` (optional) - Return streams information for each peer. |
| 815 | + * Type: `Boolean` |
| 816 | + * Default: `false` |
| 817 | +* `options.verbose` (optional) - Return streams, latency, and direction info as well as address and ID for each peer. |
| 818 | + * Type: `Boolean` |
| 819 | + * Default: `false` |
| 820 | + |
| 821 | +#### Returns |
| 822 | + |
| 823 | +Peer information for peers with open connections. |
| 824 | + |
| 825 | +* Type: `Promise<Object[]>` |
| 826 | + |
| 827 | +#### Examples |
| 828 | + |
| 829 | +```js |
| 830 | +const peers = await ipfs.swarm.peers({ verbose: true }) |
| 831 | +console.log(res) |
| 832 | +/* |
| 833 | +[ |
| 834 | + { |
| 835 | + addr: '/ip6/2a03:b0c0:3:e1::130:e001/tcp/4001', |
| 836 | + peer: 'QmYR4jxcGUTQZ7mA5DkfBSxpdJW5Y4CsfgHFfARLAV3goA', |
| 837 | + latency: '27.965651ms', |
| 838 | + muxer: '', |
| 839 | + direction: 2, |
| 840 | + streams: [ { protocol: '/ipfs/bitswap/1.1.0' } ] |
| 841 | + }, |
| 842 | + { |
| 843 | + addr: '/ipfs/QmdGQoGuK3pao6bRDqGSDvux5SFHa4kC1XNFfHFcvcbydY/p2p-circuit', |
| 844 | + peer: 'QmcqrAQZqcQxrVpw2Png7FrSfNArfEFTu9UhPopmKPZpGP', |
| 845 | + latency: '772.455375ms', |
| 846 | + muxer: '', |
| 847 | + direction: 2, |
| 848 | + streams: [ |
| 849 | + { protocol: '/ipfs/bitswap/1.1.0' }, |
| 850 | + { protocol: '/ipfs/kad/1.0.0' } |
| 851 | + ] |
| 852 | + }, |
| 853 | + // ... |
| 854 | +] |
| 855 | +*/ |
| 856 | +``` |
0 commit comments