Java Code Examples for io.netty.buffer.ByteBufUtil#equals()
The following examples show how to use
io.netty.buffer.ByteBufUtil#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecordingSessionFactory.java From arcusplatform with Apache License 2.0 | 6 votes |
private static void verifySignature(SecretKeySpec secret, UUID cameraId, UUID accountId, UUID placeId, UUID personId, UUID recordingId, ByteBuf sig) throws Exception { StringBuilder message = new StringBuilder(180); message.append(cameraId); message.append(accountId); message.append(placeId); message.append(personId); message.append(recordingId); Mac hmac = Mac.getInstance("HmacSHA256"); hmac.init(secret); byte[] result = hmac.doFinal(message.toString().getBytes(StandardCharsets.UTF_8)); ByteBuf computed = Unpooled.wrappedBuffer(result, 0, 16); if (!ByteBufUtil.equals(sig,computed)) { RECORDING_SESSION_CREATE_VALIDATION.inc(); throw new Exception("signature validation failed"); } }
Example 2
Source File: CleartextHttp2ServerUpgradeHandler.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int prefaceLength = CONNECTION_PREFACE.readableBytes(); int bytesRead = Math.min(in.readableBytes(), prefaceLength); if (!ByteBufUtil.equals(CONNECTION_PREFACE, CONNECTION_PREFACE.readerIndex(), in, in.readerIndex(), bytesRead)) { ctx.pipeline().remove(this); } else if (bytesRead == prefaceLength) { // Full h2 preface match, removed source codec, using http2 codec to handle // following network traffic ctx.pipeline() .remove(httpServerCodec) .remove(httpServerUpgradeHandler); ctx.pipeline().addAfter(ctx.name(), null, http2ServerHandler); ctx.pipeline().remove(this); ctx.fireUserEventTriggered(PriorKnowledgeUpgradeEvent.INSTANCE); } }
Example 3
Source File: Http2ServerUpgradeHandler.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int prefaceLength = CONNECTION_PREFACE.readableBytes(); int bytesRead = Math.min(in.readableBytes(), prefaceLength); if (!ByteBufUtil.equals(CONNECTION_PREFACE, CONNECTION_PREFACE.readerIndex(), in, in.readerIndex(), bytesRead)) { ctx.pipeline().remove(this); } else if (bytesRead == prefaceLength) { // Full h2 preface match, removed source codec, using http2 codec to handle // following network traffic ctx.pipeline() .remove(httpServerCodec) .remove(httpServerUpgradeHandler); // 用业务线程池 ctx.pipeline().addAfter(bizGroup, ctx.name(), null, http2ServerHandler); ctx.pipeline().remove(this); ctx.fireUserEventTriggered(Http2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent.INSTANCE); } }
Example 4
Source File: CleartextHttp2ServerUpgradeHandler.java From glowroot with Apache License 2.0 | 6 votes |
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int prefaceLength = CONNECTION_PREFACE.readableBytes(); int bytesRead = Math.min(in.readableBytes(), prefaceLength); if (!ByteBufUtil.equals(CONNECTION_PREFACE, CONNECTION_PREFACE.readerIndex(), in, in.readerIndex(), bytesRead)) { ctx.pipeline().remove(this); } else if (bytesRead == prefaceLength) { // Full h2 preface match, removed source codec, using http2 codec to handle // following network traffic ctx.pipeline() .remove(httpServerCodec) .remove(httpServerUpgradeHandler); ctx.pipeline().addAfter(ctx.name(), null, http2ServerHandler); ctx.pipeline().remove(this); ctx.fireUserEventTriggered(PriorKnowledgeUpgradeEvent.INSTANCE); } }
Example 5
Source File: Http2ConnectionHandler.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Decodes the client connection preface string from the input buffer. * * @return {@code true} if processing of the client preface string is complete. Since client preface strings can * only be received by servers, returns true immediately for client endpoints. */ private boolean readClientPrefaceString(ByteBuf in) throws Http2Exception { if (clientPrefaceString == null) { return true; } int prefaceRemaining = clientPrefaceString.readableBytes(); int bytesRead = min(in.readableBytes(), prefaceRemaining); // If the input so far doesn't match the preface, break the connection. if (bytesRead == 0 || !ByteBufUtil.equals(in, in.readerIndex(), clientPrefaceString, clientPrefaceString.readerIndex(), bytesRead)) { int maxSearch = 1024; // picked because 512 is too little, and 2048 too much int http1Index = ByteBufUtil.indexOf(HTTP_1_X_BUF, in.slice(in.readerIndex(), min(in.readableBytes(), maxSearch))); if (http1Index != -1) { String chunk = in.toString(in.readerIndex(), http1Index - in.readerIndex(), CharsetUtil.US_ASCII); throw connectionError(PROTOCOL_ERROR, "Unexpected HTTP/1.x request: %s", chunk); } String receivedBytes = hexDump(in, in.readerIndex(), min(in.readableBytes(), clientPrefaceString.readableBytes())); throw connectionError(PROTOCOL_ERROR, "HTTP/2 client preface string missing or corrupt. " + "Hex dump for received bytes: %s", receivedBytes); } in.skipBytes(bytesRead); clientPrefaceString.skipBytes(bytesRead); if (!clientPrefaceString.isReadable()) { // Entire preface has been read. clientPrefaceString.release(); clientPrefaceString = null; return true; } return false; }
Example 6
Source File: Http2GoAwayHandler.java From armeria with Apache License 2.0 | 5 votes |
@VisibleForTesting static boolean isExpected(long errorCode, ByteBuf debugData) { // 'Error flushing' happens when a client closes the connection early. return errorCode == CODE_INTERNAL_ERROR && ByteBufUtil.equals(debugData, debugData.readerIndex(), ERROR_FLUSHING, 0, ERROR_FLUSHING_LEN); }
Example 7
Source File: UnconnectedDataItemResponse.java From ethernet-ip with Apache License 2.0 | 5 votes |
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; UnconnectedDataItemResponse that = (UnconnectedDataItemResponse) o; return ByteBufUtil.equals(data, that.data); }
Example 8
Source File: ConnectedDataItemResponse.java From ethernet-ip with Apache License 2.0 | 5 votes |
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ConnectedDataItemResponse that = (ConnectedDataItemResponse) o; return ByteBufUtil.equals(data, that.data); }
Example 9
Source File: MonitorServerHandler.java From tajo with Apache License 2.0 | 5 votes |
private boolean isPing(Object msg) { if (msg instanceof ByteBuf) { return ByteBufUtil.equals(ping.duplicate(), ((ByteBuf) msg).duplicate()); } return false; }
Example 10
Source File: TextFieldSerializerDeserializer.java From tajo with Apache License 2.0 | 4 votes |
private static boolean isNullText(ByteBuf val, ByteBuf nullBytes) { return val.readableBytes() > 0 && ByteBufUtil.equals(nullBytes, val); }
Example 11
Source File: MonitorClientHandler.java From tajo with Apache License 2.0 | 4 votes |
private boolean isPing(Object msg) { if(msg instanceof ByteBuf){ return ByteBufUtil.equals(ping.duplicate(), ((ByteBuf)msg).duplicate()); } return false; }