Search in sources :

Example 1 with WebSocketMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory in project besu by hyperledger.

the class WebSocketServiceLoginTest method before.

@Before
public void before() throws URISyntaxException {
    vertx = Vertx.vertx();
    final String authTomlPath = Paths.get(ClassLoader.getSystemResource("JsonRpcHttpService/auth.toml").toURI()).toAbsolutePath().toString();
    websocketConfiguration = WebSocketConfiguration.createDefault();
    websocketConfiguration.setPort(0);
    websocketConfiguration.setAuthenticationEnabled(true);
    websocketConfiguration.setAuthenticationCredentialsFile(authTomlPath);
    websocketConfiguration.setHostsAllowlist(Collections.singletonList("*"));
    websocketConfiguration.setRpcApisNoAuth(new ArrayList<>(NO_AUTH_METHODS));
    peerDiscoveryMock = mock(P2PNetwork.class);
    blockchainQueries = mock(BlockchainQueries.class);
    synchronizer = mock(Synchronizer.class);
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID);
    final Map<String, JsonRpcMethod> websocketMethods = new WebSocketMethodsFactory(new SubscriptionManager(new NoOpMetricsSystem()), new HashMap<>()).methods();
    rpcMethods = spy(new JsonRpcMethodsFactory().methods(CLIENT_VERSION, CHAIN_ID, genesisConfigOptions, peerDiscoveryMock, blockchainQueries, synchronizer, MainnetProtocolSchedule.fromConfig(genesisConfigOptions), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.empty(), Optional.empty(), JSON_RPC_APIS, mock(PrivacyParameters.class), mock(JsonRpcConfiguration.class), mock(WebSocketConfiguration.class), mock(MetricsConfiguration.class), natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class)));
    websocketMethods.putAll(rpcMethods);
    webSocketMessageHandlerSpy = spy(new WebSocketMessageHandler(vertx, new JsonRpcExecutor(new AuthenticatedJsonRpcProcessor(new BaseJsonRpcProcessor(), DefaultAuthenticationService.create(vertx, websocketConfiguration).get(), websocketConfiguration.getRpcApisNoAuth()), websocketMethods), mock(EthScheduler.class), TimeoutOptions.defaultOptions().getTimeoutSeconds()));
    websocketService = new WebSocketService(vertx, websocketConfiguration, webSocketMessageHandlerSpy, new NoOpMetricsSystem());
    websocketService.start().join();
    jwtAuth = websocketService.authenticationService.get().getJwtAuthProvider();
    websocketConfiguration.setPort(websocketService.socketAddress().getPort());
    final HttpClientOptions httpClientOptions = new HttpClientOptions().setDefaultHost(websocketConfiguration.getHost()).setDefaultPort(websocketConfiguration.getPort());
    httpClient = vertx.createHttpClient(httpClientOptions);
}
Also used : HashMap(java.util.HashMap) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) WebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory) SubscriptionManager(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager) HttpClientOptions(io.vertx.core.http.HttpClientOptions) FilterManager(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager) BaseJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) JsonRpcExecutor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor) AuthenticatedJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor) HashSet(java.util.HashSet) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) JsonRpcConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) Before(org.junit.Before)

Example 2 with WebSocketMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory in project besu by hyperledger.

the class WebSocketServiceTest method before.

@Before
public void before() {
    vertx = Vertx.vertx();
    websocketConfiguration = WebSocketConfiguration.createDefault();
    websocketConfiguration.setPort(0);
    websocketConfiguration.setHostsAllowlist(Collections.singletonList("*"));
    websocketConfiguration.setMaxActiveConnections(maxConnections);
    websocketConfiguration.setMaxFrameSize(maxFrameSize);
    websocketMethods = new WebSocketMethodsFactory(new SubscriptionManager(new NoOpMetricsSystem()), new HashMap<>()).methods();
    webSocketMessageHandlerSpy = spy(new WebSocketMessageHandler(vertx, new JsonRpcExecutor(new BaseJsonRpcProcessor(), websocketMethods), mock(EthScheduler.class), TimeoutOptions.defaultOptions().getTimeoutSeconds()));
    websocketService = new WebSocketService(vertx, websocketConfiguration, webSocketMessageHandlerSpy, new NoOpMetricsSystem());
    websocketService.start().join();
    websocketConfiguration.setPort(websocketService.socketAddress().getPort());
    final HttpClientOptions httpClientOptions = new HttpClientOptions().setDefaultHost(websocketConfiguration.getHost()).setDefaultPort(websocketConfiguration.getPort());
    httpClient = vertx.createHttpClient(httpClientOptions);
}
Also used : BaseJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) WebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory) SubscriptionManager(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager) JsonRpcExecutor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Before(org.junit.Before)

Example 3 with WebSocketMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory in project besu by hyperledger.

the class WebSocketHostAllowlistTest method initServerAndClient.

@Before
public void initServerAndClient() {
    webSocketConfiguration.setPort(0);
    vertx = Vertx.vertx();
    final Map<String, JsonRpcMethod> websocketMethods = new WebSocketMethodsFactory(new SubscriptionManager(new NoOpMetricsSystem()), new HashMap<>()).methods();
    webSocketMessageHandlerSpy = spy(new WebSocketMessageHandler(vertx, new JsonRpcExecutor(new BaseJsonRpcProcessor(), websocketMethods), mock(EthScheduler.class), TimeoutOptions.defaultOptions().getTimeoutSeconds()));
    websocketService = new WebSocketService(vertx, webSocketConfiguration, webSocketMessageHandlerSpy, new NoOpMetricsSystem());
    websocketService.start().join();
    final InetSocketAddress inetSocketAddress = websocketService.socketAddress();
    websocketPort = inetSocketAddress.getPort();
    final HttpClientOptions httpClientOptions = new HttpClientOptions().setDefaultHost(webSocketConfiguration.getHost()).setDefaultPort(websocketPort);
    httpClient = vertx.createHttpClient(httpClientOptions);
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) WebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory) SubscriptionManager(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager) HttpClientOptions(io.vertx.core.http.HttpClientOptions) BaseJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) JsonRpcExecutor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor) Before(org.junit.Before)

