Skip to content

Commit

Permalink
add webRTCDirect transport and bind to 0.0.0.0 in rust peer
Browse files Browse the repository at this point in the history
  • Loading branch information
p-shahi committed Apr 6, 2023
1 parent 6a47031 commit 01cb60c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 2 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 packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@libp2p/webrtc": "github:libp2p/js-libp2p-webrtc#feat/browser-to-browser",
"@libp2p/websockets": "^5.0.3",
"@libp2p/webtransport": "^1.0.7",
"@multiformats/mafmt": "^12.0.0",
"@multiformats/multiaddr": "^12.0.0",
"@types/node": "18.14.6",
"@types/react": "18.0.28",
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/lib/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { create as KuboClient } from 'kubo-rpc-client'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { webSockets } from '@libp2p/websockets'
import { webTransport } from '@libp2p/webtransport'
import { webRTC } from '@libp2p/webrtc'
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
import { PeerId } from 'kubo-rpc-client/dist/src/types'
import { CHAT_TOPIC } from './constants'

Expand All @@ -43,7 +43,7 @@ export async function startLibp2p(options: {} = {}) {
const libp2p = await createLibp2p({
// dht: kadDHT(),
datastore,
transports: [webTransport(), webSockets(), webRTC()],
transports: [webTransport(), webSockets(), webRTC(), webRTCDirect()],
// transports: [webRTC()],
connectionEncryption: [noise()],
streamMuxers: [yamux()],
Expand Down
4 changes: 2 additions & 2 deletions rust-peer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ async fn main() -> Result<()> {

let mut swarm = create_swarm()?;

swarm.listen_on(format!("/ip4/0.0.0.0/udp/9090/webrtc").parse()?)?;
swarm.listen_on(format!("/ip4/0.0.0.0/udp/9090/webrtc-direct").parse()?)?;

if let Some(listen_address) = opt.listen_address {
swarm.add_external_address(
format!("/ip4/{}/udp/9090/webrtc", listen_address).parse()?,
format!("/ip4/{}/udp/9090/webrtc-direct", listen_address).parse()?,
AddressScore::Infinite,
);
}
Expand Down

0 comments on commit 01cb60c

Please sign in to comment.