class GridConnectionBytesVerifyFilter extends GridNioFilterAdapter {
    /** */
    private static final int MAGIC_META_KEY = GridNioSessionMetaKey.nextUniqueKey();

    /** */
    private static final int MAGIC_BUF_KEY = GridNioSessionMetaKey.nextUniqueKey();

    /** */
    private IgniteLogger log;

    /**
     * Creates a filter instance.
     *
     * @param log Logger.
     */
    public GridConnectionBytesVerifyFilter(IgniteLogger log) {
        super("GridConnectionBytesVerifyFilter");

        this.log = log;
    }

    /** {@inheritDoc} */
    @Override public void onSessionOpened(GridNioSession ses) throws IgniteCheckedException {
        proceedSessionOpened(ses);
    }

    /** {@inheritDoc} */
    @Override public void onSessionClosed(GridNioSession ses) throws IgniteCheckedException {
        proceedSessionClosed(ses);
    }

    /** {@inheritDoc} */
    @Override public void onExceptionCaught(
        GridNioSession ses,
        IgniteCheckedException ex
    ) throws IgniteCheckedException {
        proceedExceptionCaught(ses, ex);
    }

    /** {@inheritDoc} */
    @Override public GridNioFuture<?> onSessionWrite(
        GridNioSession ses,
        Object msg,
        boolean fut,
        IgniteInClosure<IgniteException> ackC
    ) throws IgniteCheckedException {
        return proceedSessionWrite(ses, msg, fut, ackC);
    }

    /** {@inheritDoc} */
    @Override public void onMessageReceived(GridNioSession ses, Object msg) throws IgniteCheckedException {<FILL_FUNCTION_BODY>}

    /** {@inheritDoc} */
    @Override public GridNioFuture<Boolean> onSessionClose(GridNioSession ses) throws IgniteCheckedException {
        return proceedSessionClose(ses);
    }

    /** {@inheritDoc} */
    @Override public void onSessionIdleTimeout(GridNioSession ses) throws IgniteCheckedException {
        proceedSessionIdleTimeout(ses);
    }

    /** {@inheritDoc} */
    @Override public void onSessionWriteTimeout(GridNioSession ses) throws IgniteCheckedException {
        proceedSessionWriteTimeout(ses);
    }
}

        // Verify only incoming connections.
        if (!ses.accepted()) {
            proceedMessageReceived(ses, msg);

            return;
        }

        if (!(msg instanceof ByteBuffer))
            throw new GridNioException("Failed to decode incoming message (message should be a byte buffer, is " +
                "filter properly placed?): " + msg.getClass());

        ByteBuffer buf = (ByteBuffer)msg;

        Integer magic = ses.meta(MAGIC_META_KEY);

        if (magic == null || magic < U.IGNITE_HEADER.length) {
            byte[] magicBuf = ses.meta(MAGIC_BUF_KEY);

            if (magicBuf == null)
                magicBuf = new byte[U.IGNITE_HEADER.length];

            int magicRead = magic == null ? 0 : magic;

            int cnt = buf.remaining();

            buf.get(magicBuf, magicRead, Math.min(U.IGNITE_HEADER.length - magicRead, cnt));

            if (cnt + magicRead < U.IGNITE_HEADER.length) {
                // Magic bytes are not fully read.
                ses.addMeta(MAGIC_META_KEY, cnt + magicRead);
                ses.addMeta(MAGIC_BUF_KEY, magicBuf);
            }
            else if (U.bytesEqual(magicBuf, 0, U.IGNITE_HEADER, 0, U.IGNITE_HEADER.length)) {
                // Magic bytes read and equal to IGNITE_HEADER.
                ses.removeMeta(MAGIC_BUF_KEY);
                ses.addMeta(MAGIC_META_KEY, U.IGNITE_HEADER.length);

                proceedMessageReceived(ses, buf);
            }
            else {
                ses.close();

                LT.warn(log, "Unknown connection detected (is some other software connecting to this " +
                    "Ignite port?) [rmtAddr=" + ses.remoteAddress() + ", locAddr=" + ses.localAddress() + ']');
            }
        }
        else
            proceedMessageReceived(ses, buf);
    
<methods>public org.apache.ignite.internal.util.nio.GridNioFilter nextFilter() ,public void nextFilter(org.apache.ignite.internal.util.nio.GridNioFilter) ,public GridNioFuture<?> onPauseReads(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public GridNioFuture<?> onResumeReads(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public org.apache.ignite.internal.util.nio.GridNioFilter previousFilter() ,public void previousFilter(org.apache.ignite.internal.util.nio.GridNioFilter) ,public void proceedExceptionCaught(org.apache.ignite.internal.util.nio.GridNioSession, org.apache.ignite.IgniteCheckedException) throws org.apache.ignite.IgniteCheckedException,public void proceedMessageReceived(org.apache.ignite.internal.util.nio.GridNioSession, java.lang.Object) throws org.apache.ignite.IgniteCheckedException,public GridNioFuture<?> proceedPauseReads(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public GridNioFuture<?> proceedResumeReads(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public GridNioFuture<java.lang.Boolean> proceedSessionClose(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public void proceedSessionClosed(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public void proceedSessionIdleTimeout(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public void proceedSessionOpened(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public GridNioFuture<?> proceedSessionWrite(org.apache.ignite.internal.util.nio.GridNioSession, java.lang.Object, boolean, IgniteInClosure<org.apache.ignite.IgniteException>) throws org.apache.ignite.IgniteCheckedException,public void proceedSessionWriteTimeout(org.apache.ignite.internal.util.nio.GridNioSession) throws org.apache.ignite.IgniteCheckedException,public void start() ,public void stop() ,public java.lang.String toString() <variables>private java.lang.String name,protected org.apache.ignite.internal.util.nio.GridNioFilter nextFilter,protected org.apache.ignite.internal.util.nio.GridNioFilter prevFilter