Example 4 with WebSocketMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory in project besu by hyperledger.

the class RunnerBuilder method createWebsocketService.

private WebSocketService createWebsocketService(final Vertx vertx, final WebSocketConfiguration configuration, final SubscriptionManager subscriptionManager, final Map<String, JsonRpcMethod> jsonRpcMethods, final PrivacyParameters privacyParameters, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries, final Optional<AuthenticationService> authenticationService, final ObservableMetricsSystem metricsSystem) {
    final WebSocketMethodsFactory websocketMethodsFactory = new WebSocketMethodsFactory(subscriptionManager, jsonRpcMethods);
    if (privacyParameters.isEnabled()) {
        final PrivateWebSocketMethodsFactory privateWebSocketMethodsFactory = new PrivateWebSocketMethodsFactory(privacyParameters, subscriptionManager, protocolSchedule, blockchainQueries);
        privateWebSocketMethodsFactory.methods().forEach(websocketMethodsFactory::addMethods);
    }
    rpcEndpointServiceImpl.getPluginMethods(configuration.getRpcApis()).values().forEach(websocketMethodsFactory::addMethods);
    final JsonRpcProcessor jsonRpcProcessor;
    if (authenticationService.isPresent()) {
        jsonRpcProcessor = new AuthenticatedJsonRpcProcessor(new BaseJsonRpcProcessor(), authenticationService.get(), configuration.getRpcApisNoAuth());
    } else {
        jsonRpcProcessor = new BaseJsonRpcProcessor();
    }
    final JsonRpcExecutor jsonRpcExecutor = new JsonRpcExecutor(jsonRpcProcessor, websocketMethodsFactory.methods());
    final WebSocketMessageHandler websocketMessageHandler = new WebSocketMessageHandler(vertx, jsonRpcExecutor, besuController.getProtocolManager().ethContext().getScheduler(), webSocketConfiguration.getTimeoutSec());
    return new WebSocketService(vertx, configuration, websocketMessageHandler, authenticationService, metricsSystem);
}
Also used : BaseJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor) WebSocketMessageHandler(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketMessageHandler) JsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcProcessor) BaseJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor) AuthenticatedJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor) WebSocketService(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketService) WebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory) PrivateWebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.PrivateWebSocketMethodsFactory) PrivateWebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.PrivateWebSocketMethodsFactory) AuthenticatedJsonRpcProcessor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor) JsonRpcExecutor(org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor)

Example 5 with WebSocketMethodsFactory

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory in project besu by hyperledger.

the class RunnerBuilder method createWebsocketService.

private WebSocketService createWebsocketService(final Vertx vertx, final WebSocketConfiguration configuration, final SubscriptionManager subscriptionManager, final Map<String, JsonRpcMethod> jsonRpcMethods, final PrivacyParameters privacyParameters, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries, final Optional<AuthenticationService> authenticationService) {
    final WebSocketMethodsFactory websocketMethodsFactory = new WebSocketMethodsFactory(subscriptionManager, jsonRpcMethods);
    if (privacyParameters.isEnabled()) {
        final PrivateWebSocketMethodsFactory privateWebSocketMethodsFactory = new PrivateWebSocketMethodsFactory(privacyParameters, subscriptionManager, protocolSchedule, blockchainQueries);
        privateWebSocketMethodsFactory.methods().forEach(websocketMethodsFactory::addMethods);
    }
    rpcEndpointServiceImpl.getPluginMethods(configuration.getRpcApis()).values().forEach(websocketMethodsFactory::addMethods);
    final WebSocketRequestHandler websocketRequestHandler = new WebSocketRequestHandler(vertx, websocketMethodsFactory.methods(), besuController.getProtocolManager().ethContext().getScheduler(), webSocketConfiguration.getTimeoutSec());
    return new WebSocketService(vertx, configuration, websocketRequestHandler, authenticationService);
}
Also used : WebSocketRequestHandler(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketRequestHandler) WebSocketService(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketService) WebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory) PrivateWebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.PrivateWebSocketMethodsFactory) PrivateWebSocketMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.PrivateWebSocketMethodsFactory)

Aggregations

WebSocketMethodsFactory (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory)5 BaseJsonRpcProcessor (org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor)4 JsonRpcExecutor (org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor)4 HttpClientOptions (io.vertx.core.http.HttpClientOptions)3 SubscriptionManager (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager)3 EthScheduler (org.hyperledger.besu.ethereum.eth.manager.EthScheduler)3 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)3 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 AuthenticatedJsonRpcProcessor (org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor)2 JsonRpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod)2 WebSocketService (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketService)2 PrivateWebSocketMethodsFactory (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.PrivateWebSocketMethodsFactory)2 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 StubGenesisConfigOptions (org.hyperledger.besu.config.StubGenesisConfigOptions)1 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 JsonRpcConfiguration (org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration)1 JsonRpcProcessor (org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcProcessor)1 FilterManager (org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager)1