xtaci / smux

A Stream Multiplexing Library for golang with least memory usage(TDMA)
MIT License
1.31k stars 196 forks source link

Return result code from remote server? #38

Closed WinstonPrivacy closed 5 years ago

WinstonPrivacy commented 5 years ago

Is it possible to return a result code on a stream from a remote server? This would allow the local client to more quickly determine if a remote error occurred and provide a better user experience.

Examples:

  1. Client opens mux to remote server but uses the wrong cipher. Server responds with a "Reauthorize" code so the client doesn't continue to make connections.

  2. Client opens stream on an existing mux but the server is too busy. Server responds with "Back off" code so the client can drop the mux and open up one elsewhere.

  3. Clients opens stream with http/s request to a remote domain, but the remote is not responding. Server responds with "Can't connect" so the client can error out quickly without waiting for a timeout.

Thanks!

WinstonPrivacy commented 5 years ago

We researched this a little more. This seems to be fairly nuanced because smux drops packets that it doesn't understand.

So if you make a bad request and drop the entire session (as we were doing by accident), the next requests timeout because smux doesn't return anything.

Similarly, if you attempt to connect using a bad cipher, smux doesn't respond. This is probably ideal from a security standpoint though it can inconvenience callers.

This basically means that there needs to be an open smux tunnel between two peers for error messages to be exchanged. And if that's the case, the error messages can be sent at the application level (ie: HTTP).