List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:org.restcomm.media.rtp.netty.RtpDemultiplexer.java
License:Open Source License
private void handleStunPacket(ChannelHandlerContext ctx, ByteBuf buffer) { // Retrieve data from network final byte[] data = buffer.array(); final int length = buffer.readableBytes(); final int offset = buffer.arrayOffset(); // Wrap data into an STUN packet try {/*from w w w. ja v a 2s .c o m*/ StunMessage stunPacket = StunMessage.decode(data, (char) offset, (char) length); ctx.fireChannelRead(stunPacket); } catch (StunException e) { // Drop packet as we could not decode it ReferenceCountUtil.release(buffer); log.warn("Channel " + ctx.channel().localAddress() + "could not decode incoming STUN packet", e); } }
From source file:org.restcomm.media.rtp.netty.RtpDemultiplexer.java
License:Open Source License
private void handleDtlsPacket(ChannelHandlerContext ctx, ByteBuf buffer) { // Retrieve data from network final int length = buffer.readableBytes(); final int offset = buffer.arrayOffset(); // Wrap data into a DTLS packet byte[] data = new byte[length - offset]; buffer.getBytes(offset, data);/* w ww . j a v a 2 s . c o m*/ DtlsPacket dtlsPacket = new DtlsPacket(data); ctx.fireChannelRead(dtlsPacket); }
From source file:org.restcomm.media.rtp.netty.RtpDemultiplexer.java
License:Open Source License
private void handleRtpPacket(ChannelHandlerContext ctx, ByteBuf buffer) { // Retrieve data from network final int offset = buffer.arrayOffset(); /*/*from ww w .j a v a 2 s. com*/ * When RTP and RTCP packets are multiplexed onto a single port, the RTCP packet type field occupies the same position * in the packet as the combination of the RTP marker (M) bit and the RTP payload type (PT). This field can be used to * distinguish RTP and RTCP packets when two restrictions are observed: * * 1) the RTP payload type values used are distinct from the RTCP packet types used. * * 2) for each RTP payload type (PT), PT+128 is distinct from the RTCP packet types used. The first constraint precludes * a direct conflict between RTP payload type and RTCP packet type; the second constraint precludes a conflict between * an RTP data packet with the marker bit set and an RTCP packet. */ int type = buffer.getByte(offset + 1) & 0xff & 0x7f; int rtcpType = type + 128; // RTP payload types 72-76 conflict with the RTCP SR, RR, SDES, BYE and APP packets defined in the RTP specification switch (rtcpType) { case RtcpHeader.RTCP_SR: case RtcpHeader.RTCP_RR: case RtcpHeader.RTCP_SDES: case RtcpHeader.RTCP_BYE: case RtcpHeader.RTCP_APP: RtcpPacket rtcpPacket = buildRtcpPacket(buffer); ctx.fireChannelRead(rtcpPacket); default: RtpPacket rtpPacket = buildRtpPacket(buffer); ctx.fireChannelRead(rtpPacket); break; } }
From source file:org.rzo.netty.ahessian.auth.AuthTokenList.java
License:Apache License
public int authenticate(ChannelHandlerContext ctx, ByteBuf e) { ByteBuf b = e;/*from ww w . j a v a 2s .co m*/ int toCopy = Math.min(_receivedBytes.length - _receivedLength, b.readableBytes()); byte[] bytes = new byte[toCopy]; b.readBytes(bytes); System.arraycopy(bytes, 0, _receivedBytes, _receivedLength, bytes.length); _receivedLength += toCopy; if (_receivedLength == _receivedBytes.length) { _currentToken = _tokens.get(new ByteArrayWrapper(_receivedBytes)); if (_currentToken != null && (_uniqueLogon || _currentToken.isLoggedOn())) { logger.info("authenticated"); ((SimpleAuthToken) _currentToken).setLoggedOn(true); if (b.readableBytes() != 0) ctx.fireChannelRead(e); return PASSED; } else { _currentToken = null; return FAILED; } } else return NOT_COMPLETE; }
From source file:org.rzo.netty.ahessian.auth.ServerAuthFilter.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object e) throws Exception { if (!_authenticated) { int result = _token.authenticate(ctx, (ByteBuf) e); if (result == AuthToken.FAILED) { logger.warn("authentication failed -> close connection"); ctx.channel().close();/*from w w w. j av a2 s .c o m*/ } else if (result == AuthToken.PASSED) { _authenticated = true; } } else ctx.fireChannelRead(e); }
From source file:org.rzo.netty.ahessian.auth.SimpleAuthToken.java
License:Apache License
public int authenticate(ChannelHandlerContext ctx, ByteBuf e) { ByteBuf b = e;// w w w. j a va2 s .co m int toCopy = Math.min(_receivedBytes.length - _receivedLength, b.readableBytes()); byte[] bytes = new byte[toCopy]; b.readBytes(bytes); System.arraycopy(bytes, 0, _receivedBytes, _receivedLength, bytes.length); _receivedLength += toCopy; if (_receivedLength == _password.length) { if (Arrays.equals(_receivedBytes, _password)) { logger.info("authenticated"); if (b.readableBytes() != 0) ctx.fireChannelRead(e); return PASSED; } else return FAILED; } else return NOT_COMPLETE; }
From source file:org.rzo.netty.ahessian.crypto.ClientCryptoFilterInbound.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object e) throws Exception { // have we sent our secret key ? if (_data._decodeCipher != null) { // decode and send upstream ByteBuf m = Util.code(_data._decodeCipher, (ByteBuf) e, true); ctx.fireChannelRead(e); }/*from w ww .jav a 2s . com*/ // we are still in the crypto protocol else { ByteBuf b = (ByteBuf) e; // is this our first message ? if (_data._encodedPublicKey == null) { int size = b.readInt(); _data._encodedPublicKey = new byte[size]; } // readin the server's public key // it may come in multiple chunks int available = b.readableBytes(); int toRead = Math.min(_data._encodedPublicKey.length - _data._bytesRead, available); b.readBytes(_data._encodedPublicKey, _data._bytesRead, toRead); _data._bytesRead += toRead; // we have completed reception of the public key ? if (_data._bytesRead == _data._encodedPublicKey.length) { // generate our secret key and send it to the server sendSecretKey(ctx); } } }
From source file:org.rzo.netty.ahessian.crypto.ServerCryptoFilterInbound.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object e) throws Exception { // have we sent our secret key ? if (_decodeCipher != null) { ByteBuf m = Util.code(_decodeCipher, (ByteBuf) e, true); ctx.fireChannelRead(m); } else {/*from www . ja v a2s. c o m*/ ByteBuf b = (ByteBuf) e; // is this our first message ? if (_cryptedIvKeyMessage == null) { int size = b.readInt(); // consistency check, so we do not get an out of memory // exception if (size > 1024) { ctx.channel().close(); return; } _cryptedIvKeyMessage = new byte[size]; } // readin the client's secret key and iv int available = b.readableBytes(); int toRead = Math.min(_cryptedIvKeyMessage.length - _bytesRead, available); b.readBytes(_cryptedIvKeyMessage, _bytesRead, toRead); _bytesRead += toRead; // we have completed receiption ? if (_bytesRead == _cryptedIvKeyMessage.length) { boolean ok = false; try { createCiphers(); ok = true; } catch (Exception ex) { ex.printStackTrace(); ctx.channel().close(); } // inform pipline that we are ready for encrypted communication if (ok) ctx.fireChannelActive(); } } }
From source file:org.rzo.netty.ahessian.heartbeat.ServerHeartbeatHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { _handler.ping(); ctx.fireChannelRead(msg); }
From source file:org.rzo.netty.ahessian.io.InputStreamHandler.java
License:Apache License
/** * Instantiates a new input stream decoder. * /*from ww w .j a v a 2 s .c om*/ * @param executor * the thread pool */ /* * (non-Javadoc) * * @see * org.jboss.netty.channel.SimpleChannelUpstreamHandler#messageReceived( * org.jboss.netty.channel.ChannelHandlerContext, * org.jboss.netty.channel.MessageEvent) */ @Override public void channelRead(final ChannelHandlerContext ctx, final Object e) throws Exception { // System.out.println(System.currentTimeMillis()+" InputStreamHanlder.messageReceived +"); _in.write(((ByteBuf) e)); ctx.fireChannelReadComplete(); ctx.fireChannelRead(_in); // System.out.println(System.currentTimeMillis()+" InputStreamHanlder.messageReceived -"); }