use of io.netty.channel.local.LocalAddress in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method waitUntilActiveHandler_handlerAdded.
@Test
public void waitUntilActiveHandler_handlerAdded() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final WaitUntilActiveHandler handler = new WaitUntilActiveHandler(new ChannelHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
assertTrue(ctx.channel().isActive());
latch.countDown();
super.handlerAdded(ctx);
}
}, noopLogger);
ChannelHandler lateAddingHandler = new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ctx.pipeline().addLast(handler);
ctx.pipeline().fireUserEventTriggered(ProtocolNegotiationEvent.DEFAULT);
// do not propagate channelActive().
}
};
LocalAddress addr = new LocalAddress("local");
ChannelFuture cf = new Bootstrap().channel(LocalChannel.class).handler(lateAddingHandler).group(group).register();
chan = cf.channel();
ChannelFuture sf = new ServerBootstrap().channel(LocalServerChannel.class).childHandler(new ChannelHandlerAdapter() {
}).group(group).bind(addr);
server = sf.channel();
sf.sync();
assertEquals(1, latch.getCount());
chan.connect(addr).sync();
assertTrue(latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
assertNull(chan.pipeline().context(WaitUntilActiveHandler.class));
}
use of io.netty.channel.local.LocalAddress in project grpc-java by grpc.
the class WriteBufferingAndExceptionHandlerTest method channelCloseFailuresPropagated.
@Test
public void channelCloseFailuresPropagated() throws Exception {
WriteBufferingAndExceptionHandler handler = new WriteBufferingAndExceptionHandler(new ChannelHandlerAdapter() {
});
LocalAddress addr = new LocalAddress("local");
ChannelFuture cf = new Bootstrap().channel(LocalChannel.class).handler(handler).group(group).register();
chan = cf.channel();
cf.sync();
ChannelFuture sf = new ServerBootstrap().channel(LocalServerChannel.class).childHandler(new ChannelHandlerAdapter() {
}).group(group).bind(addr);
server = sf.channel();
sf.sync();
ChannelFuture wf = chan.writeAndFlush(new Object());
chan.connect(addr);
chan.close();
try {
wf.sync();
fail();
} catch (Exception e) {
Status status = Status.fromThrowable(e);
assertThat(status.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(status.getDescription()).contains("Connection closing while performing protocol negotiation");
}
}
use of io.netty.channel.local.LocalAddress in project grpc-java by grpc.
the class WriteBufferingAndExceptionHandlerTest method channelInactiveFailuresPropagated.
@Test
public void channelInactiveFailuresPropagated() throws Exception {
WriteBufferingAndExceptionHandler handler = new WriteBufferingAndExceptionHandler(new ChannelHandlerAdapter() {
});
LocalAddress addr = new LocalAddress("local");
ChannelFuture cf = new Bootstrap().channel(LocalChannel.class).handler(handler).group(group).register();
chan = cf.channel();
cf.sync();
ChannelFuture sf = new ServerBootstrap().channel(LocalServerChannel.class).childHandler(new ChannelHandlerAdapter() {
}).group(group).bind(addr);
server = sf.channel();
sf.sync();
ChannelFuture wf = chan.writeAndFlush(new Object());
chan.connect(addr);
chan.pipeline().fireChannelInactive();
try {
wf.sync();
fail();
} catch (Exception e) {
Status status = Status.fromThrowable(e);
assertThat(status.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(status.getDescription()).contains("Connection closed while performing protocol negotiation");
}
}
use of io.netty.channel.local.LocalAddress in project grpc-java by grpc.
the class WriteBufferingAndExceptionHandlerTest method uncaughtException_closeAtMostOnce.
@Test
public void uncaughtException_closeAtMostOnce() throws Exception {
final AtomicInteger closes = new AtomicInteger();
WriteBufferingAndExceptionHandler handler = new WriteBufferingAndExceptionHandler(new ChannelDuplexHandler() {
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
closes.getAndIncrement();
// Simulates a loop between this handler and the WriteBufferingAndExceptionHandler.
ctx.fireExceptionCaught(Status.ABORTED.withDescription("zap").asRuntimeException());
super.close(ctx, promise);
}
});
LocalAddress addr = new LocalAddress("local");
ChannelFuture cf = new Bootstrap().channel(LocalChannel.class).handler(handler).group(group).register();
chan = cf.channel();
cf.sync();
ChannelFuture sf = new ServerBootstrap().channel(LocalServerChannel.class).childHandler(new ChannelHandlerAdapter() {
}).group(group).bind(addr);
server = sf.channel();
sf.sync();
chan.connect(addr).sync();
chan.close().sync();
assertEquals(1, closes.get());
}
use of io.netty.channel.local.LocalAddress in project SpongeCommon by SpongePowered.
the class PlayerListMixin method impl$canPlayerLoginServer.
protected final CompletableFuture<net.minecraft.network.chat.Component> impl$canPlayerLoginServer(final SocketAddress param0, final com.mojang.authlib.GameProfile param1) {
final SpongeGameProfile profile = SpongeGameProfile.basicOf(param1);
return Sponge.server().serviceProvider().banService().find(profile).thenCompose(profileBanOpt -> {
if (profileBanOpt.isPresent()) {
final Ban.Profile var0 = profileBanOpt.get();
final MutableComponent var1 = new TranslatableComponent("multiplayer.disconnect.banned.reason", var0.reason().orElse(Component.empty()));
if (var0.expirationDate().isPresent()) {
var1.append(new TranslatableComponent("multiplayer.disconnect.banned.expiration", BAN_DATE_FORMAT.format(var0.expirationDate().get())));
}
return CompletableFuture.completedFuture(var1);
}
if (param0 instanceof LocalAddress) {
// don't bother looking up IP bans on local address
return CompletableFuture.completedFuture(null);
}
final InetAddress address;
try {
address = InetAddress.getByName(NetworkUtil.getHostString(param0));
} catch (final UnknownHostException ex) {
// no
return CompletableFuture.completedFuture(new TextComponent(ex.getMessage()));
}
return Sponge.server().serviceProvider().banService().find(address).thenCompose(ipBanOpt -> {
if (ipBanOpt.isPresent()) {
final Ban.IP var2 = ipBanOpt.get();
final MutableComponent var3 = new TranslatableComponent("multiplayer.disconnect.banned_ip.reason", var2.reason().orElse(Component.empty()));
if (var2.expirationDate().isPresent()) {
var3.append(new TranslatableComponent("multiplayer.disconnect.banned_ip.expiration", BAN_DATE_FORMAT.format(var2.expirationDate().get())));
}
return CompletableFuture.completedFuture(var3);
}
return CompletableFuture.supplyAsync(() -> {
if (!Sponge.server().isWhitelistEnabled()) {
return true;
}
final PermissionService permissionService = Sponge.server().serviceProvider().permissionService();
Subject subject = permissionService.userSubjects().subject(param1.getId().toString()).orElse(null);
if (subject == null) {
subject = permissionService.defaults();
}
return subject.hasPermission(LoginPermissions.BYPASS_WHITELIST_PERMISSION);
}, SpongeCommon.server()).thenCompose(w -> {
if (w) {
return CompletableFuture.completedFuture(null);
}
return Sponge.server().serviceProvider().whitelistService().isWhitelisted(profile).<net.minecraft.network.chat.Component>thenApply(whitelisted -> {
if (!whitelisted) {
return new TranslatableComponent("multiplayer.disconnect.not_whitelisted");
}
return null;
});
});
});
}).thenApplyAsync(component -> {
if (component != null) {
return component;
}
if (this.players.size() >= this.maxPlayers && !this.shadow$canBypassPlayerLimit(param1)) {
return new TranslatableComponent("multiplayer.disconnect.server_full");
}
return null;
}, SpongeCommon.server());
}
Aggregations