webpeerjs 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/dist/esm/webpeerjs.js +215 -148
- package/dist/umd/webpeerjs.js +48593 -47615
- package/package.json +3 -1
- package/src/config.js +48 -9
- package/src/peer.js +2 -5
- package/src/webpeerjs.js +126 -91
package/README.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# WebpeerJS
|
|
2
|
-
> Simple peer-to-peer
|
|
2
|
+
> Simple peer-to-peer in the browser.
|
|
3
3
|
|
|
4
|
-
WebpeerJS enables browser to browser connectivity without a central server.
|
|
4
|
+
Build completely P2P web applications, no trackers or relay servers required. [WebpeerJS](https://github.com/nuzulul/webpeerjs) enables browser to browser connectivity without a central server. Connecting people safely, privately, openly and reliably.
|
|
5
5
|
|
|
6
6
|
[Live Demo](https://nuzulul.github.io/webpeerjs/demo/)
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
* ✅ Decentralized Network
|
|
11
|
-
* ✅
|
|
11
|
+
* ✅ Unlimited Peers
|
|
12
12
|
* ✅ Works in The Browser
|
|
13
|
+
* ✅ Broadcast Message / Room
|
|
13
14
|
|
|
14
15
|
## Install
|
|
15
16
|
|
|
@@ -21,6 +22,8 @@ npm i webpeerjs
|
|
|
21
22
|
|
|
22
23
|
Browser `<script>` tag :
|
|
23
24
|
|
|
25
|
+
Uses built-in JS files from [latest release](https://github.com/nuzulul/webpeerjs/releases/latest) or [CDN](https://www.jsdelivr.com/package/npm/webpeerjs) will make it's exports available as `webpeerjs` in the global namespace.
|
|
26
|
+
|
|
24
27
|
```
|
|
25
28
|
<script src="https://cdn.jsdelivr.net/npm/webpeerjs@0.0/dist/umd/webpeerjs.min.js"></script>
|
|
26
29
|
```
|
|
@@ -36,7 +39,7 @@ void async function main() {
|
|
|
36
39
|
|
|
37
40
|
console.log(`My node id : ${node.id}`)
|
|
38
41
|
|
|
39
|
-
const [broadcast,listen,members] = node.joinRoom('
|
|
42
|
+
const [broadcast,listen,members] = node.joinRoom('globalroom')
|
|
40
43
|
|
|
41
44
|
listen((message,id) => {
|
|
42
45
|
console.log(`Message from ${id} : ${message}`)
|
package/dist/esm/webpeerjs.js
CHANGED
|
@@ -11,6 +11,7 @@ import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-
|
|
|
11
11
|
import { createLibp2p } from 'libp2p';
|
|
12
12
|
import { IDBDatastore } from 'datastore-idb';
|
|
13
13
|
import { webTransport } from '@libp2p/webtransport';
|
|
14
|
+
import { webSockets } from '@libp2p/websockets';
|
|
14
15
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
15
16
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
16
17
|
import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery';
|
|
@@ -33,20 +34,15 @@ const CONFIG_PEER_DISCOVERY_GLOBAL = '_peer-discovery._p2p._pubsub';
|
|
|
33
34
|
const CONFIG_PEER_DISCOVERY_WEBPEERJS= prefix$1+'-peer-discovery';
|
|
34
35
|
const CONFIG_PUBSUB_PEER_DISCOVERY = [CONFIG_PEER_DISCOVERY_GLOBAL, CONFIG_PEER_DISCOVERY_UNIVERSAL_CONNECTIVITY, CONFIG_PEER_DISCOVERY_WEBPEERJS];
|
|
35
36
|
const CONFIG_DELEGATED_API = 'https://delegated-ipfs.dev';
|
|
37
|
+
const CONFIG_DNS_RESOLVER = 'https://dns.google/resolve';
|
|
38
|
+
const CONFIG_KNOWN_BOOTSTRAP_DNS = '_dnsaddr.bootstrap.libp2p.io';
|
|
39
|
+
const CONFIG_TIMEOUT_DIAL_KNOWN_PEERS = 15000;
|
|
36
40
|
|
|
37
41
|
const CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS = [
|
|
38
42
|
'QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
|
|
39
43
|
'QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
|
40
44
|
'QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt',
|
|
41
|
-
'QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ'
|
|
42
|
-
'12D3KooWPEDBmt7vm6FNNYuqaA4n2qMUZ6wPK5NcRc8t6KpqgRkV',
|
|
43
|
-
'12D3KooWSHbugDEQeWm2LjtRRMpNgLu6oZ8zkX8XcTwYMAewVekP',
|
|
44
|
-
'12D3KooWASoxFpwwy8JDdu4Tm57mhESsnbFPogam9VVmhR95FGXr',
|
|
45
|
-
'12D3KooWHh98YpAkJsn3ULjMjK1n9QVkXmi8Sb3gTDMatHxCmDP5',
|
|
46
|
-
'12D3KooWS79EhkPU7ESUwgG4vyHHzW9FDNZLoWVth9b5N5NSrvaj',
|
|
47
|
-
'12D3KooWBbkCD5MpJhMc1mfPAVGEyVkQnyxPKGS7AHwDqQM2JUsk',
|
|
48
|
-
'12D3KooWKLdecs31Zmo2pLBjR9HY2vWo3VwM4eBm21Czeucbe6FL',
|
|
49
|
-
'12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H'
|
|
45
|
+
'QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ'
|
|
50
46
|
];
|
|
51
47
|
|
|
52
48
|
const CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS = [
|
|
@@ -56,13 +52,46 @@ const CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS = [
|
|
|
56
52
|
const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS.concat(CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS);
|
|
57
53
|
|
|
58
54
|
const CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS = [
|
|
55
|
+
{
|
|
56
|
+
"Peers": [
|
|
57
|
+
{
|
|
58
|
+
"Addrs": [
|
|
59
|
+
"/dns6/sv15.bootstrap.libp2p.io/tcp/443/wss",
|
|
60
|
+
"/dns4/sv15.bootstrap.libp2p.io/tcp/443/wss"
|
|
61
|
+
],
|
|
62
|
+
"ID": "QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
|
|
63
|
+
"Schema": "peer"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"Peers": [
|
|
69
|
+
{
|
|
70
|
+
"Addrs": [
|
|
71
|
+
"/dns4/am6.bootstrap.libp2p.io/tcp/443/wss",
|
|
72
|
+
"/dns6/am6.bootstrap.libp2p.io/tcp/443/wss"
|
|
73
|
+
],
|
|
74
|
+
"ID": "QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
|
|
75
|
+
"Schema": "peer"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"Peers": [
|
|
81
|
+
{
|
|
82
|
+
"Addrs": [
|
|
83
|
+
"/dns6/sg1.bootstrap.libp2p.io/tcp/443/wss",
|
|
84
|
+
"/dns4/sg1.bootstrap.libp2p.io/tcp/443/wss"
|
|
85
|
+
],
|
|
86
|
+
"ID": "QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
|
|
87
|
+
"Schema": "peer"
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
59
91
|
];
|
|
60
92
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
64
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
65
|
-
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
93
|
+
//this code comes from https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/blob/9d0da565f70e9b2403251c9d11dfc0b9b52babfa/src/peer.ts
|
|
94
|
+
|
|
66
95
|
var Peer;
|
|
67
96
|
(function (Peer) {
|
|
68
97
|
let _codec;
|
|
@@ -401,7 +430,7 @@ class webpeerjs{
|
|
|
401
430
|
const addr = connect.addr;
|
|
402
431
|
|
|
403
432
|
if(CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS.includes(id)){
|
|
404
|
-
if(!this.#connections.has(id)&&addr.includes('webtransport')){
|
|
433
|
+
if((!this.#connections.has(id) || (this.#connections.get(id).includes('/wss/')))&&addr.includes('webtransport')){
|
|
405
434
|
await this.#dbstore.put(new Key(id), new TextEncoder().encode(addr));
|
|
406
435
|
}
|
|
407
436
|
}
|
|
@@ -692,6 +721,7 @@ class webpeerjs{
|
|
|
692
721
|
//if this disconnected peer is known bootstrap redial it
|
|
693
722
|
else if(this.#dialedKnownBootstrap.has(id)){
|
|
694
723
|
const addr = this.#connections.get(id);
|
|
724
|
+
if(addr.includes('/wss/'))return
|
|
695
725
|
let mddrs = [];
|
|
696
726
|
const addrs = multiaddr(addr);
|
|
697
727
|
mddrs.push(addrs);
|
|
@@ -732,8 +762,29 @@ class webpeerjs{
|
|
|
732
762
|
this.#ping();
|
|
733
763
|
});
|
|
734
764
|
|
|
735
|
-
this.#libp2p.addEventListener('peer:identify', (evt) => {
|
|
765
|
+
this.#libp2p.addEventListener('peer:identify', async (evt) => {
|
|
736
766
|
//console.log('peer:identify '+evt.detail.peerId.toString(),evt.detail)
|
|
767
|
+
|
|
768
|
+
const id = evt.detail.peerId.toString();
|
|
769
|
+
|
|
770
|
+
if(CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS.includes(id)){
|
|
771
|
+
const remoteAddr = evt.detail.connection.remoteAddr.toString();
|
|
772
|
+
if(remoteAddr.includes('/wss/')){
|
|
773
|
+
let addrs = [];
|
|
774
|
+
let mddrs = [];
|
|
775
|
+
for(const peer of evt.detail.listenAddrs){
|
|
776
|
+
if(!peer.toString().includes('webtransport'))continue
|
|
777
|
+
const addr = peer.toString()+'/p2p/'+id;
|
|
778
|
+
const mddr = multiaddr(addr);
|
|
779
|
+
addrs.push(addr);
|
|
780
|
+
mddrs.push(mddr);
|
|
781
|
+
}
|
|
782
|
+
this.#dialedKnownBootstrap.set(id,addrs);
|
|
783
|
+
await this.#libp2p.hangUp(peerIdFromString(id));
|
|
784
|
+
this.#dialMultiaddress(mddrs);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
737
788
|
if(evt.detail.protocols.includes(CONFIG_PROTOCOL)){
|
|
738
789
|
//console.log('peer:identify '+evt.detail.peerId.toString(),evt)
|
|
739
790
|
|
|
@@ -1116,37 +1167,39 @@ class webpeerjs{
|
|
|
1116
1167
|
}
|
|
1117
1168
|
}
|
|
1118
1169
|
|
|
1119
|
-
#findHybridPeer(){
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1170
|
+
async #findHybridPeer(){
|
|
1171
|
+
|
|
1172
|
+
if(!navigator.onLine)return
|
|
1173
|
+
if(!this.#isDialEnabled)return
|
|
1174
|
+
|
|
1175
|
+
for(const target of CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS){
|
|
1176
|
+
if(!this.#isConnected(target) && !this.#connections.has(target)){
|
|
1177
|
+
//console.log('findPeer',target)
|
|
1178
|
+
const peerId = peerIdFromString(target);
|
|
1179
|
+
//const peerInfo = await this.#libp2p.services.aminoDHT.findPeer(peerId)
|
|
1180
|
+
|
|
1181
|
+
//console.info(peerInfo)
|
|
1182
|
+
for await (const event of this.#libp2p.services.aminoDHT.findPeer(peerId)){
|
|
1183
|
+
//console.info('findPeer',event)
|
|
1184
|
+
if (event.name === 'FINAL_PEER'){
|
|
1185
|
+
//console.log(event.peer.id.toString(),event.peer.multiaddrs.toString())
|
|
1186
|
+
let mddrs = [];
|
|
1187
|
+
let addrs = [];
|
|
1188
|
+
const id = event.peer.id.toString();
|
|
1189
|
+
for(const mddr of event.peer.multiaddrs){
|
|
1190
|
+
const peeraddr = mddr.toString()+'/p2p/'+id;
|
|
1191
|
+
const peermddr = multiaddr(peeraddr);
|
|
1192
|
+
addrs.push(peeraddr);
|
|
1193
|
+
mddrs.push(peermddr);
|
|
1194
|
+
}
|
|
1195
|
+
this.#dialedKnownBootstrap.set(id,addrs);
|
|
1196
|
+
if(!this.#isConnected(id)){
|
|
1197
|
+
this.#dialMultiaddress(mddrs);
|
|
1145
1198
|
}
|
|
1146
1199
|
}
|
|
1147
1200
|
}
|
|
1148
1201
|
}
|
|
1149
|
-
}
|
|
1202
|
+
}
|
|
1150
1203
|
}
|
|
1151
1204
|
|
|
1152
1205
|
|
|
@@ -1490,65 +1543,47 @@ class webpeerjs{
|
|
|
1490
1543
|
if(peers == 0){
|
|
1491
1544
|
this.#dialKnownPeers();
|
|
1492
1545
|
}
|
|
1493
|
-
},
|
|
1546
|
+
},120*1000);
|
|
1494
1547
|
}
|
|
1495
1548
|
|
|
1496
1549
|
|
|
1497
1550
|
//dial to all known bootstrap peers and DNS
|
|
1498
1551
|
#dialKnownPeers(){
|
|
1499
|
-
//this.#dialKnownBootstrap()
|
|
1500
1552
|
setTimeout(()=>{
|
|
1501
1553
|
this.#dialSavedKnownID();
|
|
1502
|
-
this.#findHybridPeer();
|
|
1503
1554
|
setTimeout(()=>{this.#dialUpdateSavedKnownID();},50000);
|
|
1555
|
+
setTimeout(()=>{this.#findHybridPeer();},60000);
|
|
1504
1556
|
setTimeout(()=>{
|
|
1505
1557
|
const peers = this.#libp2p.getPeers().length;
|
|
1506
1558
|
if(peers == 0){
|
|
1507
1559
|
this.#dialKnownID();
|
|
1508
|
-
this.#findHybridPeer();
|
|
1560
|
+
setTimeout(()=>{this.#findHybridPeer();},60000);
|
|
1509
1561
|
setTimeout(()=>{
|
|
1510
1562
|
const peers = this.#libp2p.getPeers().length;
|
|
1511
1563
|
if(peers == 0){
|
|
1512
|
-
|
|
1513
|
-
|
|
1564
|
+
this.#dialKnownBootstrap();
|
|
1565
|
+
setTimeout(()=>{this.#findHybridPeer();},15000);
|
|
1514
1566
|
setTimeout(()=>{
|
|
1515
|
-
this.#libp2p.getPeers().length;
|
|
1516
|
-
|
|
1567
|
+
const peers = this.#libp2p.getPeers().length;
|
|
1568
|
+
if(peers == 0){
|
|
1569
|
+
this.#dialKnownDNS();
|
|
1570
|
+
setTimeout(()=>{this.#findHybridPeer();},15000);
|
|
1571
|
+
setTimeout(()=>{
|
|
1572
|
+
const peers = this.#libp2p.getPeers().length;
|
|
1573
|
+
if(peers == 0){
|
|
1574
|
+
this.#dialKnownDNSonly();
|
|
1575
|
+
setTimeout(()=>{this.#findHybridPeer();},15000);
|
|
1576
|
+
}
|
|
1577
|
+
},CONFIG_TIMEOUT_DIAL_KNOWN_PEERS);
|
|
1578
|
+
}
|
|
1579
|
+
},CONFIG_TIMEOUT_DIAL_KNOWN_PEERS);
|
|
1517
1580
|
}
|
|
1518
|
-
},
|
|
1581
|
+
},CONFIG_TIMEOUT_DIAL_KNOWN_PEERS);
|
|
1519
1582
|
}
|
|
1520
|
-
},
|
|
1583
|
+
},CONFIG_TIMEOUT_DIAL_KNOWN_PEERS);
|
|
1521
1584
|
},5000);
|
|
1522
1585
|
}
|
|
1523
1586
|
|
|
1524
|
-
|
|
1525
|
-
//dial based on known bootsrap peers address
|
|
1526
|
-
#dialKnownBootstrap(){
|
|
1527
|
-
|
|
1528
|
-
if(!navigator.onLine)return
|
|
1529
|
-
if(!this.#isDialEnabled)return
|
|
1530
|
-
|
|
1531
|
-
const bootstrap = CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS;
|
|
1532
|
-
for(const peer of bootstrap){
|
|
1533
|
-
const address = peer.Peers[0].Addrs;
|
|
1534
|
-
const id = peer.Peers[0].ID;
|
|
1535
|
-
let mddrs = [];
|
|
1536
|
-
let addrs = [];
|
|
1537
|
-
for(const addr of address){
|
|
1538
|
-
const peeraddr = addr+'/p2p/'+id;
|
|
1539
|
-
const peermddr = multiaddr(peeraddr);
|
|
1540
|
-
addrs.push(peeraddr);
|
|
1541
|
-
mddrs.push(peermddr);
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
this.#dialedKnownBootstrap.set(id,addrs);
|
|
1545
|
-
if(!this.#isConnected(id)){
|
|
1546
|
-
this.#dialMultiaddress(mddrs);
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
1587
|
async #dialSavedKnownID(){
|
|
1553
1588
|
|
|
1554
1589
|
if(!navigator.onLine)return
|
|
@@ -1669,118 +1704,149 @@ class webpeerjs{
|
|
|
1669
1704
|
}
|
|
1670
1705
|
}
|
|
1671
1706
|
}
|
|
1672
|
-
|
|
1707
|
+
|
|
1708
|
+
|
|
1709
|
+
//dial based on known bootsrap peers address using Websocket expected
|
|
1710
|
+
#dialKnownBootstrap(){
|
|
1711
|
+
|
|
1712
|
+
if(!navigator.onLine)return
|
|
1713
|
+
if(!this.#isDialEnabled)return
|
|
1714
|
+
|
|
1715
|
+
const bootstrap = CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS;
|
|
1716
|
+
for(const peer of bootstrap){
|
|
1717
|
+
const address = peer.Peers[0].Addrs;
|
|
1718
|
+
const id = peer.Peers[0].ID;
|
|
1719
|
+
let mddrs = [];
|
|
1720
|
+
let addrs = [];
|
|
1721
|
+
for(const addr of address){
|
|
1722
|
+
if(!addr.includes('wss'))continue
|
|
1723
|
+
const peeraddr = addr+'/p2p/'+id;
|
|
1724
|
+
const peermddr = multiaddr(peeraddr);
|
|
1725
|
+
addrs.push(peeraddr);
|
|
1726
|
+
mddrs.push(peermddr);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
this.#dialedKnownBootstrap.set(id,addrs);
|
|
1730
|
+
this.#isDialWebsocket = true;
|
|
1731
|
+
if(!this.#isConnected(id)){
|
|
1732
|
+
this.#dialMultiaddress(mddrs);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1673
1737
|
|
|
1674
1738
|
//dial based on known bootstrap DNS
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
const
|
|
1681
|
-
const
|
|
1739
|
+
async #dialKnownDNS(){
|
|
1740
|
+
|
|
1741
|
+
if(!navigator.onLine)return
|
|
1742
|
+
if(!this.#isDialEnabled)return
|
|
1743
|
+
|
|
1744
|
+
const dnsresolver = CONFIG_DNS_RESOLVER;
|
|
1745
|
+
const bootstrapdns = CONFIG_KNOWN_BOOTSTRAP_DNS;
|
|
1746
|
+
const response = await fetch(dnsresolver+'?name='+bootstrapdns+'&type=txt');
|
|
1747
|
+
const json = await response.json();
|
|
1748
|
+
const dns = json.Answer;
|
|
1749
|
+
const BOOTSTRAP_PEER_IDS = [];
|
|
1682
1750
|
for(const dnsaddr of dns){
|
|
1683
|
-
const id = dnsaddr.data.split('/').pop()
|
|
1684
|
-
BOOTSTRAP_PEER_IDS.push(id)
|
|
1751
|
+
const id = dnsaddr.data.split('/').pop();
|
|
1752
|
+
BOOTSTRAP_PEER_IDS.push(id);
|
|
1685
1753
|
}
|
|
1686
|
-
const api =
|
|
1687
|
-
const delegatedClient = createDelegatedRoutingV1HttpApiClient(api)
|
|
1754
|
+
const api = CONFIG_DELEGATED_API;
|
|
1755
|
+
const delegatedClient = createDelegatedRoutingV1HttpApiClient(api);
|
|
1688
1756
|
const peers = await Promise.all(
|
|
1689
1757
|
BOOTSTRAP_PEER_IDS.map((peerId) => first(delegatedClient.getPeers(peerIdFromString(peerId)))),
|
|
1690
|
-
)
|
|
1758
|
+
);
|
|
1691
1759
|
for(const peer of peers){
|
|
1692
|
-
const address = peer.Addrs
|
|
1693
|
-
const id = peer.ID
|
|
1694
|
-
let mddrs = []
|
|
1695
|
-
let addrs = []
|
|
1760
|
+
const address = peer.Addrs;
|
|
1761
|
+
const id = peer.ID;
|
|
1762
|
+
let mddrs = [];
|
|
1763
|
+
let addrs = [];
|
|
1696
1764
|
for(const addr of address){
|
|
1697
|
-
const peeraddr = addr.toString()+'/p2p/'+id.toString()
|
|
1698
|
-
const peermddr = multiaddr(peeraddr)
|
|
1699
|
-
addrs.push(peeraddr)
|
|
1700
|
-
mddrs.push(peermddr)
|
|
1765
|
+
const peeraddr = addr.toString()+'/p2p/'+id.toString();
|
|
1766
|
+
const peermddr = multiaddr(peeraddr);
|
|
1767
|
+
addrs.push(peeraddr);
|
|
1768
|
+
mddrs.push(peermddr);
|
|
1701
1769
|
}
|
|
1702
1770
|
|
|
1703
|
-
this.#dialedKnownBootstrap.set(id,addrs)
|
|
1771
|
+
this.#dialedKnownBootstrap.set(id,addrs);
|
|
1772
|
+
this.#isDialWebsocket = true;
|
|
1704
1773
|
if(!this.#isConnected(id)){
|
|
1705
|
-
this.#dialMultiaddress(mddrs)
|
|
1774
|
+
this.#dialMultiaddress(mddrs);
|
|
1706
1775
|
}
|
|
1707
1776
|
}
|
|
1708
1777
|
|
|
1709
|
-
}
|
|
1778
|
+
}
|
|
1710
1779
|
|
|
1711
1780
|
|
|
1712
1781
|
//dial based on known bootstrap DNS using DNS resolver only
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
const
|
|
1782
|
+
async #dialKnownDNSonly(){
|
|
1783
|
+
|
|
1784
|
+
if(!navigator.onLine)return
|
|
1785
|
+
if(!this.#isDialEnabled)return
|
|
1786
|
+
|
|
1787
|
+
const dnsresolver = CONFIG_DNS_RESOLVER;
|
|
1788
|
+
const bootstrapdns = CONFIG_KNOWN_BOOTSTRAP_DNS;
|
|
1789
|
+
const response = await fetch(dnsresolver+'?name='+bootstrapdns+'&type=txt');
|
|
1790
|
+
const json = await response.json();
|
|
1791
|
+
const dns = json.Answer;
|
|
1719
1792
|
|
|
1720
1793
|
for(const dnsitem of dns){
|
|
1721
|
-
const arr = dnsitem.data.split('/')
|
|
1722
|
-
const id = arr.pop()
|
|
1723
|
-
const dnsaddr = '_dnsaddr.'+arr[2]
|
|
1724
|
-
this.#dialDNSWebsocketWebtransport(id,dnsaddr)
|
|
1794
|
+
const arr = dnsitem.data.split('/');
|
|
1795
|
+
const id = arr.pop();
|
|
1796
|
+
const dnsaddr = '_dnsaddr.'+arr[2];
|
|
1797
|
+
this.#dialDNSWebsocketWebtransport(id,dnsaddr);
|
|
1725
1798
|
}
|
|
1726
|
-
}
|
|
1799
|
+
}
|
|
1727
1800
|
|
|
1728
1801
|
|
|
1729
1802
|
//dial DNS with webtransport and websocket
|
|
1730
|
-
|
|
1731
|
-
const dnsresolver =
|
|
1732
|
-
const response = await fetch(dnsresolver+'?name='+dnsaddr+'&type=txt')
|
|
1733
|
-
const json = await response.json()
|
|
1734
|
-
const dns = json.Answer
|
|
1735
|
-
let mddrs = []
|
|
1736
|
-
let addrs = []
|
|
1803
|
+
async #dialDNSWebsocketWebtransport(id,dnsaddr){
|
|
1804
|
+
const dnsresolver = CONFIG_DNS_RESOLVER;
|
|
1805
|
+
const response = await fetch(dnsresolver+'?name='+dnsaddr+'&type=txt');
|
|
1806
|
+
const json = await response.json();
|
|
1807
|
+
const dns = json.Answer;
|
|
1808
|
+
let mddrs = [];
|
|
1809
|
+
let addrs = [];
|
|
1737
1810
|
for(const dnsitem of dns){
|
|
1738
|
-
const arr = dnsitem.data.split('=')
|
|
1739
|
-
const dnsaddr = arr[1]
|
|
1740
|
-
const maddr = multiaddr(dnsaddr)
|
|
1741
|
-
mddrs.push(maddr)
|
|
1742
|
-
addrs.push(dnsaddr)
|
|
1811
|
+
const arr = dnsitem.data.split('=');
|
|
1812
|
+
const dnsaddr = arr[1];
|
|
1813
|
+
const maddr = multiaddr(dnsaddr);
|
|
1814
|
+
mddrs.push(maddr);
|
|
1815
|
+
addrs.push(dnsaddr);
|
|
1743
1816
|
}
|
|
1744
1817
|
|
|
1745
1818
|
|
|
1746
|
-
this.#isDialWebsocket = true
|
|
1747
|
-
this.#dialedKnownBootstrap.set(id,addrs)
|
|
1819
|
+
this.#isDialWebsocket = true;
|
|
1820
|
+
this.#dialedKnownBootstrap.set(id,addrs);
|
|
1748
1821
|
|
|
1749
|
-
this.#dialedKnownBootstrap.set(id,addrs)
|
|
1822
|
+
this.#dialedKnownBootstrap.set(id,addrs);
|
|
1750
1823
|
if(!this.#isConnected(id)){
|
|
1751
|
-
this.#dialMultiaddress(mddrs)
|
|
1752
|
-
this.#dialWebsocket(mddrs)
|
|
1824
|
+
this.#dialMultiaddress(mddrs);
|
|
1825
|
+
this.#dialWebsocket(mddrs);
|
|
1753
1826
|
}
|
|
1754
|
-
}
|
|
1827
|
+
}
|
|
1755
1828
|
|
|
1756
1829
|
|
|
1757
1830
|
//dial only webtransport multiaddrs
|
|
1758
1831
|
async #dialWebtransport(multiaddrs){
|
|
1759
1832
|
const webTransportMadrs = multiaddrs.filter((maddr) => maddr.protoNames().includes('webtransport')&&maddr.protoNames().includes('certhash'));
|
|
1760
|
-
for (const
|
|
1833
|
+
for (const mddr of webTransportMadrs) {
|
|
1761
1834
|
try {
|
|
1762
|
-
//console.log(`attempting to dial webtransport multiaddr: %o`,
|
|
1763
|
-
await this.#libp2p.dial(
|
|
1835
|
+
//console.log(`attempting to dial webtransport multiaddr: %o`, mddr.toString())
|
|
1836
|
+
await this.#libp2p.dial(mddr);
|
|
1764
1837
|
return // if we succeed dialing the peer, no need to try another address
|
|
1765
1838
|
} catch (error) {
|
|
1766
1839
|
}
|
|
1767
1840
|
}
|
|
1768
1841
|
}
|
|
1769
|
-
|
|
1770
|
-
//dial only webtransport multiaddrs
|
|
1771
|
-
/*#dialWebtransport1(multiaddrs){
|
|
1772
|
-
const webTransportMadrs = multiaddrs.filter((maddr) => maddr.protoNames().includes('webtransport')&&maddr.protoNames().includes('certhash'))
|
|
1773
|
-
if(webTransportMadrs.length == 0)return
|
|
1774
|
-
this.#libp2p.dial(webTransportMadrs).then((data)=>{console.warn(data)},(data)=>{console.warn(data)})
|
|
1775
|
-
}*/
|
|
1776
1842
|
|
|
1777
1843
|
//dial only websocket multiaddrs
|
|
1778
1844
|
async #dialWebsocket(multiaddrs){
|
|
1779
1845
|
const webSocketMadrs = multiaddrs.filter((maddr) => maddr.protoNames().includes('wss'));
|
|
1780
|
-
for (const
|
|
1846
|
+
for (const mddr of webSocketMadrs) {
|
|
1781
1847
|
try {
|
|
1782
|
-
//console.log(`attempting to dial websocket multiaddr: %o`,
|
|
1783
|
-
await this.#libp2p.dial(
|
|
1848
|
+
//console.log(`attempting to dial websocket multiaddr: %o`, mddr)
|
|
1849
|
+
await this.#libp2p.dial(mddr);
|
|
1784
1850
|
return // if we succeed dialing the peer, no need to try another address
|
|
1785
1851
|
} catch (error) {
|
|
1786
1852
|
}
|
|
@@ -1818,7 +1884,8 @@ class webpeerjs{
|
|
|
1818
1884
|
],
|
|
1819
1885
|
},
|
|
1820
1886
|
transports:[
|
|
1821
|
-
webTransport(),
|
|
1887
|
+
webTransport(),
|
|
1888
|
+
webSockets(),
|
|
1822
1889
|
circuitRelayTransport({
|
|
1823
1890
|
discoverRelays: CONFIG_DISCOVER_RELAYS,
|
|
1824
1891
|
reservationConcurrency: 1,
|