Skip to content

Commit d96b499

Browse files
committed
update to support new Transport interface
Refs libp2p#2652
1 parent e8207f9 commit d96b499

File tree

5 files changed

+418
-311
lines changed

5 files changed

+418
-311
lines changed

transports/webrtc/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ futures-lite = "1"
1818
futures-timer = "3"
1919
hex = "0.4"
2020
if-watch = "0.2"
21-
libp2p-core = { version = "0.33.0", path = "../../core", default-features = false }
22-
libp2p-noise = { version = "0.36.0", path = "../../transports/noise" }
21+
libp2p-core = { version = "0.34.0", path = "../../core", default-features = false }
22+
libp2p-noise = { version = "0.37.0", path = "../../transports/noise" }
2323
log = "0.4"
2424
serde = { version = "1.0", features = ["derive"] }
2525
stun = "0.4"
@@ -35,8 +35,8 @@ webrtc-util = { version = "0.5.3", default-features = false, features = ["conn",
3535
[dev-dependencies]
3636
anyhow = "1.0"
3737
env_logger = "0.9"
38-
libp2p-request-response = { version = "0.18.0", path = "../../protocols/request-response" }
39-
libp2p-swarm = { version = "0.36.0", path = "../../swarm" }
38+
libp2p-request-response = { version = "0.20.0", path = "../../protocols/request-response" }
39+
libp2p-swarm = { version = "0.38.0", path = "../../swarm" }
4040
rand = "0.8"
4141
rand_core = "0.5"
4242
rcgen = "0.9"

transports/webrtc/src/connection.rs

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use webrtc::peer_connection::RTCPeerConnection;
3333
use webrtc_data::data_channel::DataChannel as DetachedDataChannel;
3434

3535
use std::io;
36-
use std::pin::Pin;
3736
use std::sync::{Arc, Mutex as StdMutex};
3837
use std::task::{Context, Poll};
3938

@@ -226,68 +225,68 @@ impl<'a> StreamMuxer for Connection {
226225
/// abruptly interrupt the execution.
227226
fn destroy_outbound(&self, _s: Self::OutboundSubstream) {}
228227

229-
fn read_substream(
230-
&self,
231-
cx: &mut Context<'_>,
232-
s: &mut Self::Substream,
233-
buf: &mut [u8],
234-
) -> Poll<Result<usize, Self::Error>> {
235-
Pin::new(s).poll_read(cx, buf)
236-
}
237-
238-
fn write_substream(
239-
&self,
240-
cx: &mut Context<'_>,
241-
s: &mut Self::Substream,
242-
buf: &[u8],
243-
) -> Poll<Result<usize, Self::Error>> {
244-
Pin::new(s).poll_write(cx, buf)
245-
}
246-
247-
fn flush_substream(
248-
&self,
249-
cx: &mut Context<'_>,
250-
s: &mut Self::Substream,
251-
) -> Poll<Result<(), Self::Error>> {
252-
trace!("Flushing substream {}", s.stream_identifier());
253-
Pin::new(s).poll_flush(cx)
254-
}
255-
256-
fn shutdown_substream(
257-
&self,
258-
cx: &mut Context<'_>,
259-
s: &mut Self::Substream,
260-
) -> Poll<Result<(), Self::Error>> {
261-
trace!("Closing substream {}", s.stream_identifier());
262-
Pin::new(s).poll_close(cx)
263-
}
264-
265-
fn destroy_substream(&self, s: Self::Substream) {
266-
trace!("Destroying substream {}", s.stream_identifier());
267-
let mut data_channels_inner = self.data_channels_inner.lock().unwrap();
268-
data_channels_inner.map.remove(&s.stream_identifier());
269-
}
228+
// fn read_substream(
229+
// &self,
230+
// cx: &mut Context<'_>,
231+
// s: &mut Self::Substream,
232+
// buf: &mut [u8],
233+
// ) -> Poll<Result<usize, Self::Error>> {
234+
// Pin::new(s).poll_read(cx, buf)
235+
// }
236+
237+
// fn write_substream(
238+
// &self,
239+
// cx: &mut Context<'_>,
240+
// s: &mut Self::Substream,
241+
// buf: &[u8],
242+
// ) -> Poll<Result<usize, Self::Error>> {
243+
// Pin::new(s).poll_write(cx, buf)
244+
// }
245+
246+
// fn flush_substream(
247+
// &self,
248+
// cx: &mut Context<'_>,
249+
// s: &mut Self::Substream,
250+
// ) -> Poll<Result<(), Self::Error>> {
251+
// trace!("Flushing substream {}", s.stream_identifier());
252+
// Pin::new(s).poll_flush(cx)
253+
// }
254+
255+
// fn shutdown_substream(
256+
// &self,
257+
// cx: &mut Context<'_>,
258+
// s: &mut Self::Substream,
259+
// ) -> Poll<Result<(), Self::Error>> {
260+
// trace!("Closing substream {}", s.stream_identifier());
261+
// Pin::new(s).poll_close(cx)
262+
// }
263+
264+
// fn destroy_substream(&self, s: Self::Substream) {
265+
// trace!("Destroying substream {}", s.stream_identifier());
266+
// let mut data_channels_inner = self.data_channels_inner.lock().unwrap();
267+
// data_channels_inner.map.remove(&s.stream_identifier());
268+
// }
270269

271270
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
272271
debug!("Closing connection");
273272

274273
let mut data_channels_inner = self.data_channels_inner.lock().unwrap();
275274

276275
// First, flush all the buffered data.
277-
for (_, ch) in &mut data_channels_inner.map {
278-
match ready!(self.flush_substream(cx, ch)) {
279-
Ok(_) => continue,
280-
Err(e) => return Poll::Ready(Err(e)),
281-
}
282-
}
276+
// for (_, ch) in &mut data_channels_inner.map {
277+
// match ready!(self.flush_substream(cx, ch)) {
278+
// Ok(_) => continue,
279+
// Err(e) => return Poll::Ready(Err(e)),
280+
// }
281+
// }
283282

284283
// Second, shutdown all the substreams.
285-
for (_, ch) in &mut data_channels_inner.map {
286-
match ready!(self.shutdown_substream(cx, ch)) {
287-
Ok(_) => continue,
288-
Err(e) => return Poll::Ready(Err(e)),
289-
}
290-
}
284+
// for (_, ch) in &mut data_channels_inner.map {
285+
// match ready!(self.shutdown_substream(cx, ch)) {
286+
// Ok(_) => continue,
287+
// Err(e) => return Poll::Ready(Err(e)),
288+
// }
289+
// }
291290

292291
// Third, close `incoming_data_channels_rx`
293292
data_channels_inner.incoming_data_channels_rx.close();

transports/webrtc/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub enum Error {
4242
got: PeerId,
4343
},
4444

45+
#[error("no active listeners")]
46+
NoListeners,
47+
4548
#[error("internal error: {0} (see debug logs)")]
4649
InternalError(String),
4750
}

0 commit comments

Comments
 (0)