Skip to content

Commit

Permalink
feat: latest-dcutr updates from libp2p/js-libp2p/pull/1928
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Aug 10, 2023
1 parent 800607b commit f613fab
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@libp2p/mplex": "^9.0.2",
"@libp2p/webrtc": "^3.1.3",
"@libp2p/websockets": "^7.0.2",
"@libp2p/webtransport": "^3.0.3",
"@multiformats/multiaddr-matcher": "^1.0.1",
"blockstore-core": "^4.2.0",
"blockstore-level": "^1.1.1",
Expand Down
7 changes: 4 additions & 3 deletions patches/@libp2p+interface-internal+0.1.2.patch
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
diff --git a/node_modules/@libp2p/interface-internal/dist/src/connection-manager/index.d.ts b/node_modules/@libp2p/interface-internal/dist/src/connection-manager/index.d.ts
index 14d3f8c..8e6d2a9 100644
index 14d3f8c..5c51718 100644
--- a/node_modules/@libp2p/interface-internal/dist/src/connection-manager/index.d.ts
+++ b/node_modules/@libp2p/interface-internal/dist/src/connection-manager/index.d.ts
@@ -3,6 +3,11 @@ import type { Connection, MultiaddrConnection } from '@libp2p/interface/connecti
@@ -3,6 +3,12 @@ import type { Connection, MultiaddrConnection } from '@libp2p/interface/connecti
import type { PeerId } from '@libp2p/interface/peer-id';
import type { PeerMap } from '@libp2p/peer-collections';
import type { Multiaddr } from '@multiformats/multiaddr';
+
+export interface OpenConnectionOptions extends AbortOptions {
+ priority?: number
+ force?: boolean
+}
+
export interface ConnectionManager {
/**
* Return connections, optionally filtering by a PeerId
@@ -34,7 +39,7 @@ export interface ConnectionManager {
@@ -34,7 +40,7 @@ export interface ConnectionManager {
* const connection = await libp2p.connectionManager.openConnection(peerId)
* ```
*/
Expand Down
13 changes: 13 additions & 0 deletions patches/libp2p+0.46.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,16 @@ index 11bda5d..2490f0b 100644
/**
* Responsible for managing known connections.
*/
diff --git a/node_modules/libp2p/dist/src/connection-manager/index.js b/node_modules/libp2p/dist/src/connection-manager/index.js
index fa40713..8b57329 100644
--- a/node_modules/libp2p/dist/src/connection-manager/index.js
+++ b/node_modules/libp2p/dist/src/connection-manager/index.js
@@ -300,7 +300,7 @@ export class DefaultConnectionManager {
}
options.signal?.throwIfAborted();
const { peerId } = getPeerAddress(peerIdOrMultiaddr);
- if (peerId != null) {
+ if (peerId != null && options.force !== true) {
log('dial %p', peerId);
const existingConnections = this.getConnections(peerId);
if (existingConnections.length > 0) {
3 changes: 2 additions & 1 deletion src/dcutr/dcutr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ export class DefaultDCUtRService implements Startable {
})
const newDirectConnection = await this.connectionManager.openConnection(multiaddrs, {
signal,
priority: DCUTR_DIAL_PRIORITY
priority: DCUTR_DIAL_PRIORITY,
force: true
})
// if (tcpMultiaddrs.length > 0) {
// connectAttempts.push(this.simultaneousConnectTCP(tcpMultiaddrs, simulConnectAbortController.signal))
Expand Down
8 changes: 4 additions & 4 deletions src/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { type DualKadDHT, kadDHT } from '@libp2p/kad-dht'
import { mplex } from '@libp2p/mplex'
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
// import { webTransport } from '@libp2p/webtransport'
import { webTransport } from './webtransport'
import { webTransport } from '@libp2p/webtransport'
// import { webTransport } from './webtransport'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import { autoNATService } from 'libp2p/autonat'
Expand Down Expand Up @@ -56,12 +56,12 @@ export function libp2pDefaults (): Libp2pOptions<{ dht: DualKadDHT, pubsub: PubS
ipniContentRouting('https://cid.contact')
],
services: {
dcutr: dcutrService(),
dcutr: dcutrService({ timeout: 15000 }),
identify: identifyService(),
autoNAT: autoNATService(),
// pubsub: gossipsub(),
dht: kadDHT({
clientMode: true,
clientMode: false,
validators: {
ipns: ipnsValidator
},
Expand Down
8 changes: 5 additions & 3 deletions src/provider/HeliaProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ export const HeliaProvider = ({ children }) => {
}, [helia])

useEffect(() => {
if (helia == null) {
if (helia == null || fs == null) {
return
}
(window as any).helia = helia
(window as any).helia = helia;
(window as any).heliaFs = fs;

let timeoutId: any = null
const refreshFn = async () => {
updateInfo()
Expand Down Expand Up @@ -122,7 +124,7 @@ export const HeliaProvider = ({ children }) => {
clearTimeout(timeoutId)
}

}, [helia])
}, [helia, fs, updateInfo])


return (
Expand Down

0 comments on commit f613fab

Please sign in to comment.