Refine search
/** {@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); }
/** {@inheritDoc} */ @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { log.debug("Filter chain: {}", session.getFilterChain()); String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isDebugEnabled()) { log.warn("Exception caught on session: {} id: {}", session.getId(), sessionId, cause); } if (cause instanceof IOException) { // Mina states that the connection will be automatically closed when an IOException is caught log.debug("IOException caught on {}", sessionId); } else { log.debug("Non-IOException caught on {}", sessionId); if (session.containsAttribute("FORCED_CLOSE")) { log.info("Close already forced on this session: {}", session.getId()); } else { // set flag session.setAttribute("FORCED_CLOSE", Boolean.TRUE); //session.suspendRead(); cleanSession(session, true); } } }
/** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override public void sessionClosed(NextFilter next, IoSession session) throws Exception { IoSession forward = (IoSession) session.getAttribute(FORWARD_KEY); if (forward != null && forward.isConnected() && !forward.isClosing()) { if (log.isDebugEnabled()) { log.debug("[{}] Closing: {}", name, forward); } forward.close(true); } next.sessionClosed(session); }
private void removeSession( IoSession session ) { // remove the session from the list of polled sessions polledSessions.remove( session ); // add the bytes processed between last polling and session closing // prevent non seen byte with non-connected protocols like HTTP and datagrams IoSessionStat sessStat = ( IoSessionStat ) session.removeAttribute( KEY ); if (sessStat != null) { totalMsgWritten.addAndGet(session.getWrittenMessages() - sessStat.lastMessageWrite); totalMsgRead.addAndGet(session.getReadMessages() - sessStat.lastMessageRead); totalBytesWritten.addAndGet(session.getWrittenBytes() - sessStat.lastByteWrite); totalBytesRead.addAndGet(session.getReadBytes() - sessStat.lastByteRead); } }
/** * Updates the system counter of read bytes. This information is used by the incoming * bytes statistic. * * @param session the session that read more bytes from the socket. */ private void updateReadBytesCounter(IoSession session) { long currentBytes = session.getReadBytes(); Long prevBytes = (Long) session.getAttribute("_read_bytes"); long delta; if (prevBytes == null) { delta = currentBytes; } else { delta = currentBytes - prevBytes; } session.setAttribute("_read_bytes", currentBytes); ServerTrafficCounter.incrementIncomingCounter(delta); }
log.trace("messageReceived nextFilter: {} session: {} message: {}", nextFilter, session, obj); String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (sessionId != null) { if (log.isTraceEnabled()) { handshake = (InboundHandshake) session.getAttribute(RTMPConnection.RTMP_HANDSHAKE); session.write(s1); } else { log.warn("Client was rejected due to invalid handshake"); handshake = (InboundHandshake) session.getAttribute(RTMPConnection.RTMP_HANDSHAKE); log.debug("Using encrypted communications, adding ciphers to the session"); rtmp.setEncrypted(true); session.setAttribute(RTMPConnection.RTMPE_CIPHER_IN, handshake.getCipherIn()); session.setAttribute(RTMPConnection.RTMPE_CIPHER_OUT, handshake.getCipherOut()); session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE); session.getFilterChain().addAfter("rtmpeFilter", "protocolFilter", new ProtocolCodecFilter(new RTMPMinaCodecFactory())); nextFilter.messageReceived(session, message); } else { Cipher cipher = (Cipher) session.getAttribute(RTMPConnection.RTMPE_CIPHER_IN); if (cipher != null) { if (log.isDebugEnabled()) {
final IoBuffer message = IoBuffer.allocate(length); ServletUtils.copy(req, message.asOutputStream()); message.flip(); RTMP rtmp = conn.getState(); int connectionState = rtmp.getState(); session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, handshake); if (message.remaining() >= Constants.HANDSHAKE_SIZE) { handshake = (InboundHandshake) session.getAttribute(RTMPConnection.RTMP_HANDSHAKE); session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE); } else { log.warn("Client was rejected due to invalid handshake");
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(); } }
@Override public void messageReceived(NextFilter nextFilter, IoSession session, Object obj) throws Exception { log.trace("messageReceived nextFilter: {} session: {} message: {}", nextFilter, session, obj); if (obj instanceof SslFilterMessage || !session.isSecured()) { log.trace("Either ssl message or un-secured session: {}", session.isSecured()); nextFilter.messageReceived(session, obj); } else { String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (sessionId != null) { log.info("RTMPS Session id: {}", sessionId); handshake = (InboundHandshake) session.getAttribute(RTMPConnection.RTMP_HANDSHAKE); buf.get(dst); if (s1 != null) { session.write(s1); } else { log.warn("Client was rejected due to invalid handshake"); case RTMP.STATE_HANDSHAKE: handshake = (InboundHandshake) session.getAttribute(RTMPConnection.RTMP_HANDSHAKE); session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE); session.getFilterChain().addAfter("rtmpsFilter", "protocolFilter", new ProtocolCodecFilter(new RTMPMinaCodecFactory()));
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 { if (headersFos != null) { client.setAttribute(ProxyFilter.FORWARD_KEY, session); session.setAttribute(ProxyFilter.FORWARD_KEY, client);
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); session.setAttribute("line", line); logger.debug("SEND[{}]: {} bytes: {}", new Object[]{ session.getId(), bytes.length, msg}); session.write(buffer).addListener(onWriteComplete);
@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();
log.debug("Session created RTMP"); if (!session.getFilterChain().contains("rtmpeFilter")) { session.getFilterChain().addFirst("rtmpeFilter", new RTMPEIoFilter()); String sessionId = null; if (!session.containsAttribute(RTMPConnection.RTMP_SESSION_ID)) { session.setAttribute(RTMPConnection.RTMP_SESSION_ID, sessionId); session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, handshake); log.debug("Created: {}", sessionId); } else { sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); log.warn("Session previously created: {} id: {}", session.getId(), sessionId); RTMPConnManager connManager = (RTMPConnManager) RTMPConnManager.getInstance(); if ((RTMPMinaConnection) connManager.getConnectionBySessionId(sessionId) == null) {
@Override public ChannelHandler writeAndFlush(Object msg) { WriteFuture writeFuture = session.write(msg); return new MinaChannelHandler(writeFuture); }
/** {@inheritDoc} */ @Override public void sessionIdle(IoSession session, IdleStatus status) throws Exception { if (log.isTraceEnabled()) { log.trace("Idle (session: {}) local: {} remote: {}\nread: {} write: {}", session.getId(), session.getLocalAddress(), session.getRemoteAddress(), session.getReadBytes(), session.getWrittenBytes()); } String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (sessionId != null) { RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId); if (conn != null) { // close the idle socket conn.onInactive(); } } }
/** {@inheritDoc} */ @Override public void sessionOpened(IoSession session) throws Exception { String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); log.debug("Session opened: {} id: {}", session.getId(), sessionId); RTMPConnManager connManager = (RTMPConnManager) RTMPConnManager.getInstance(); session.setAttribute(RTMPConnection.RTMP_CONN_MANAGER, new WeakReference<IConnectionManager<RTMPConnection>>(connManager)); RTMPMinaConnection conn = (RTMPMinaConnection) connManager.getConnectionBySessionId(sessionId); handler.connectionOpened(conn); }
if (session.isClosing()) { log.debug("Session already being closed"); } else { final String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isDebugEnabled()) { log.debug("Forcing close on session: {} id: {}", session.getId(), sessionId); log.debug("Session closing: {}", session.isClosing()); final WriteRequestQueue writeQueue = session.getWriteRequestQueue(); if (writeQueue != null && !writeQueue.isEmpty(session)) { log.debug("Clearing write queue"); final CloseFuture future = immediately ? session.closeNow() : session.closeOnFlush(); IoFutureListener<CloseFuture> listener = new IoFutureListener<CloseFuture>() { @SuppressWarnings({ "unchecked", "rawtypes" })
private void readHandle(DatagramChannel handle) throws Exception { IoBuffer readBuf = IoBuffer.allocate(getSessionConfig().getReadBufferSize()); SocketAddress remoteAddress = receive(handle, readBuf); if (remoteAddress != null) { IoSession session = newSessionWithoutLock(remoteAddress, localAddress(handle)); readBuf.flip(); if (!session.isReadSuspended()) { session.getFilterChain().fireMessageReceived(readBuf); } } }
/** {@inheritDoc} */ @Override public void sessionClosed(IoSession session) throws Exception { String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); log.debug("Session closed: {} id: {}", session.getId(), sessionId); if (log.isTraceEnabled()) { log.trace("Session attributes: {}", session.getAttributeKeys()); } if (sessionId != null) { RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId); if (conn != null) { // fire-off closed event handler.connectionClosed(conn); // clear any session attributes we may have previously set // TODO: verify this cleanup code is necessary. The session is over and will be garbage collected surely? if (session.containsAttribute(RTMPConnection.RTMP_HANDSHAKE)) { session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE); } if (session.containsAttribute(RTMPConnection.RTMPE_CIPHER_IN)) { session.removeAttribute(RTMPConnection.RTMPE_CIPHER_IN); session.removeAttribute(RTMPConnection.RTMPE_CIPHER_OUT); } } else { log.warn("Connection was not found for {}", sessionId); } cleanSession(session, false); } else { log.debug("Connections session id was null in session, may already be closed"); } }