All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.shaded.vertx.core.net.impl.SslHandshakeCompletionHandler Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
/*
 * Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
 * which is available at https://www.apache.org/licenses/LICENSE-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
 */
package com.arangodb.shaded.vertx.core.net.impl;

import com.arangodb.shaded.netty.channel.Channel;
import com.arangodb.shaded.netty.channel.ChannelHandlerContext;
import com.arangodb.shaded.netty.channel.ChannelInboundHandlerAdapter;
import com.arangodb.shaded.netty.handler.ssl.SniCompletionEvent;
import com.arangodb.shaded.netty.handler.ssl.SslHandshakeCompletionEvent;
import com.arangodb.shaded.netty.util.Attribute;
import com.arangodb.shaded.netty.util.AttributeKey;
import com.arangodb.shaded.netty.util.concurrent.Promise;
import com.arangodb.shaded.vertx.core.AsyncResult;
import com.arangodb.shaded.vertx.core.Future;
import com.arangodb.shaded.vertx.core.Handler;

/**
 * An handler that waits for SSL handshake completion and dispatch it to the server handler.
 *
 * @author Julien Viet
 */
public class SslHandshakeCompletionHandler extends ChannelInboundHandlerAdapter {

  static AttributeKey SERVER_NAME_ATTR = AttributeKey.valueOf("sniServerName");
  private final Promise promise;

  public SslHandshakeCompletionHandler(Promise promise) {
    this.promise = promise;
  }

  @Override
  public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    if (evt instanceof SniCompletionEvent) {
      SniCompletionEvent completion = (SniCompletionEvent) evt;
      if (completion.isSuccess()) {
        Attribute val = ctx.channel().attr(SERVER_NAME_ATTR);
        val.set(completion.hostname());
      } else {
        promise.tryFailure(completion.cause());
      }
    } else if (evt instanceof SslHandshakeCompletionEvent) {
      SslHandshakeCompletionEvent completion = (SslHandshakeCompletionEvent) evt;
      if (completion.isSuccess()) {
        ctx.pipeline().remove(this);
        promise.setSuccess(null);
      } else {
        promise.tryFailure(completion.cause());
      }
    } else {
      ctx.fireUserEventTriggered(evt);
    }
  }
  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    // Ignore these exception as they will be reported to the handler
    // the handshake will ultimately fail or succeed
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy