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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations