Skip to content

Commit e7c1910

Browse files
committed
Add message.proto and fix a few mypy-ci errors
1 parent c2ba14d commit e7c1910

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

libp2p/transport/webrtc/async_bridge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ async def __aenter__(self) -> "WebRTCAsyncBridge":
3838
"""Enter async context manager"""
3939
if not self._in_context:
4040
self._loop_context = open_loop()
41-
await self._loop_context.__aenter__()
41+
if self._loop_context:
42+
await self._loop_context.__aenter__()
4243
self._in_context = True
4344
return self
4445

libp2p/transport/webrtc/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def get_muxed_conn(self) -> IMuxedConn:
5656
"""Get the underlying muxed connection."""
5757
return cast(IMuxedConn, self.connection)
5858

59-
def set_protocol(self, protocol: TProtocol) -> None:
59+
def set_protocol(self, protocol_id: TProtocol) -> None:
6060
"""Set the protocol for this stream."""
61-
self.protocol = protocol
62-
logger.debug(f"Stream {self.stream_id} set protocol: {protocol}")
61+
self.protocol = protocol_id
62+
logger.debug(f"Stream {self.stream_id} set protocol: {protocol_id}")
6363

6464
def get_protocol(self) -> TProtocol | None:
6565
"""Get the protocol for this stream."""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
3+
message Message {
4+
// Specifies type in `data` field.
5+
enum Type {
6+
// String of `RTCSessionDescription.sdp`
7+
SDP_OFFER = 0;
8+
// String of `RTCSessionDescription.sdp`
9+
SDP_ANSWER = 1;
10+
// String of `RTCIceCandidate.toJSON()`
11+
ICE_CANDIDATE = 2;
12+
}
13+
14+
optional Type type = 1;
15+
optional string data = 2;
16+
}

libp2p/transport/webrtc/private_to_public/transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def dial(self, maddr: Multiaddr) -> IRawConnection:
186186
peer_id = (
187187
peer_id_str
188188
if isinstance(peer_id_str, ID)
189-
else ID.from_base58(peer_id_str)
189+
else ID.from_base58(str(peer_id_str))
190190
)
191191

192192
# Extract port from multiaddr

0 commit comments

Comments
 (0)