Refine search
private void deliverRawText0(String text){ boolean errorDelivering = false; IoBuffer buffer = IoBuffer.allocate(text.length()); buffer.setAutoExpand(true); try { //Charset charset = Charset.forName(CHARSET); //buffer.putString(text, charset.newEncoder()); buffer.put(text.getBytes(StandardCharsets.UTF_8)); if (flashClient) { buffer.put((byte) '\0'); } buffer.flip(); ioSessionLock.lock(); try { ioSession.write(buffer); } finally { ioSessionLock.unlock(); } } catch (Exception e) { Log.debug("Error delivering raw text:\n" + text, e); errorDelivering = true; } // Attempt to close the connection if delivering text fails. if (errorDelivering) { close(); } }
byte connectionType = buf.get(); handshake.setHandshakeType(connectionType); log.trace("Incoming C0 connection type: {}", connectionType); buf.get(dst); int remaining = buf.remaining(); if (remaining > 0) { IoBuffer s1 = handshake.decodeClientRequest1(IoBuffer.wrap(dst)); if (s1 != null) { buf.get(dst); if (handshake.decodeClientRequest2(IoBuffer.wrap(dst))) { log.debug("Connected, removing handshake data and adding rtmp protocol filter"); if (buf.hasRemaining()) { log.trace("Receiving message: {}", buf); nextFilter.messageReceived(session, buf); byte[] encrypted = new byte[message.remaining()]; message.get(encrypted); message.clear(); message.free(); byte[] plain = cipher.update(encrypted); IoBuffer messageDecrypted = IoBuffer.wrap(plain); if (log.isDebugEnabled()) { log.debug("Receiving decrypted message: {}", messageDecrypted);
/** {@inheritDoc} */ @Override public void messageReceived(NextFilter next, IoSession session, Object message) throws Exception { // Create forwarding IO session IoSession forward = (IoSession) session.getAttribute(FORWARD_KEY); if (forward != null && forward.isConnected()) { if (message instanceof IoBuffer) { final IoBuffer buf = (IoBuffer) message; if (log.isDebugEnabled()) { log.debug("[{}] RAW >> {}", name, buf.getHexDump()); } IoBuffer copy = IoBuffer.allocate(buf.limit()); int limit = buf.limit(); copy.put(buf); copy.flip(); forward.write(copy); buf.flip(); buf.position(0); buf.limit(limit); } } next.messageReceived(session, message); }
public BaseRTMPTConnection(String type) { super(type); this.buffer = IoBuffer.allocate(0).setAutoExpand(true); }
/** {@inheritDoc} */ @Override public void messageReceived(NextFilter next, IoSession session, Object message) throws Exception { if (message instanceof IoBuffer) { IoBuffer out = (IoBuffer) message; if (headers != null) { IoBuffer header = IoBuffer.allocate(12); header.putLong(System.currentTimeMillis()); header.putInt(out.limit() - out.position()); header.flip(); headers.write(header.buf()); } if (raw != null) { raw.write(out.asReadOnlyBuffer().buf()); } } next.messageReceived(session, message); }
/** * Generates response for non-versioned connections, such as those before FP9. * * @param input * incoming RTMP bytes * @return outgoing handshake */ private IoBuffer generateUnversionedHandshake(byte[] input) { log.debug("Using old style (un-versioned) handshake"); IoBuffer output = IoBuffer.allocate((Constants.HANDSHAKE_SIZE * 2) + 1); // 3073 // non-encrypted output.put(RTMPConnection.RTMP_NON_ENCRYPTED); // set server uptime in seconds output.putInt((int) Red5.getUpTime() / 1000); //0x01 output.position(Constants.HANDSHAKE_SIZE + 1); output.put(input); output.flip(); // fill S1 with handshake data (nearly all 0's) output.mark(); output.position(1); output.get(s1); output.reset(); return output; }
final IoBuffer message = IoBuffer.allocate(length); ServletUtils.copy(req, message.asOutputStream()); message.flip(); RTMP rtmp = conn.getState(); int connectionState = rtmp.getState(); if (message.remaining() >= (Constants.HANDSHAKE_SIZE + 1)) { byte connectionType = message.get(); log.trace("Incoming C0 connection type: {}", connectionType); session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, handshake); message.get(dst); IoBuffer s1 = handshake.decodeClientRequest1(IoBuffer.wrap(dst)); if (s1 != null) { if (message.remaining() >= Constants.HANDSHAKE_SIZE) { message.get(dst); log.trace("Copied {}", Hex.encodeHexString(dst)); if (handshake.decodeClientRequest2(IoBuffer.wrap(dst))) { log.debug("Connected, removing handshake data and adding rtmp protocol filter"); message.clear(); message.free();
switch (connectionState) { case RTMP.STATE_CONNECT: if (message.indexOf("P".getBytes()[0]) == 0) { log.info("Non-native RTMPS connection requested for: {}", sessionId); byte connectionType = buf.get(); handshake.setHandshakeType(connectionType); log.trace("Incoming C0 connection type: {}", connectionType); buf.get(dst); int remaining = buf.remaining(); if (remaining > 0) { log.trace("Stored {} bytes for later decoding", remaining); IoBuffer s1 = handshake.decodeClientRequest1(IoBuffer.wrap(dst)); if (s1 != null) { buf.get(dst); if (handshake.decodeClientRequest2(IoBuffer.wrap(dst))) { log.debug("Connected, removing handshake data and adding rtmp protocol filter"); session.getFilterChain().addAfter("rtmpsFilter", "protocolFilter", new ProtocolCodecFilter(new RTMPMinaCodecFactory())); if (buf.hasRemaining()) { log.trace("Receiving message: {}", buf); nextFilter.messageReceived(session, buf);
boolean isClient = session.getRemoteAddress().equals(forward); if (log.isDebugEnabled()) { log.debug("Is downstream: " + isClient); session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(codecFactory)); session.getFilterChain().addFirst("proxy", new ProxyFilter(isClient ? "client" : "server")); String fileName = System.currentTimeMillis() + '_' + forward.getHostName() + '_' + forward.getPort() + '_' + (isClient ? "DOWNSTREAM" : "UPSTREAM"); File headersFile = loader.getResource(dumpTo + fileName + ".cap").getFile(); WritableByteChannel headers = headersFos.getChannel(); WritableByteChannel raw = rawFos.getChannel(); IoBuffer header = IoBuffer.allocate(1); header.put((byte) (isClient ? 0x00 : 0x01)); header.flip(); headers.write(header.buf()); session.getFilterChain().addFirst("dump", new NetworkDumpFilter(headers, raw)); } finally {
private Frame encodeCloseMessage ( final IoSession session, final CloseMessage message ) throws CharacterCodingException { final IoBuffer data = IoBuffer.allocate ( 0 ); data.setAutoExpand ( true ); data.putString ( message.getMessage (), getCharsetEncoder ( session ) ); data.put ( (byte)0x00 ); data.putInt ( message.getCode () ); data.flip (); return new Frame ( FrameType.CLOSE, data ); }
buf.mark(); int msgPos = savedBuf.position(); // carry on from previous buffer boolean seenNewline = false; while (!seenNewline && buf.hasRemaining() && msgPos < maxLineLength) { curByte = buf.get(); int end = buf.position(); buf.reset(); int start = buf.position(); if (savedBuf.position() > 0) { buf.get(tmp); savedBuf.put(tmp); int len = savedBuf.position() - 1; savedBuf.flip(); parsedBuf.buffer = savedBuf.getSlice(len); savedBuf.clear(); } else { parsedBuf.buffer = buf.getSlice(end - start - 1); buf.get(); // throw away newline int end = buf.position(); buf.reset(); int start = buf.position();
final byte[] bytes = msg.getBytes(); final IoBuffer buffer = allocator.allocate(bytes.length, true); buffer.put(bytes); buffer.flip(); }; if (line != null && line.getSession() != null && line.getSession().getAttribute("line") == line) { logger.debug("SEND[{}]: {} bytes: {}", new Object[]{ line.getSession().getId(), bytes.length, msg}); line.getSession().write(buffer).addListener(onWriteComplete);
@Override public void encode(IoSession session, Object msg, ProtocolEncoderOutput out) throws Exception { if (type.isInstance(msg)) { byte[] data = serializer.serialize(msg); IoBuffer buffer = IoBuffer.allocate(100); buffer.setAutoExpand(true); buffer.setAutoShrink(true); buffer.putInt(data.length); buffer.put(data); buffer.flip(); session.write(buffer); } }
private void storeRemainingInSession(IoBuffer buf, IoSession session) { IoBuffer remainingBuf = IoBuffer.allocate(buf.capacity()); remainingBuf.setAutoExpand(true); remainingBuf.order(buf.order()); remainingBuf.put(buf); session.setAttribute(BUFFER, remainingBuf); }
log.debug("decodeClientRequest1: {}", Hex.encodeHexString(in.array())); if (in.hasArray()) { c1 = in.array(); } else { c1 = new byte[Constants.HANDSHAKE_SIZE]; in.get(c1); IoBuffer s0s1s2 = IoBuffer.allocate(Constants.HANDSHAKE_SIZE * 2 + 1); // 3073 s0s1s2.put(handshakeType); // 1 s0s1s2.put(s1); // 1536 s0s1s2.put(c1); // 1536 s0s1s2.flip(); log.trace("S0+S1+S2 size: {}", s0s1s2.limit());
@Override public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest request) throws Exception { log.trace("filterWrite nextFilter: {} session: {} request: {}", nextFilter, session, request); Cipher cipher = (Cipher) session.getAttribute(RTMPConnection.RTMPE_CIPHER_OUT); if (cipher == null) { if (log.isTraceEnabled()) { } else { IoBuffer message = (IoBuffer) request.getMessage(); if (!message.hasRemaining()) { if (log.isTraceEnabled()) { log.trace("Ignoring empty message"); log.debug("Encrypting message: {}", message); byte[] plain = new byte[message.remaining()]; message.get(plain); message.clear(); message.free(); IoBuffer messageEncrypted = IoBuffer.wrap(encrypted); if (log.isDebugEnabled()) { log.debug("Writing encrypted message: {}", messageEncrypted);
IoBuffer buf = IoBuffer.allocate(1024); buf.setAutoExpand(true); Output output; if (resp.getEncoding() == Encoding.AMF0) { buf.putShort((short) 0); // encoded using AMF0 } else { buf.putShort((short) 3); // encoded using AMF3 buf.putShort((short) headers.size()); // write the header count if (resp.getEncoding() == Encoding.AMF0) { output = new Output(buf); buf.putShort((short) resp.getCalls().size()); // write the number of bodies for (RemotingCall call : resp.getCalls()) { log.debug("Call"); Output.putString(buf, ""); buf.putInt(-1); log.info("result: {}", call.getResult()); if (call.isAMF3) { buf.flip(); if (log.isDebugEnabled()) { log.debug(">>{}", buf.getHexDump());
public void write(byte[] b, int off, int len) throws IOException { while (len > buffer.remaining()) { int nlen = buffer.remaining(); buffer.put(b, off, nlen); len -= nlen; off += nlen; send(); buffer = IoBuffer.allocate((64 * 1024) - 42); } buffer.put(b, off, len); } private void send() throws IOException {