@Override
public MessageLite getHandshakeResponse(FabricHandshake inbound) throws Exception {
if (inbound.getRpcVersion() != FabricRpcConfig.RPC_VERSION) {
throw new RpcException(String.format("Invalid rpc version. Expected %d, actual %d.", inbound.getRpcVersion(), FabricRpcConfig.RPC_VERSION));
}
if (!inbound.hasIdentity() || inbound.getIdentity().getAddress().isEmpty() || inbound.getIdentity().getPort() < 1) {
throw new RpcException(String.format("RPC didn't provide valid counter identity. Received %s.", inbound.getIdentity()));
}
connection.setIdentity(inbound.getIdentity());
final boolean isLoopback = inbound.getIdentity().getAddress().equals(address) && inbound.getIdentity().getPort() == port;
if (!isLoopback) {
FabricConnectionManager manager = connectionRegistry.getConnectionManager(inbound.getIdentity());
connection.wrapCloseHandler(manager.getCloseHandlerCreator());
manager.addExternalConnection(connection);
}
return FabricHandshake.newBuilder().setRpcVersion(FabricRpcConfig.RPC_VERSION).build();
}