@Override protected NettyServerBuilder newServerBuilder() { final String address = getAddress(); final int port = getPort(); if (GrpcServerProperties.ANY_IP_ADDRESS.equals(address)) { return NettyServerBuilder.forPort(port); } else { return NettyServerBuilder.forAddress(new InetSocketAddress(InetAddresses.forString(address), port)); } }
/** {@inheritDoc} */ @Override public AltsServerBuilder addService(BindableService bindableService) { delegate.addService(bindableService); return this; }
/** {@inheritDoc} */ @Override public AltsServerBuilder executor(Executor executor) { delegate.executor(executor); return this; }
serverBuilder = NettyServerBuilder.forPort(serverConf.getPort()); } else { LOGGER.info("server build on address {}:{}", serverConf.getIp(), serverConf.getPort()); new InetSocketAddress( InetAddresses.forString(serverConf.getIp()), serverConf.getPort()); serverBuilder = NettyServerBuilder.forAddress(addr); serverBuilder.addService(dataTransferPipedServer) .addService(routeServer) .maxConcurrentCallsPerConnection(20000) .maxInboundMessageSize(256 << 20) .flowControlWindow(32 << 20) .keepAliveTime(6, TimeUnit.MINUTES) .keepAliveTimeout(24, TimeUnit.HOURS) .maxConnectionIdle(1, TimeUnit.HOURS) .permitKeepAliveTime(1, TimeUnit.SECONDS) .permitKeepAliveWithoutCalls(true) .executor((TaskExecutor) applicationContext.getBean("grpcServiceExecutor")) .maxConnectionAge(24, TimeUnit.HOURS) .maxConnectionAgeGrace(24, TimeUnit.HOURS); serverBuilder.sslContext(sslContext); } catch (SSLException e) { throw new SecurityException(e); return serverBuilder.build();
LOGGER.info("server build on port only :{}", defaultServerConf.getPort()); serverBuilder = NettyServerBuilder.forPort(defaultServerConf.getPort()); } else { LOGGER.info("server build on address {}:{}", defaultServerConf.getIp(), defaultServerConf.getPort()); new InetSocketAddress( InetAddresses.forString(defaultServerConf.getIp()), defaultServerConf.getPort()); serverBuilder = NettyServerBuilder.forAddress(addr); serverBuilder.addService(service); serverBuilder.addService(service); serverBuilder.executor((TaskExecutor) applicationContext.getBean("grpcServiceExecutor")); serverBuilder.maxInboundMessageSize(256 << 20) .flowControlWindow(16 << 20); return serverBuilder.build();
public HillviewServer(final HostAndPort listenAddress, final IDataSet initialDataset) throws IOException { this.initialDatasets = new HashMap<Integer, IDataSet>(); this.addInitialDataset(initialDataset); this.listenAddress = listenAddress; this.memoizedCommands = new MemoizedResults(); this.server = NettyServerBuilder.forAddress(new InetSocketAddress(listenAddress.getHost(), listenAddress.getPort())) .executor(executorService) .workerEventLoopGroup(workerElg) .bossEventLoopGroup(bossElg) .addService(this) .maxInboundMessageSize(MAX_MESSAGE_SIZE) .build() .start(); this.dataSets = CacheBuilder.newBuilder() .expireAfterAccess(EXPIRE_TIME_IN_HOURS, TimeUnit.HOURS) .removalListener( (RemovalListener<Integer, IDataSet>) removalNotification -> HillviewLogger.instance.info("Removing reference to dataset", "{0}: {1}", removalNotification.getKey(), removalNotification.getValue().toString())) .build(); this.toUnsubscribe = CacheBuilder.newBuilder() .expireAfterAccess(EXPIRE_TIME_IN_HOURS, TimeUnit.HOURS) .build(); }
/** Creates a gRPC server builder for the given port. */ public static AltsServerBuilder forPort(int port) { NettyServerBuilder nettyDelegate = NettyServerBuilder.forAddress(new InetSocketAddress(port)) .maxConnectionIdle(1, TimeUnit.HOURS) .keepAliveTime(270, TimeUnit.SECONDS) .keepAliveTimeout(20, TimeUnit.SECONDS) .permitKeepAliveTime(10, TimeUnit.SECONDS) .permitKeepAliveWithoutCalls(true); return new AltsServerBuilder(nettyDelegate); }
/** {@inheritDoc} */ @Override public Server build() { if (!CheckGcpEnvironment.isOnGcp()) { if (enableUntrustedAlts) { logger.log( Level.WARNING, "Untrusted ALTS mode is enabled and we cannot guarantee the trustworthiness of the " + "ALTS handshaker service"); } else { Status status = Status.INTERNAL.withDescription("ALTS is only allowed to run on Google Cloud Platform"); delegate.intercept(new FailingServerInterceptor(status)); } } delegate.protocolNegotiator( AltsProtocolNegotiator.createServerNegotiator( new TsiHandshakerFactory() { @Override public TsiHandshaker newHandshaker(String authority) { // Used the shared grpc channel to connecting to the ALTS handshaker service. // TODO: Release the channel if it is not used. // https://github.com/grpc/grpc-java/issues/4755. return AltsTsiHandshaker.newServer( HandshakerServiceGrpc.newStub(handshakerChannelPool.getObject()), new AltsHandshakerOptions(RpcProtocolVersionsUtil.getRpcProtocolVersions())); } })); return delegate.build(); }
@Override // Keep this in sync with NettyGrpcServerFactory#configureSecurity protected void configureSecurity(final NettyServerBuilder builder) { final Security security = this.properties.getSecurity(); if (security.isEnabled()) { final File certificateChainFile = toCheckedFile("certificateChain", security.getCertificateChainPath()); final File privateKeyFile = toCheckedFile("privateKey", security.getPrivateKeyPath()); final SslContextBuilder sslContextBuilder = GrpcSslContexts.forServer(certificateChainFile, privateKeyFile); if (security.getClientAuth() != ClientAuth.NONE) { sslContextBuilder.clientAuth(of(security.getClientAuth())); final String trustCertCollectionPath = security.getTrustCertCollectionPath(); if (trustCertCollectionPath != null && !trustCertCollectionPath.isEmpty()) { final File trustCertCollectionFile = toCheckedFile("trustCertCollection", trustCertCollectionPath); sslContextBuilder.trustManager(trustCertCollectionFile); } } try { builder.sslContext(sslContextBuilder.build()); } catch (final SSLException e) { throw new IllegalStateException("Failed to create ssl context for grpc server", e); } } }
@Override // Keep this in sync with NettyGrpcServerFactory#configureSecurity protected void configureSecurity(final NettyServerBuilder builder) { final Security security = this.properties.getSecurity(); if (security.isEnabled()) { final File certificateChainFile = toCheckedFile("certificateChain", security.getCertificateChainPath()); final File privateKeyFile = toCheckedFile("privateKey", security.getPrivateKeyPath()); final SslContextBuilder sslContextBuilder = GrpcSslContexts.forServer(certificateChainFile, privateKeyFile); if (security.getClientAuth() != ClientAuth.NONE) { sslContextBuilder.clientAuth(of(security.getClientAuth())); final String trustCertCollectionPath = security.getTrustCertCollectionPath(); if (trustCertCollectionPath != null && !trustCertCollectionPath.isEmpty()) { final File trustCertCollectionFile = toCheckedFile("trustCertCollection", trustCertCollectionPath); sslContextBuilder.trustManager(trustCertCollectionFile); } } try { builder.sslContext(sslContextBuilder.build()); } catch (final SSLException e) { throw new IllegalStateException("Failed to create ssl context for grpc server", e); } } }
@Override protected NettyServerBuilder newServerBuilder() { final String address = getAddress(); final int port = getPort(); if (GrpcServerProperties.ANY_IP_ADDRESS.equals(address)) { return NettyServerBuilder.forPort(port); } else { return NettyServerBuilder.forAddress(new InetSocketAddress(InetAddresses.forString(address), port)); } }
/** {@inheritDoc} */ @Override public AltsServerBuilder addService(ServerServiceDefinition service) { delegate.addService(service); return this; }