diff options
| author | acdenisSK <[email protected]> | 2017-07-24 01:47:39 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-24 01:51:36 +0200 |
| commit | e72e25cf8b0160a3ec0de0be98dd8f1467d3b505 (patch) | |
| tree | 0509c1cefea9f1fc95a8b50d3f0556becdb16603 /src | |
| parent | Also ignore data frame errors (diff) | |
| download | serenity-e72e25cf8b0160a3ec0de0be98dd8f1467d3b505.tar.xz serenity-e72e25cf8b0160a3ec0de0be98dd8f1467d3b505.zip | |
Revert the ignoring of protocol and data frame errors, while actually handling ping pongs
When receiving pings, serenity MUST send the pong with the same data as the ping. Well, as said in the rfc for websockets anyway. Though, regarding the errors, i found out that serenity's gateway wouldn't work, but i do see that i'll have to file an issue to see if they know why are these happening at all
Diffstat (limited to 'src')
| -rw-r--r-- | src/gateway/shard.rs | 2 | ||||
| -rw-r--r-- | src/http/mod.rs | 2 | ||||
| -rw-r--r-- | src/internal/ws_impl.rs | 28 |
3 files changed, 18 insertions, 14 deletions
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs index 5dcd4d1..473c17b 100644 --- a/src/gateway/shard.rs +++ b/src/gateway/shard.rs @@ -495,8 +495,6 @@ impl Shard { self.reconnect().and(Ok(None)) } }, - Err(Error::WebSocket(WebSocketError::ProtocolError(..))) - | Err(Error::WebSocket(WebSocketError::DataFrameError(..))) => Ok(None), Err(Error::WebSocket(why)) => { if let WebSocketError::NoDataAvailable = why { if self.heartbeat_instants.1.is_none() { diff --git a/src/http/mod.rs b/src/http/mod.rs index 850f800..71b5885 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -295,7 +295,9 @@ pub fn create_permission(channel_id: u64, target_id: u64, map: &Value) -> Result /// Creates a private channel with a user. pub fn create_private_channel(map: &Value) -> Result<PrivateChannel> { + info!("{:?}", map); let body = map.to_string(); + info!("{}", body); let response = request!(Route::UsersMeChannels, post(body), "/users/@me/channels"); diff --git a/src/internal/ws_impl.rs b/src/internal/ws_impl.rs index 0db40ee..8366a23 100644 --- a/src/internal/ws_impl.rs +++ b/src/internal/ws_impl.rs @@ -17,36 +17,40 @@ pub trait SenderExt { impl ReceiverExt for WsClient<TlsStream<TcpStream>> { fn recv_json<F, T>(&mut self, decode: F) -> Result<T> where F: FnOnce(Value) -> Result<T> { - match self.recv_message()? { + let message = self.recv_message()?; + + if let OwnedMessage::Ping(ref x) = message { + self.send_message(&OwnedMessage::Pong(x.clone())).map_err(Error::from)?; + } + + let res = match message { OwnedMessage::Binary(bytes) => { let value = serde_json::from_reader(ZlibDecoder::new(&bytes[..]))?; - decode(value).map_err(|why| { + Some(decode(value).map_err(|why| { let s = String::from_utf8_lossy(&bytes); warn!("(╯°□°)╯︵ ┻━┻ Error decoding: {}", s); why - }) + })) }, OwnedMessage::Close(data) => { - Err(Error::Gateway(GatewayError::Closed(data))) + Some(Err(Error::Gateway(GatewayError::Closed(data)))) }, OwnedMessage::Text(payload) => { let value = serde_json::from_str(&payload)?; - decode(value).map_err(|why| { + Some(decode(value).map_err(|why| { warn!("(╯°□°)╯︵ ┻━┻ Error decoding: {}", payload); why - }) + })) }, - OwnedMessage::Ping(x) | OwnedMessage::Pong(x) => { - warn!("Unexpectly got ping/pong: {:?}", x); - - Err(Error::Gateway(GatewayError::Closed(None))) - }, - } + OwnedMessage::Ping(..) | OwnedMessage::Pong(..) => None, + }; + + res.unwrap() } } |