[2950] Support websocket binary frames (#2980)

* [2950] Support websocket binary frames 

Signed-off-by: Frank Li <b439988l@gmail.com>

Co-authored-by: Stefan Pingel <16143240+pinges@users.noreply.github.com>
pull/2996/head
Frank Li 3 years ago committed by GitHub
parent 7b19439281
commit c35c3bced5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 15
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java
  3. 25
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTest.java

@ -10,6 +10,7 @@
- Update JDK 11 to latest version in Besu Docker images. [#2925](https://github.com/hyperledger/besu/pull/2925)
- Add Sepolia proof-of-work testnet configurations [#2920](https://github.com/hyperledger/besu/pull/2920)
- Allow block period to be configured for IBFT2 and QBFT using transitions [\#2902](https://github.com/hyperledger/besu/pull/2902)
- Add support for binary messages (0x02) for websocket. [#2980](https://github.com/hyperledger/besu/pull/2980)
### Bug Fixes
- Do not change the sender balance, but set gas fee to zero, when simulating a transaction without enforcing balance checks. [#2454](https://github.com/hyperledger/besu/pull/2454)

@ -123,6 +123,21 @@ public class WebSocketService {
LOG.debug("Websocket Connected ({})", socketAddressAsString(socketAddress));
websocket.binaryMessageHandler(
buffer -> {
LOG.debug(
"Received Websocket request (binary frame) {} ({})",
buffer.toString(),
socketAddressAsString(socketAddress));
AuthenticationUtils.getUser(
authenticationService,
token,
user ->
websocketRequestHandler.handle(
authenticationService, connectionId, buffer.toString(), user));
});
websocket.textMessageHandler(
payload -> {
LOG.debug(

@ -41,6 +41,7 @@ import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.WebSocket;
import io.vertx.core.http.WebSocketBase;
import io.vertx.core.http.WebSocketFrame;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
@ -168,6 +169,30 @@ public class WebSocketServiceTest {
async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}
@Test
public void websocketServiceHandlesBinaryFrames(final TestContext context) {
final Async async = context.async();
httpClient.webSocket(
"/",
future -> {
if (future.succeeded()) {
WebSocket ws = future.result();
final JsonObject requestJson = new JsonObject().put("id", 1).put("method", "eth_x");
ws.handler(
// we don't really care what the response is
buffer -> {
async.complete();
});
ws.writeFinalBinaryFrame(Buffer.buffer(requestJson.toString()));
} else {
context.fail("websocket connection failed");
}
});
async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}
@Test
public void websocketServiceRemoveSubscriptionOnConnectionClose(final TestContext context) {
final Async async = context.async();

Loading…
Cancel
Save