webpeerjs 0.0.3 → 0.0.5

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/package.json CHANGED
@@ -1,15 +1,12 @@
1
1
  {
2
2
  "name": "webpeerjs",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Simple peer-to-peer with IPFS",
5
5
  "main": "./dist/umd/webpeerjs.js",
6
- "module": "./src/webpeerjs.js",
7
- "imports": {
8
- "#/pubsub-peer-discovery/*.js": "./node_modules/@libp2p/pubsub-peer-discovery/dist/src/*.js"
9
- },
6
+ "module": "./dist/esm/webpeerjs.js",
10
7
  "exports": {
11
8
  ".": {
12
- "import": "./src/webpeerjs.js",
9
+ "import": "./dist/esm/webpeerjs.js",
13
10
  "require": "./dist/umd/webpeerjs.js"
14
11
  }
15
12
  },
package/src/config.js CHANGED
@@ -3,11 +3,12 @@ export const CONFIG_PREFIX = prefix
3
3
  export const CONFIG_BLOCKSTORE_PATH = prefix+'-blockstore'
4
4
  export const CONFIG_DATASTORE_PATH = prefix+'-datastore'
5
5
  export const CONFIG_DBSTORE_PATH = prefix+'-dbstore'
6
- export const CONFIG_MAX_CONNECTIONS = 50
6
+ export const CONFIG_MAX_CONNECTIONS = 100
7
7
  export const CONFIG_MIN_CONNECTIONS = 0
8
- export const CONFIG_DISCOVER_RELAYS = 2
8
+ export const CONFIG_DISCOVER_RELAYS = 1
9
9
  export const CONFIG_PEER_DISCOVERY_UNIVERSAL_CONNECTIVITY = 'universal-connectivity-browser-peer-discovery'
10
- export const CONFIG_PUBSUB_PEER_DISCOVERY = ['_peer-discovery._p2p._pubsub',CONFIG_PEER_DISCOVERY_UNIVERSAL_CONNECTIVITY,prefix+'-peer-discovery']
10
+ export const CONFIG_PEER_DISCOVERY_GLOBAL = '_peer-discovery._p2p._pubsub'
11
+ export const CONFIG_PUBSUB_PEER_DISCOVERY = [CONFIG_PEER_DISCOVERY_GLOBAL,CONFIG_PEER_DISCOVERY_UNIVERSAL_CONNECTIVITY,prefix+'-peer-discovery']
11
12
  export const CONFIG_PUPSUB_TOPIC = prefix+'-room'
12
13
  export const CONFIG_DELEGATED_API = 'https://delegated-ipfs.dev'
13
14
  export const CONFIG_DNS_RESOLVER = 'https://dns.google/resolve'
@@ -15,261 +16,10 @@ export const CONFIG_KNOWN_BOOTSTRAP_DNS = '_dnsaddr.bootstrap.libp2p.io'
15
16
  export const CONFIG_JOIN_ROOM_VERSION = 1
16
17
 
17
18
  export const CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS = [
18
- {
19
- "Peers": [
20
- {
21
- "Addrs": [
22
- "/ip4/147.28.186.157/udp/9091/quic-v1",
23
- "/ip4/147.28.186.157/udp/9090/webrtc-direct/certhash/uEiBbC9bbdvraVWDvcvCEdJAWDymmUqiJQ964FuyEq0hELw"
24
- ],
25
- "ID": "12D3KooWGahRw3ZnM4gAyd9FK75v4Bp5keFYTvkcAwhpEm28wbV3",
26
- "Schema": "peer"
27
- }
28
- ]
29
- },
30
- {
31
- "Peers": [
32
- {
33
- "Addrs": [
34
- "/ip6/2604:1380:4642:6600::3/udp/9095/quic-v1/webtransport/certhash/uEiCU6MjDlUhqtik_vc8Ps5_MJtGhJKn-XSqvuzn8SJGL9A/certhash/uEiDlk15VyYoXwTaB608Y80ch3OptpMiKFblYdduSVLy2sQ",
35
- "/ip4/147.28.186.157/udp/9095/quic-v1",
36
- "/ip6/2604:1380:4642:6600::3/udp/9095/quic-v1",
37
- "/ip4/147.28.186.157/udp/9095/quic-v1/webtransport/certhash/uEiCU6MjDlUhqtik_vc8Ps5_MJtGhJKn-XSqvuzn8SJGL9A/certhash/uEiDlk15VyYoXwTaB608Y80ch3OptpMiKFblYdduSVLy2sQ"
38
- ],
39
- "ID": "12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr",
40
- "Schema": "peer"
41
- }
42
- ]
43
- },
44
- {
45
- "Peers": [
46
- {
47
- "Addrs": [
48
- "/ip6/2607:f2f8:a880:0:5054:ff:fe9f:4913/udp/4001/quic-v1/webtransport/certhash/uEiD84ZvAnGWTQx_WlOAqreebO036a5RRB5zfJBo9QJfDBA/certhash/uEiAOMkIVxeNye76-f5ADnLCSNqNlnhOYdkwyRlqLFbhIkQ",
49
- "/ip6/2607:f2f8:a880::70/udp/4001/quic-v1/webtransport/certhash/uEiD84ZvAnGWTQx_WlOAqreebO036a5RRB5zfJBo9QJfDBA/certhash/uEiAOMkIVxeNye76-f5ADnLCSNqNlnhOYdkwyRlqLFbhIkQ",
50
- "/ip6/2607:f2f8:a880:0:5054:ff:fe9f:4913/tcp/4001",
51
- "/ip6/2607:f2f8:a880:0:5054:ff:fe9f:4913/udp/4001/quic-v1",
52
- "/ip4/174.136.97.180/udp/4001/quic-v1/webtransport/certhash/uEiD84ZvAnGWTQx_WlOAqreebO036a5RRB5zfJBo9QJfDBA/certhash/uEiAOMkIVxeNye76-f5ADnLCSNqNlnhOYdkwyRlqLFbhIkQ",
53
- "/ip4/174.136.97.180/udp/4001/quic-v1",
54
- "/ip6/2607:f2f8:a880::70/udp/4001/quic-v1",
55
- "/ip4/174.136.97.180/tcp/4001"
56
- ],
57
- "ID": "12D3KooWPEDBmt7vm6FNNYuqaA4n2qMUZ6wPK5NcRc8t6KpqgRkV",
58
- "Schema": "peer"
59
- }
60
- ]
61
- },
62
- {
63
- "Peers": [
64
- {
65
- "Addrs": [
66
- "/ip4/174.136.97.179/udp/4001/quic-v1",
67
- "/ip6/2607:f2f8:a880::50/udp/4002/quic-v1/webtransport/certhash/uEiBF7KOka9hhb2IjhUd-OkfgTFOf-VpgV7fwvMkKOkMrdQ/certhash/uEiDxVhDwzFlnorujU_rjTnO_TTLRMlXxzPLEgaG-1xOPkA",
68
- "/ip4/174.136.97.179/udp/4001/quic-v1/webtransport/certhash/uEiBF7KOka9hhb2IjhUd-OkfgTFOf-VpgV7fwvMkKOkMrdQ/certhash/uEiDxVhDwzFlnorujU_rjTnO_TTLRMlXxzPLEgaG-1xOPkA",
69
- "/ip6/2607:f2f8:a880::50/udp/4001/quic-v1",
70
- "/ip4/174.136.97.179/udp/4002/quic-v1/webtransport/certhash/uEiBF7KOka9hhb2IjhUd-OkfgTFOf-VpgV7fwvMkKOkMrdQ/certhash/uEiDxVhDwzFlnorujU_rjTnO_TTLRMlXxzPLEgaG-1xOPkA",
71
- "/ip6/2607:f2f8:a880::50/tcp/4001",
72
- "/ip6/2607:f2f8:a880::50/udp/4001/quic-v1/webtransport/certhash/uEiBF7KOka9hhb2IjhUd-OkfgTFOf-VpgV7fwvMkKOkMrdQ/certhash/uEiDxVhDwzFlnorujU_rjTnO_TTLRMlXxzPLEgaG-1xOPkA",
73
- "/ip4/174.136.97.179/tcp/4001"
74
- ],
75
- "ID": "12D3KooWSHbugDEQeWm2LjtRRMpNgLu6oZ8zkX8XcTwYMAewVekP",
76
- "Schema": "peer"
77
- }
78
- ]
79
- },
80
- {
81
- "Peers": [
82
- {
83
- "Addrs": [
84
- "/ip6/2a03:4000:46:26e::c17/udp/443/quic-v1/webtransport/certhash/uEiAortGu7HNi8-pV9onPFkTwykrnWuJEqYf7zbQVE1FEtg/certhash/uEiB5Z8j3pdTJU_TDYoJ-GgUQSaXOmvKIGmASL9s-p3VHQA",
85
- "/ip4/45.83.104.156/udp/443/quic-v1",
86
- "/ip4/45.83.104.156/udp/443/quic-v1/webtransport/certhash/uEiAortGu7HNi8-pV9onPFkTwykrnWuJEqYf7zbQVE1FEtg/certhash/uEiB5Z8j3pdTJU_TDYoJ-GgUQSaXOmvKIGmASL9s-p3VHQA",
87
- "/ip6/2a03:4000:46:26e::c17/tcp/443",
88
- "/ip6/2a03:4000:46:26e::c17/udp/443/quic-v1",
89
- "/ip4/45.83.104.156/tcp/443"
90
- ],
91
- "ID": "12D3KooWASoxFpwwy8JDdu4Tm57mhESsnbFPogam9VVmhR95FGXr",
92
- "Schema": "peer"
93
- }
94
- ]
95
- },
96
- {
97
- "Peers": [
98
- {
99
- "Addrs": [
100
- "/ip4/139.178.91.71/udp/4001/quic-v1",
101
- "/ip6/2604:1380:45e3:6e00::1/tcp/4001",
102
- "/ip4/139.178.91.71/tcp/4001",
103
- "/ip4/139.178.91.71/udp/4001/quic-v1/webtransport/certhash/uEiDYGZMqjz8wsz59DHA4iJin4nqTUfuJhq9AeAZlHBrmvg/certhash/uEiBXLv0dkEqbhmcinRbwj8b_3vWs0kWwf1-fiaz5wS-tew",
104
- "/ip6/2604:1380:45e3:6e00::1/udp/4001/quic-v1/webtransport/certhash/uEiDYGZMqjz8wsz59DHA4iJin4nqTUfuJhq9AeAZlHBrmvg/certhash/uEiBXLv0dkEqbhmcinRbwj8b_3vWs0kWwf1-fiaz5wS-tew",
105
- "/dnsaddr/bootstrap.libp2p.io",
106
- "/dns6/sv15.bootstrap.libp2p.io/tcp/443/wss",
107
- "/ip6/2604:1380:45e3:6e00::1/udp/4001/quic-v1",
108
- "/ip4/139.178.91.71/tcp/443/tls/sni/sv15.bootstrap.libp2p.io/ws",
109
- "/ip6/2604:1380:45e3:6e00::1/tcp/443/tls/sni/sv15.bootstrap.libp2p.io/ws",
110
- "/dns4/sv15.bootstrap.libp2p.io/tcp/443/wss"
111
- ],
112
- "ID": "QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
113
- "Schema": "peer"
114
- }
115
- ]
116
- },
117
- {
118
- "Peers": [
119
- {
120
- "Addrs": [
121
- "/ip4/139.178.65.157/udp/4001/quic-v1",
122
- "/dns6/ny5.bootstrap.libp2p.io/tcp/443/wss",
123
- "/ip6/2604:1380:45d2:8100::1/tcp/4001",
124
- "/dns4/ny5.bootstrap.libp2p.io/tcp/443/wss",
125
- "/ip4/139.178.65.157/tcp/4001",
126
- "/ip6/2604:1380:45d2:8100::1/udp/4001/quic-v1"
127
- ],
128
- "ID": "QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
129
- "Schema": "peer"
130
- }
131
- ]
132
- },
133
- {
134
- "Peers": [
135
- {
136
- "Addrs": [
137
- "/dns4/am6.bootstrap.libp2p.io/tcp/443/wss",
138
- "/ip6/2604:1380:4602:5c00::3/udp/4001/quic-v1/webtransport/certhash/uEiD3Q2mfd5EYt6Y2M9rsge_nna4hVyCgUVlfSz3IjAK8ew/certhash/uEiAHt8JR08mlUCCGnN8VpqG9G4sfvdjAd0v5ZM5W1lqntw",
139
- "/ip6/2604:1380:4602:5c00::3/tcp/4001",
140
- "/ip4/147.75.87.27/udp/4001/quic-v1",
141
- "/ip6/2604:1380:4602:5c00::3/udp/4001/quic-v1",
142
- "/ip4/147.75.87.27/tcp/4001",
143
- "/dns6/am6.bootstrap.libp2p.io/tcp/443/wss",
144
- "/ip4/147.75.87.27/udp/4001/quic-v1/webtransport/certhash/uEiD3Q2mfd5EYt6Y2M9rsge_nna4hVyCgUVlfSz3IjAK8ew/certhash/uEiAHt8JR08mlUCCGnN8VpqG9G4sfvdjAd0v5ZM5W1lqntw"
145
- ],
146
- "ID": "QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
147
- "Schema": "peer"
148
- }
149
- ]
150
- },
151
- {
152
- "Peers": [
153
- {
154
- "Addrs": [
155
- "/ip6/2604:1380:40e1:9c00::1/udp/4001/quic-v1/webtransport/certhash/uEiBENNd9IIPnU1cTGoVATo6cly-O2fQAjKpIyFi0msoJew/certhash/uEiD8N0sSnHOUIsKxz4pDuVqx4szt-huTZWafW_EY19H7MQ",
156
- "/ip6/2604:1380:40e1:9c00::1/tcp/4001",
157
- "/dnsaddr/bootstrap.libp2p.io",
158
- "/ip4/145.40.118.135/udp/4001/quic-v1/webtransport/certhash/uEiBENNd9IIPnU1cTGoVATo6cly-O2fQAjKpIyFi0msoJew/certhash/uEiD8N0sSnHOUIsKxz4pDuVqx4szt-huTZWafW_EY19H7MQ",
159
- "/ip4/145.40.118.135/udp/4001/quic-v1",
160
- "/dns4/sg1.bootstrap.libp2p.io/tcp/443/wss",
161
- "/ip6/2604:1380:40e1:9c00::1/udp/4001/quic-v1",
162
- "/ip4/145.40.118.135/tcp/4001",
163
- "/dns6/sg1.bootstrap.libp2p.io/tcp/443/wss",
164
- "/ip4/145.40.118.135/tcp/443/tls/sni/sg1.bootstrap.libp2p.io/ws",
165
- "/ip6/2604:1380:40e1:9c00::1/tcp/443/tls/sni/sg1.bootstrap.libp2p.io/ws"
166
- ],
167
- "ID": "QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
168
- "Schema": "peer"
169
- }
170
- ]
171
- },
172
- {
173
- "Peers": [
174
- {
175
- "Addrs": [
176
- "/ip4/104.131.131.82/udp/4001/quic-v1/webtransport/certhash/uEiCIMEw_vvBwFLEqWbOj_wx7I90HmfMabSyVZ9Vn5srjPA/certhash/uEiBy22YtYUPU8T3aJ4rL3jC0lLR8MFZZNkFP-rWRxMrqQA",
177
- "/ip4/104.131.131.82/udp/4001/quic-v1",
178
- "/ip4/104.131.131.82/tcp/4001",
179
- "/ip4/104.131.131.82/udp/4001/quic"
180
- ],
181
- "ID": "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
182
- "Schema": "peer"
183
- }
184
- ]
185
- },
186
- {
187
- "Peers": [
188
- {
189
- "Addrs": [
190
- "/ip4/16.170.214.173/udp/4001/quic-v1/webtransport/certhash/uEiAKAeeOxU7ExDc81y7d53D96nFaRmmXwSFj0429Ij9T9A/certhash/uEiB4ttGGuaUzqF84q5RFhUTVArF4mb9t_UN_kcsfd4qYEQ",
191
- "/ip4/16.170.214.173/tcp/4001",
192
- "/ip4/16.170.214.173/udp/4001/quic-v1"
193
- ],
194
- "ID": "12D3KooWHh98YpAkJsn3ULjMjK1n9QVkXmi8Sb3gTDMatHxCmDP5",
195
- "Schema": "peer"
196
- }
197
- ]
198
- },
199
- {
200
- "Peers": [
201
- {
202
- "Addrs": [
203
- "/ip4/18.119.248.24/udp/4001/quic-v1",
204
- "/ip4/18.119.248.24/tcp/4001",
205
- "/ip4/18.119.248.24/udp/4001/quic-v1/webtransport/certhash/uEiDwG2YnjoUpoKqmUMX-aYJeLi1UNEsqa8EFhpHFUVs0AQ/certhash/uEiCqy6-Pk3S2iYS0puQ0UhtTZ1s_nw-sIsoB-bX0Le6lFA"
206
- ],
207
- "ID": "12D3KooWS79EhkPU7ESUwgG4vyHHzW9FDNZLoWVth9b5N5NSrvaj",
208
- "Schema": "peer"
209
- }
210
- ]
211
- },
212
- {
213
- "Peers": [
214
- {
215
- "Addrs": [
216
- "/ip4/83.173.236.99/udp/4001/quic-v1/webtransport/certhash/uEiD8mhYDW_6kgJAb07RlZnA-YSScG38df5wb9IxFtZmQwQ/certhash/uEiACG9e-sG_ild6y5t-jvb_dfsNi_gPgZ7nn7Qa5ctT-Wg",
217
- "/ip6/2a02:121e:21e:1:546f:18ff:fea8:8e/tcp/4001",
218
- "/ip4/83.173.236.99/tcp/10201",
219
- "/dns4/ipfs-ws.neaweb.ch/tcp/443/wss",
220
- "/ip4/89.251.251.195/udp/4001/quic-v1",
221
- "/ip4/89.251.251.195/udp/4001/quic-v1/webtransport/certhash/uEiD8mhYDW_6kgJAb07RlZnA-YSScG38df5wb9IxFtZmQwQ/certhash/uEiACG9e-sG_ild6y5t-jvb_dfsNi_gPgZ7nn7Qa5ctT-Wg",
222
- "/ip6/2a02:121e:21e:1:546f:18ff:fea8:8e/udp/4001/quic-v1",
223
- "/ip4/89.251.251.195/tcp/4001/quic-v1/webtransport",
224
- "/ip6/2a02:121e:21e:1:546f:18ff:fea8:8e/tcp/4011/ws",
225
- "/ip4/89.251.251.195/tcp/4001",
226
- "/dns4/ipfs-ws.neaweb.tech/tcp/443/wss",
227
- "/ip4/89.251.251.195/tcp/4001/quic-v1",
228
- "/ip4/83.173.236.99/tcp/4001",
229
- "/ip6/2a02:121e:21e:1:546f:18ff:fea8:8e/udp/4001/quic-v1/webtransport/certhash/uEiD8mhYDW_6kgJAb07RlZnA-YSScG38df5wb9IxFtZmQwQ/certhash/uEiACG9e-sG_ild6y5t-jvb_dfsNi_gPgZ7nn7Qa5ctT-Wg",
230
- "/ip4/83.173.236.99/udp/4001/quic-v1",
231
- "/ip4/83.173.236.99/udp/19707/quic-v1",
232
- "/ip4/83.173.236.99/udp/19707/quic-v1/webtransport/certhash/uEiD8mhYDW_6kgJAb07RlZnA-YSScG38df5wb9IxFtZmQwQ/certhash/uEiACG9e-sG_ild6y5t-jvb_dfsNi_gPgZ7nn7Qa5ctT-Wg"
233
- ],
234
- "ID": "12D3KooWBbkCD5MpJhMc1mfPAVGEyVkQnyxPKGS7AHwDqQM2JUsk",
235
- "Schema": "peer"
236
- }
237
- ]
238
- },
239
- {
240
- "Peers": [
241
- {
242
- "Addrs": [
243
- "/ip4/89.58.11.155/udp/4001/quic-v1/webtransport/certhash/uEiDDgTBtcIstrvU4MRSfcD7tYDIsQrnGAxW6Oh5AoLm4Ig/certhash/uEiAXHXsg1wBb-sPvpBw8BVpRFxso1milPa801TxjPNYQ3w",
244
- "/ip4/89.58.11.155/udp/4001/quic",
245
- "/ip6/64:ff9b::593a:b9b/udp/4001/quic-v1/webtransport/certhash/uEiDDgTBtcIstrvU4MRSfcD7tYDIsQrnGAxW6Oh5AoLm4Ig/certhash/uEiAXHXsg1wBb-sPvpBw8BVpRFxso1milPa801TxjPNYQ3w",
246
- "/ip6/64:ff9b::593a:b9b/udp/4001/quic-v1",
247
- "/ip4/89.58.11.155/udp/4001/quic-v1",
248
- "/ip4/89.58.11.155/tcp/4001"
249
- ],
250
- "ID": "12D3KooWKLdecs31Zmo2pLBjR9HY2vWo3VwM4eBm21Czeucbe6FL",
251
- "Schema": "peer"
252
- }
253
- ]
254
- },
255
- {
256
- "Peers": [
257
- {
258
- "Addrs": [
259
- "/ip4/205.198.64.76/tcp/4001",
260
- "/ip4/205.198.64.76/udp/4001/quic-v1",
261
- "/ip4/205.198.64.76/udp/4001/quic-v1/webtransport/certhash/uEiCT4khDdgvF2NHCw-fu3qUk2qRqx0AgTEt0PHZct8jq5g/certhash/uEiA2RYkSCyOOtJmrpm_Dn8jJr-LLwS0S7K3HX3dbJJlN_w"
262
- ],
263
- "ID": "12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H",
264
- "Schema": "peer"
265
- }
266
- ]
267
- },
268
19
  ]
269
20
 
270
21
  export const CONFIG_KNOWN_BOOTSTRAP_PEER_IDS = [
271
22
  '12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr',
272
- '12D3KooWGahRw3ZnM4gAyd9FK75v4Bp5keFYTvkcAwhpEm28wbV3',
273
23
  '12D3KooWPEDBmt7vm6FNNYuqaA4n2qMUZ6wPK5NcRc8t6KpqgRkV',
274
24
  '12D3KooWSHbugDEQeWm2LjtRRMpNgLu6oZ8zkX8XcTwYMAewVekP',
275
25
  '12D3KooWASoxFpwwy8JDdu4Tm57mhESsnbFPogam9VVmhR95FGXr',
package/src/peer.js ADDED
@@ -0,0 +1,64 @@
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable complexity */
3
+ /* eslint-disable @typescript-eslint/no-namespace */
4
+ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
+ /* eslint-disable @typescript-eslint/no-empty-interface */
6
+ import { decodeMessage, encodeMessage, message } from 'protons-runtime';
7
+ import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc';
8
+ export var Peer;
9
+ (function (Peer) {
10
+ let _codec;
11
+ Peer.codec = () => {
12
+ if (_codec == null) {
13
+ _codec = message((obj, w, opts = {}) => {
14
+ if (opts.lengthDelimited !== false) {
15
+ w.fork();
16
+ }
17
+ if ((obj.publicKey != null && obj.publicKey.byteLength > 0)) {
18
+ w.uint32(10);
19
+ w.bytes(obj.publicKey);
20
+ }
21
+ if (obj.addrs != null) {
22
+ for (const value of obj.addrs) {
23
+ w.uint32(18);
24
+ w.bytes(value);
25
+ }
26
+ }
27
+ if (opts.lengthDelimited !== false) {
28
+ w.ldelim();
29
+ }
30
+ }, (reader, length) => {
31
+ const obj = {
32
+ publicKey: uint8ArrayAlloc(0),
33
+ addrs: []
34
+ };
35
+ const end = length == null ? reader.len : reader.pos + length;
36
+ while (reader.pos < end) {
37
+ const tag = reader.uint32();
38
+ switch (tag >>> 3) {
39
+ case 1: {
40
+ obj.publicKey = reader.bytes();
41
+ break;
42
+ }
43
+ case 2: {
44
+ obj.addrs.push(reader.bytes());
45
+ break;
46
+ }
47
+ default: {
48
+ reader.skipType(tag & 7);
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ return obj;
54
+ });
55
+ }
56
+ return _codec;
57
+ };
58
+ Peer.encode = (obj) => {
59
+ return encodeMessage(obj, Peer.codec());
60
+ };
61
+ Peer.decode = (buf) => {
62
+ return decodeMessage(buf, Peer.codec());
63
+ };
64
+ })(Peer || (Peer = {}));
package/src/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as config from './config'
2
2
 
3
- import { Peer as PBPeer } from '#/pubsub-peer-discovery/peer.js'
3
+ import { Peer as PBPeer } from './peer'
4
4
 
5
5
  import { Key } from 'interface-datastore'
6
6
 
@@ -137,26 +137,26 @@ export function metrics(data){
137
137
  const fail = errors+timeouts
138
138
  const treshold = errors+timeouts+stats.open+stats.pending
139
139
 
140
- if(treshold>50){
140
+ if(treshold>60){
141
141
  //console.log(`Treeshold hit : ${treshold}`)
142
142
  }
143
143
 
144
- if(fail>50){
144
+ if(fail>60){
145
145
  //console.log(`Open : ${stats.open} , Pending : ${stats.pending} , Succes : ${totals.success} , Fail : ${fail} `)
146
146
 
147
147
  }
148
148
 
149
- if ((fail-lastfailtreshold)>50){
149
+ if ((fail-lastfailtreshold)>30){
150
150
  if(isDialEnabled){
151
151
  isDialEnabled = false
152
- //const str = JSON.stringify({isDialEnabled,fail,lastfailtreshold})
153
- //console.warn(str)
152
+ const str = JSON.stringify({isDialEnabled,fail,lastfailtreshold})
153
+ console.warn(str)
154
154
  setTimeout(()=>{
155
155
  if(!isDialEnabled){
156
156
  isDialEnabled = true
157
157
  lastfailtreshold = fail
158
- //const str = JSON.stringify({isDialEnabled,fail,lastfailtreshold})
159
- //console.warn(str)
158
+ const str = JSON.stringify({isDialEnabled,fail,lastfailtreshold})
159
+ console.warn(str)
160
160
  }
161
161
  },6*60*1000)
162
162
  }
@@ -175,4 +175,10 @@ onunhandledrejection = function(evt) {
175
175
  console.warn(evt.reason);
176
176
  return
177
177
  }
178
- */
178
+ */
179
+
180
+ export async function getDigest(){
181
+ const buf = new TextEncoder().encode(Math.random().toString())
182
+ const digest = await sha256.encode(buf)
183
+ return digest
184
+ }
package/src/webpeerjs.js CHANGED
@@ -4,11 +4,13 @@ import {
4
4
  PBPeer,
5
5
  uint8ArrayToString,
6
6
  uint8ArrayFromString,
7
- //first,
7
+ first,
8
8
  Key,
9
9
  msgIdFnStrictNoSign,
10
- metrics } from './utils'
11
- //import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
10
+ metrics,
11
+ getDigest
12
+ } from './utils'
13
+ import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
12
14
  import { createLibp2p } from 'libp2p'
13
15
  import { IDBDatastore } from 'datastore-idb'
14
16
  import { webTransport } from '@libp2p/webtransport'
@@ -19,7 +21,7 @@ import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
19
21
  import { gossipsub } from '@chainsafe/libp2p-gossipsub'
20
22
  import { identify, identifyPush } from '@libp2p/identify'
21
23
  import { multiaddr } from '@multiformats/multiaddr'
22
- //import { peerIdFromString } from '@libp2p/peer-id'
24
+ import { peerIdFromString } from '@libp2p/peer-id'
23
25
  import { kadDHT, removePrivateAddressesMapper } from '@libp2p/kad-dht'
24
26
  import { simpleMetrics } from '@libp2p/simple-metrics'
25
27
 
@@ -78,6 +80,9 @@ class webpeerjs{
78
80
  //is dial enabled
79
81
  #isDialEnabled
80
82
 
83
+ //message tracker avoid double
84
+ #msgIdtracker
85
+
81
86
  id
82
87
  status
83
88
  IPFS
@@ -105,6 +110,7 @@ class webpeerjs{
105
110
  this.#trackDisconnect = new Map()
106
111
  this.#dialQueue = []
107
112
  this.#isDialEnabled = true
113
+ this.#msgIdtracker = []
108
114
 
109
115
  this.peers = (function(f) {
110
116
  return f
@@ -139,6 +145,9 @@ class webpeerjs{
139
145
  if(connection.toString() === config.CONFIG_KNOWN_BOOTSTRAP_PEER_IDS[0]){
140
146
  setTimeout(()=>{
141
147
  this.#announce()
148
+ setTimeout(()=>{
149
+ this.#announce()
150
+ },5000)
142
151
  },1000)
143
152
  }
144
153
 
@@ -150,6 +159,7 @@ class webpeerjs{
150
159
 
151
160
  //console.log('on:'+event.detail.topic,event.detail.data)
152
161
  //console.log('from '+event.detail.from.toString(),event)
162
+ //console.log('ontopic:'+event.detail.topic)
153
163
 
154
164
  if (event.detail.type !== 'signed') {
155
165
  return
@@ -219,6 +229,7 @@ class webpeerjs{
219
229
  const room = json.room
220
230
  const rooms = json.rooms
221
231
  const message = json.message
232
+ const msgId = json.msgId
222
233
  const signal = json.signal
223
234
  const id = json.id
224
235
  //console.log(`from ${id}:${signal} = ${message}`)
@@ -250,16 +261,21 @@ class webpeerjs{
250
261
  if(room){
251
262
  if(this.#rooms[room]){
252
263
 
253
- //inbound message
254
- if(message){
255
- this.#rooms[room].onMessage(message,id)
256
- }
257
-
258
264
  //update room members
259
265
  if(!this.#rooms[room].members.includes(id)){
260
266
  this.#rooms[room].members.push(id)
261
267
  this.#rooms[room].onMembers(this.#rooms[room].members)
262
268
  }
269
+
270
+ //inbound message
271
+ if(message){
272
+ const msgID = msgId+id
273
+ if(!this.#msgIdtracker.includes(msgID)){
274
+ this.#msgIdtracker.push(msgID)
275
+ this.#rooms[room].onMessage(message,id)
276
+ }
277
+ }
278
+
263
279
  }
264
280
  }
265
281
 
@@ -459,13 +475,47 @@ class webpeerjs{
459
475
 
460
476
  })
461
477
 
462
- setInterval(()=>{
478
+ setTimeout(()=>{
463
479
  this.#dialQueueList()
464
- },5e3)
480
+ setInterval(()=>{
481
+ this.#dialQueueList()
482
+ },5e3)
483
+ },10e3)
484
+
485
+
465
486
 
466
487
  setInterval(()=>{
467
488
  this.#trackLastSeen()
468
489
  },5e3)
490
+
491
+ setInterval(async()=>{
492
+ /*const peerId = peerIdFromString('QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN')
493
+ //const peerInfo = await this.#libp2p.services.aminoDHT.findPeer(peerId)
494
+
495
+ //console.info(peerInfo)
496
+ for await (const event of this.#libp2p.services.aminoDHT.findPeer(peerId)){
497
+ console.info(event)
498
+ }*/
499
+ },5e3)
500
+
501
+ /*setTimeout(async()=>{
502
+ try{
503
+ //console.log('getClosestPeers')
504
+ const digest = await getDigest()
505
+ //console.log('digest',digest)
506
+ for await (const event of this.#libp2p.services.aminoDHT.getClosestPeers(digest)){
507
+ if (event.name === 'FINAL_PEER'){
508
+ //event.peer.multiaddrs.forEach((ma) => {
509
+ //console.log(event.peer.id.toString(),ma.toString())
510
+ //})
511
+ //console.log(event.peer.id.toString(),event.peer.multiaddrs.toString())
512
+ }
513
+ }
514
+ }
515
+ catch(err){
516
+ console.error('query error', err)
517
+ }
518
+ },60e3)*/
469
519
 
470
520
  }
471
521
 
@@ -655,7 +705,8 @@ class webpeerjs{
655
705
  onMessage : () => {},
656
706
  listenMessage : f => (this.#rooms[room] = {...this.#rooms[room], onMessage: f}),
657
707
  sendMessage : async (message) => {
658
- const data = JSON.stringify({prefix:config.CONFIG_PREFIX,room,message,id:this.#libp2p.peerId.toString()})
708
+ const msgId = (new Date()).getTime()
709
+ const data = JSON.stringify({prefix:config.CONFIG_PREFIX,room,message,id:this.#libp2p.peerId.toString(),msgId})
659
710
  const peer = {
660
711
  publicKey: this.#libp2p.peerId.publicKey,
661
712
  addrs: [uint8ArrayFromString(data)],
@@ -737,14 +788,16 @@ class webpeerjs{
737
788
  else{
738
789
  const bootstrap = config.CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS
739
790
  const index = bootstrap.findIndex((peer)=>peer.Peers[0].ID == id)
740
- const addrs = bootstrap[index].Peers[0].Addrs
741
- let mddrs = []
742
- for(const addr of addrs){
743
- const peeraddr = addr+'/p2p/'+id
744
- const mddr = multiaddr(peeraddr)
745
- mddrs.push(mddr)
791
+ if(index > -1){
792
+ const addrs = bootstrap[index].Peers[0].Addrs
793
+ let mddrs = []
794
+ for(const addr of addrs){
795
+ const peeraddr = addr+'/p2p/'+id
796
+ const mddr = multiaddr(peeraddr)
797
+ mddrs.push(mddr)
798
+ }
799
+ this.#dialMultiaddress(mddrs)
746
800
  }
747
- this.#dialMultiaddress(mddrs)
748
801
  }
749
802
  }
750
803
  }
@@ -866,12 +919,12 @@ class webpeerjs{
866
919
 
867
920
  //dial to all known bootstrap peers and DNS
868
921
  #dialKnownPeers(){
869
- this.#dialKnownBootstrap()
870
- setTimeout(()=>{
871
- const peers = this.#libp2p.getPeers().length
872
- if(peers == 0){
922
+ //this.#dialKnownBootstrap()
923
+ //setTimeout(()=>{
924
+ //const peers = this.#libp2p.getPeers().length
925
+ //if(peers == 0){
873
926
  //currently not needed
874
- //this.#dialKnownID()
927
+ this.#dialKnownID()
875
928
  setTimeout(()=>{
876
929
  const peers = this.#libp2p.getPeers().length
877
930
  if(peers == 0){
@@ -886,8 +939,8 @@ class webpeerjs{
886
939
  },15000)
887
940
  }
888
941
  },15000)
889
- }
890
- },15000)
942
+ //}
943
+ //},15000)
891
944
  }
892
945
 
893
946
 
@@ -916,7 +969,7 @@ class webpeerjs{
916
969
 
917
970
 
918
971
  //dial based on known peers ID
919
- /*async #dialKnownID(){
972
+ async #dialKnownID(){
920
973
  const api = config.CONFIG_DELEGATED_API
921
974
  const delegatedClient = createDelegatedRoutingV1HttpApiClient(api)
922
975
  const BOOTSTRAP_PEER_IDS = config.CONFIG_KNOWN_BOOTSTRAP_PEER_IDS
@@ -941,7 +994,7 @@ class webpeerjs{
941
994
  this.#dialMultiaddress(mddrs)
942
995
  }
943
996
  }
944
- }*/
997
+ }
945
998
 
946
999
 
947
1000
  //dial based on known bootstrap DNS
@@ -1113,7 +1166,7 @@ class webpeerjs{
1113
1166
  autoDialConcurrency:0,
1114
1167
  autoDialMaxQueueLength:0,
1115
1168
  autoDialPriority:1000,
1116
- autoDialDiscoveredPeersDebounce:30e3,
1169
+ autoDialDiscoveredPeersDebounce:60e3,
1117
1170
  maxParallelDials: 3,
1118
1171
  dialTimeout: 5e3,
1119
1172
  maxIncomingPendingConnections: 5,
@@ -1125,8 +1178,8 @@ class webpeerjs{
1125
1178
  connectionEncryption: [noise()],
1126
1179
  streamMuxers: [
1127
1180
  yamux({
1128
- maxInboundStreams: 50,
1129
- maxOutboundStreams: 50,
1181
+ maxInboundStreams: 20,
1182
+ maxOutboundStreams: 20,
1130
1183
  })
1131
1184
  ],
1132
1185
  connectionGater: {
@@ -1164,6 +1217,7 @@ class webpeerjs{
1164
1217
  allowPublishToZeroTopicPeers: true,
1165
1218
  msgIdFn: msgIdFnStrictNoSign,
1166
1219
  ignoreDuplicatePublishError: true,
1220
+ runOnTransientConnection:true,
1167
1221
  }),
1168
1222
  identify: identify(),
1169
1223
  identifyPush: identifyPush(),