/** * Truncate arbitrary reason into something that will fit into the CloseFrame limits. * * @param reason * the arbitrary reason to possibly truncate. * @return the possibly truncated reason string. */ public static String truncate(String reason) { return StringUtil.truncate(reason,(ControlFrame.MAX_CONTROL_PAYLOAD - 2)); } }
protected void terminateConnection(int statusCode, String rawreason) { String reason = rawreason; reason = StringUtil.truncate(reason,(WebSocketFrame.MAX_CONTROL_PAYLOAD - 2)); LOG.debug("terminateConnection({},{})",statusCode,rawreason); session.close(statusCode,reason); }
protected void terminateConnection(int statusCode, String rawreason) { String reason = rawreason; reason = StringUtil.truncate(reason,(WebSocketFrame.MAX_CONTROL_PAYLOAD - 2)); LOG.debug("terminateConnection({},{})",statusCode,rawreason); session.close(statusCode,reason); }
protected void terminateConnection(int statusCode, String rawreason) { String reason = rawreason; reason = StringUtil.truncate(reason,(WebSocketFrame.MAX_CONTROL_PAYLOAD - 2)); LOG.debug("terminateConnection({},{})",statusCode,rawreason); session.close(statusCode,reason); }
/** * Incoming mux control block, destined for the control channel (id 0) */ @Override public void onMuxDropChannel(MuxDropChannel drop) { // Process channel long channelId = drop.getChannelId(); MuxChannel channel = getChannel(channelId,false); String reason = "Mux " + drop.toString(); reason = StringUtil.truncate(reason,(WebSocketFrame.MAX_CONTROL_PAYLOAD - 2)); channel.close(StatusCode.PROTOCOL,reason); // TODO: set channel to inactive? }
/** * Incoming mux control block, destined for the control channel (id 0) */ @Override public void onMuxDropChannel(MuxDropChannel drop) { // Process channel long channelId = drop.getChannelId(); MuxChannel channel = getChannel(channelId,false); String reason = "Mux " + drop.toString(); reason = StringUtil.truncate(reason,(WebSocketFrame.MAX_CONTROL_PAYLOAD - 2)); channel.close(StatusCode.PROTOCOL,reason); // TODO: set channel to inactive? }
/** * Incoming mux control block, destined for the control channel (id 0) */ @Override public void onMuxDropChannel(MuxDropChannel drop) { if (drop.getChannelId() == CONTROL_CHANNEL_ID) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"Invalid Channel ID"); } // Process channel long channelId = drop.getChannelId(); MuxChannel channel = this.channels.get(channelId); if (channel == null) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"Unknown Channel ID"); } String reason = "Mux " + drop.toString(); reason = StringUtil.truncate(reason,(WebSocketFrame.MAX_CONTROL_PAYLOAD - 2)); channel.close(StatusCode.PROTOCOL,reason); // TODO: set channel to inactive? }
/** * Per spec, the physical connection must be failed. * <p> * <a href="https://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-08#section-18">Section 18. Fail the Physical Connection.</a> * * <blockquote> To _Fail the Physical Connection_, an endpoint MUST send a DropChannel multiplex control block with objective channel ID of 0 and drop * reason code in the range of 2000-2999, and then _Fail the WebSocket Connection_ on the physical connection with status code of 1011. </blockquote> */ private void mustFailPhysicalConnection(MuxPhysicalConnectionException muxe) { // TODO: stop muxer from receiving incoming sub-channel traffic. MuxDropChannel drop = muxe.getMuxDropChannel(); LOG.warn(muxe); try { generator.generate(null,drop); } catch (IOException ioe) { LOG.warn("Unable to send mux DropChannel",ioe); } String reason = "Mux[MUST FAIL]" + drop.getPhrase(); reason = StringUtil.truncate(reason,WebSocketFrame.MAX_CONTROL_PAYLOAD); this.physicalConnection.close(StatusCode.SERVER_ERROR,reason); // TODO: trigger abnormal close for all sub-channels. }
/** * Per spec, the physical connection must be failed. * <p> * <a href="https://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-08#section-18">Section 18. Fail the Physical Connection.</a> * * <blockquote> To _Fail the Physical Connection_, an endpoint MUST send a DropChannel multiplex control block with objective channel ID of 0 and drop * reason code in the range of 2000-2999, and then _Fail the WebSocket Connection_ on the physical connection with status code of 1011. </blockquote> */ private void mustFailPhysicalConnection(MuxPhysicalConnectionException muxe) { // TODO: stop muxer from receiving incoming sub-channel traffic. MuxDropChannel drop = muxe.getMuxDropChannel(); LOG.warn(muxe); try { generator.generate(null,drop); } catch (IOException ioe) { LOG.warn("Unable to send mux DropChannel",ioe); } String reason = "Mux[MUST FAIL]" + drop.getPhrase(); reason = StringUtil.truncate(reason,WebSocketFrame.MAX_CONTROL_PAYLOAD); this.physicalConnection.close(StatusCode.SERVER_ERROR,reason); // TODO: trigger abnormal close for all sub-channels. }
/** * Per spec, the physical connection must be failed. * <p> * <a href="https://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-08#section-18">Section 18. Fail the Physical Connection.</a> * * <blockquote> To _Fail the Physical Connection_, an endpoint MUST send a DropChannel multiplex control block with objective channel ID of 0 and drop * reason code in the range of 2000-2999, and then _Fail the WebSocket Connection_ on the physical connection with status code of 1011. </blockquote> */ private void mustFailPhysicalConnection(MuxPhysicalConnectionException muxe) { // TODO: stop muxer from receiving incoming sub-channel traffic. MuxDropChannel drop = muxe.getMuxDropChannel(); LOG.warn(muxe); try { generator.generate(drop); } catch (IOException ioe) { LOG.warn("Unable to send mux DropChannel",ioe); } String reason = "Mux[MUST FAIL]" + drop.getPhrase(); reason = StringUtil.truncate(reason,WebSocketFrame.MAX_CONTROL_PAYLOAD); this.physicalConnection.close(StatusCode.SERVER_ERROR,reason); // TODO: trigger abnormal close for all sub-channels. }