johanhelsing / matchbox

Painless peer-to-peer WebRTC networking for rust wasm (and native!)
Apache License 2.0
869 stars 72 forks source link

feat: socket/channel closed detection #337

Closed simbleau closed 8 months ago

simbleau commented 11 months ago

The logic to close and check sockets/channels if they are closed.

One thing is noticeably absent: How do we disconnect a specific peer? I have a client/server topology, and I need a server socket to kick specific clients under certain conditions.

Closes #286

simbleau commented 11 months ago

On further investigation, I think I know a potential way to sever connections.

We would need a new signal type: Disconnect, as such:

image

And in the signaling server topologies, the peer disconnection could be handled:

image

This would require we maintain ownership of the WebSocket object, so we can do ws.close().

That's not currently possible because we split the websocket into a Sink and a Stream, and I'm not well versed enough to know what the correct way to proceed. Do we "reunite them"? Do we only need to drop the Sink? I have no idea. Probably something @johanhelsing or @garryod could help or answer.

image
simbleau commented 11 months ago

@johanhelsing @garryod thoughts?

johanhelsing commented 11 months ago

Why does signaling need to be involved in this? couldn't the server socket just close the connection?

simbleau commented 11 months ago

Why does signaling need to be involved in this? couldn't the server socket just close the connection?

That would be good, but I can't find out how to accomplish closing the socket for a specific peer.

Any ideas @johanhelsing ?

johanhelsing commented 10 months ago

Why does signaling need to be involved in this? couldn't the server socket just close the connection?

That would be good, but I can't find out how to accomplish closing the socket for a specific peer.

Any ideas @johanhelsing ?

What's the problem?

Wouldn't socket.disconnect(peer) work?

simbleau commented 10 months ago

Why does signaling need to be involved in this? couldn't the server socket just close the connection?

That would be good, but I can't find out how to accomplish closing the socket for a specific peer. Any ideas @johanhelsing ?

What's the problem?

Wouldn't socket.disconnect(peer) work?

So, for WebRtcSocket you're suggesting a .disconnect(peer), which I like for an API.

I'm just unsure how it should be implemented. The problems I'm facing are:

simbleau commented 9 months ago

@johanhelsing Updated to detect is channels and sockets are closed, but removed the socket.disconnect(PeerId) API as a todo since it's hard.