/** * Write an OP out the physical connection. * * @param op * the mux operation to write * @throws IOException */ public void output(MuxControlBlock op) throws IOException { generator.generate(null,op); }
public void setOutgoingFramesHandler(OutgoingFrames outgoing) { this.generator.setOutgoing(outgoing); }
/** * Write a 1/3/9 encoded size, then a byte buffer of that size. * * @param payload * @param buffer */ public void write139Buffer(ByteBuffer payload, ByteBuffer buffer) { write139Size(payload,buffer.remaining()); writeBuffer(payload,buffer); }
BufferUtil.flipToFill(payload); writeChannelId(payload,0); // control channel b |= (op.getEncoding() & 0x03); // enc writeChannelId(payload,op.getChannelId()); write139Buffer(payload,op.getHandshake()); break; writeChannelId(payload,op.getChannelId()); if (op.getHandshake() != null) write139Buffer(payload,op.getHandshake()); write139Size(payload,0); writeChannelId(payload,op.getChannelId()); write139Buffer(payload,op.asReasonBuffer()); break; writeChannelId(payload,op.getChannelId()); write139Size(payload,op.getSendQuotaSize()); break; write139Size(payload,op.getNumberOfSlots()); write139Size(payload,op.getInitialSendQuota()); break;
public Muxer(final LogicalConnection connection) { this.physicalConnection = connection; this.policy = connection.getPolicy().clonePolicy(); this.parser = new MuxParser(); this.parser.setEvents(this); this.generator = new MuxGenerator(); }
public void generate(long channelId, Frame frame, WriteCallback callback) { ByteBuffer muxPayload = bufferPool.acquire(frame.getPayloadLength() + DATA_FRAME_OVERHEAD,true); BufferUtil.flipToFill(muxPayload); // start building mux payload writeChannelId(muxPayload,channelId); byte b = (byte)(frame.isFin()?0x80:0x00); // fin b |= (byte)(frame.isRsv1()?0x40:0x00); // rsv1 b |= (byte)(frame.isRsv2()?0x20:0x00); // rsv2 b |= (byte)(frame.isRsv3()?0x10:0x00); // rsv3 b |= (byte)(frame.getType().getOpCode() & 0x0F); // opcode muxPayload.put(b); BufferUtil.put(frame.getPayload(),muxPayload); // build muxed frame WebSocketFrame muxFrame = WebSocketFrame.binary(); BufferUtil.flipToFlush(muxPayload,0); muxFrame.setPayload(muxPayload); // NOTE: the physical connection will handle masking rules for this frame. // release original buffer (no longer needed) bufferPool.release(frame.getPayload()); // send muxed frame down to the physical connection. outgoing.outgoingFrame(muxFrame,callback); }
BufferUtil.flipToFill(payload); writeChannelId(payload,0); // control channel b |= (op.getEncoding() & 0x03); // enc writeChannelId(payload,op.getChannelId()); write139Buffer(payload,op.getHandshake()); break; writeChannelId(payload,op.getChannelId()); if (op.getHandshake() != null) write139Buffer(payload,op.getHandshake()); write139Size(payload,0); writeChannelId(payload,op.getChannelId()); write139Buffer(payload,op.asReasonBuffer()); break; writeChannelId(payload,op.getChannelId()); write139Size(payload,op.getSendQuotaSize()); break; write139Size(payload,op.getNumberOfSlots()); write139Size(payload,op.getInitialSendQuota()); break;
public Muxer(final LogicalConnection connection) { this.physicalConnection = connection; this.policy = connection.getPolicy().clonePolicy(); this.parser = new MuxParser(); this.parser.setEvents(this); this.generator = new MuxGenerator(); }
public void generate(long channelId, Frame frame, WriteCallback callback) { ByteBuffer muxPayload = bufferPool.acquire(frame.getPayloadLength() + DATA_FRAME_OVERHEAD,true); BufferUtil.flipToFill(muxPayload); // start building mux payload writeChannelId(muxPayload,channelId); byte b = (byte)(frame.isFin()?0x80:0x00); // fin b |= (byte)(frame.isRsv1()?0x40:0x00); // rsv1 b |= (byte)(frame.isRsv2()?0x20:0x00); // rsv2 b |= (byte)(frame.isRsv3()?0x10:0x00); // rsv3 b |= (byte)(frame.getType().getOpCode() & 0x0F); // opcode muxPayload.put(b); BufferUtil.put(frame.getPayload(),muxPayload); // build muxed frame WebSocketFrame muxFrame = WebSocketFrame.binary(); BufferUtil.flipToFlush(muxPayload,0); muxFrame.setPayload(muxPayload); // NOTE: the physical connection will handle masking rules for this frame. // release original buffer (no longer needed) bufferPool.release(frame.getPayload()); // send muxed frame down to the physical connection. outgoing.outgoingFrame(muxFrame,callback); }
/** * Write a 1/3/9 encoded size, then a byte buffer of that size. * * @param payload * @param buffer */ public void write139Buffer(ByteBuffer payload, ByteBuffer buffer) { write139Size(payload,buffer.remaining()); writeBuffer(payload,buffer); }
/** * Write an OP out the physical connection. * * @param op * the mux operation to write * @throws IOException */ public void output(MuxControlBlock op) throws IOException { generator.generate(null,op); }
public void setOutgoingFramesHandler(OutgoingFrames outgoing) { this.generator.setOutgoing(outgoing); }
/** * Outgoing frame, without mux encapsulated payload. */ public void output(long channelId, Frame frame, WriteCallback callback) { if (LOG.isDebugEnabled()) { LOG.debug("output({}, {})",channelId,frame,callback); } generator.generate(channelId,frame,callback); }
/** * Outgoing frame, without mux encapsulated payload. */ public void output(long channelId, Frame frame, WriteCallback callback) { if (LOG.isDebugEnabled()) { LOG.debug("output({}, {})",channelId,frame,callback); } generator.generate(channelId,frame,callback); }
/** * 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. }