@libp2p/webrtc
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -34,2 +34,3 @@ import type { Connection } from '@libp2p/interface-connection'; | ||
filter(multiaddrs: Multiaddr[]): Multiaddr[]; | ||
private splitAddr; | ||
dial(ma: Multiaddr, options: DialOptions): Promise<Connection>; | ||
@@ -36,0 +37,0 @@ _onProtocol({ connection, stream }: IncomingStreamData): Promise<void>; |
import { symbol } from '@libp2p/interface-transport'; | ||
import { multiaddr, protocols } from '@multiformats/multiaddr'; | ||
import { peerIdFromString } from '@libp2p/peer-id'; | ||
import { WebRTCMultiaddrConnection } from '../maconn.js'; | ||
@@ -47,11 +48,3 @@ import { WebRTCPeerListener } from './listener.js'; | ||
} | ||
/* | ||
* dial connects to a remote via the circuit relay or any other protocol | ||
* and proceeds to upgrade to a webrtc connection. | ||
* multiaddr of the form: <multiaddr>/webrtc/p2p/<destination-peer> | ||
* For a circuit relay, this will be of the form | ||
* <relay address>/p2p/<relay-peer>/p2p-circuit/webrtc/p2p/<destination-peer> | ||
*/ | ||
async dial(ma, options) { | ||
log.trace('dialing address: ', ma); | ||
splitAddr(ma) { | ||
const addrs = ma.toString().split(`${TRANSPORT}/`); | ||
@@ -68,6 +61,2 @@ if (addrs.length !== 2) { | ||
} | ||
if (options.signal == null) { | ||
const controller = new AbortController(); | ||
options.signal = controller.signal; | ||
} | ||
const lastProtoInRemote = remoteAddr.protos().pop(); | ||
@@ -80,3 +69,19 @@ if (lastProtoInRemote === undefined) { | ||
} | ||
const connection = await this.components.transportManager.dial(remoteAddr); | ||
return { baseAddr: remoteAddr, peerId: peerIdFromString(destinationIdString) }; | ||
} | ||
/* | ||
* dial connects to a remote via the circuit relay or any other protocol | ||
* and proceeds to upgrade to a webrtc connection. | ||
* multiaddr of the form: <multiaddr>/webrtc/p2p/<destination-peer> | ||
* For a circuit relay, this will be of the form | ||
* <relay address>/p2p/<relay-peer>/p2p-circuit/webrtc/p2p/<destination-peer> | ||
*/ | ||
async dial(ma, options) { | ||
log.trace('dialing address: ', ma); | ||
const { baseAddr, peerId } = this.splitAddr(ma); | ||
if (options.signal == null) { | ||
const controller = new AbortController(); | ||
options.signal = controller.signal; | ||
} | ||
const connection = await this.components.transportManager.dial(baseAddr); | ||
const rawStream = await connection.newStream([SIGNALING_PROTO_ID], options); | ||
@@ -89,6 +94,7 @@ try { | ||
}); | ||
const webrtcMultiaddr = baseAddr.encapsulate(`${TRANSPORT}/p2p/${peerId.toString()}`); | ||
const result = await options.upgrader.upgradeOutbound(new WebRTCMultiaddrConnection({ | ||
peerConnection: pc, | ||
timeline: { open: (new Date()).getTime() }, | ||
remoteAddr: connection.remoteAddr | ||
remoteAddr: webrtcMultiaddr | ||
}), { | ||
@@ -116,6 +122,8 @@ skipProtection: true, | ||
}); | ||
const remotePeerId = connection.remoteAddr.getPeerId(); | ||
const webrtcMultiaddr = connection.remoteAddr.encapsulate(`${TRANSPORT}/p2p/${remotePeerId}`); | ||
await this.components.upgrader.upgradeInbound(new WebRTCMultiaddrConnection({ | ||
peerConnection: pc, | ||
timeline: { open: (new Date()).getTime() }, | ||
remoteAddr: connection.remoteAddr | ||
remoteAddr: webrtcMultiaddr | ||
}), { | ||
@@ -122,0 +130,0 @@ skipEncryption: true, |
{ | ||
"name": "@libp2p/webrtc", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A libp2p transport using WebRTC connections", | ||
@@ -5,0 +5,0 @@ "author": "", |
@@ -7,2 +7,3 @@ import type { Connection } from '@libp2p/interface-connection' | ||
import type { PeerId } from '@libp2p/interface-peer-id' | ||
import { peerIdFromString } from '@libp2p/peer-id' | ||
import { WebRTCMultiaddrConnection } from '../maconn.js' | ||
@@ -79,11 +80,3 @@ import type { Startable } from '@libp2p/interfaces/startable' | ||
/* | ||
* dial connects to a remote via the circuit relay or any other protocol | ||
* and proceeds to upgrade to a webrtc connection. | ||
* multiaddr of the form: <multiaddr>/webrtc/p2p/<destination-peer> | ||
* For a circuit relay, this will be of the form | ||
* <relay address>/p2p/<relay-peer>/p2p-circuit/webrtc/p2p/<destination-peer> | ||
*/ | ||
async dial (ma: Multiaddr, options: DialOptions): Promise<Connection> { | ||
log.trace('dialing address: ', ma) | ||
private splitAddr (ma: Multiaddr): { baseAddr: Multiaddr, peerId: PeerId } { | ||
const addrs = ma.toString().split(`${TRANSPORT}/`) | ||
@@ -102,7 +95,2 @@ if (addrs.length !== 2) { | ||
if (options.signal == null) { | ||
const controller = new AbortController() | ||
options.signal = controller.signal | ||
} | ||
const lastProtoInRemote = remoteAddr.protos().pop() | ||
@@ -116,4 +104,23 @@ if (lastProtoInRemote === undefined) { | ||
const connection = await this.components.transportManager.dial(remoteAddr) | ||
return { baseAddr: remoteAddr, peerId: peerIdFromString(destinationIdString) } | ||
} | ||
/* | ||
* dial connects to a remote via the circuit relay or any other protocol | ||
* and proceeds to upgrade to a webrtc connection. | ||
* multiaddr of the form: <multiaddr>/webrtc/p2p/<destination-peer> | ||
* For a circuit relay, this will be of the form | ||
* <relay address>/p2p/<relay-peer>/p2p-circuit/webrtc/p2p/<destination-peer> | ||
*/ | ||
async dial (ma: Multiaddr, options: DialOptions): Promise<Connection> { | ||
log.trace('dialing address: ', ma) | ||
const { baseAddr, peerId } = this.splitAddr(ma) | ||
if (options.signal == null) { | ||
const controller = new AbortController() | ||
options.signal = controller.signal | ||
} | ||
const connection = await this.components.transportManager.dial(baseAddr) | ||
const rawStream = await connection.newStream([SIGNALING_PROTO_ID], options) | ||
@@ -127,2 +134,3 @@ | ||
}) | ||
const webrtcMultiaddr = baseAddr.encapsulate(`${TRANSPORT}/p2p/${peerId.toString()}`) | ||
const result = await options.upgrader.upgradeOutbound( | ||
@@ -132,3 +140,3 @@ new WebRTCMultiaddrConnection({ | ||
timeline: { open: (new Date()).getTime() }, | ||
remoteAddr: connection.remoteAddr | ||
remoteAddr: webrtcMultiaddr | ||
}), | ||
@@ -159,6 +167,8 @@ { | ||
}) | ||
const remotePeerId = connection.remoteAddr.getPeerId() | ||
const webrtcMultiaddr = connection.remoteAddr.encapsulate(`${TRANSPORT}/p2p/${remotePeerId}`) | ||
await this.components.upgrader.upgradeInbound(new WebRTCMultiaddrConnection({ | ||
peerConnection: pc, | ||
timeline: { open: (new Date()).getTime() }, | ||
remoteAddr: connection.remoteAddr | ||
remoteAddr: webrtcMultiaddr | ||
}), { | ||
@@ -165,0 +175,0 @@ skipEncryption: true, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
634075
5180