Search in sources :

Example 81 with LocalAddress

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));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LocalAddress(io.netty.channel.local.LocalAddress) LocalChannel(io.netty.channel.local.LocalChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) WaitUntilActiveHandler(io.grpc.netty.ProtocolNegotiators.WaitUntilActiveHandler) ChannelHandler(io.netty.channel.ChannelHandler) CountDownLatch(java.util.concurrent.CountDownLatch) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLException(javax.net.ssl.SSLException) StatusRuntimeException(io.grpc.StatusRuntimeException) StatusException(io.grpc.StatusException) ExpectedException(org.junit.rules.ExpectedException) ProxyConnectException(io.netty.handler.proxy.ProxyConnectException) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) LocalServerChannel(io.netty.channel.local.LocalServerChannel) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.Test)

Example 82 with LocalAddress

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");
    }
}
Also used : ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) ChannelFuture(io.netty.channel.ChannelFuture) Status(io.grpc.Status) LocalAddress(io.netty.channel.local.LocalAddress) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 83 with LocalAddress

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");
    }
}
Also used : ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) ChannelFuture(io.netty.channel.ChannelFuture) Status(io.grpc.Status) LocalAddress(io.netty.channel.local.LocalAddress) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 84 with LocalAddress

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());
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LocalAddress(io.netty.channel.local.LocalAddress) LocalChannel(io.netty.channel.local.LocalChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) ConnectException(java.net.ConnectException) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalServerChannel(io.netty.channel.local.LocalServerChannel) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Test(org.junit.Test)

Example 85 with LocalAddress

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());
}
Also used : ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) ConnectionBridge(org.spongepowered.common.bridge.network.ConnectionBridge) SpongeUserBanList(org.spongepowered.common.service.server.ban.SpongeUserBanList) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) Inject(org.spongepowered.asm.mixin.injection.Inject) Connection(net.minecraft.network.Connection) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) PermissionService(org.spongepowered.api.service.permission.PermissionService) PlayerList(net.minecraft.server.players.PlayerList) LocalAddress(io.netty.channel.local.LocalAddress) InetAddress(java.net.InetAddress) MinecraftServer(net.minecraft.server.MinecraftServer) IntegratedPlayerListBridge(org.spongepowered.common.bridge.client.server.IntegratedPlayerListBridge) ClientboundPlayerInfoPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) GameProfile(org.spongepowered.api.profile.GameProfile) PlayerInventoryTransaction(org.spongepowered.common.event.tracking.context.transaction.inventory.PlayerInventoryTransaction) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) ServerScoreboardBridge(org.spongepowered.common.bridge.server.ServerScoreboardBridge) PlayerListBridge(org.spongepowered.common.bridge.server.players.PlayerListBridge) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) IpBanList(net.minecraft.server.players.IpBanList) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Set(java.util.Set) RegistryAccess(net.minecraft.core.RegistryAccess) TextComponent(net.minecraft.network.chat.TextComponent) Logger(org.apache.logging.log4j.Logger) BroadcastInventoryChangesEffect(org.spongepowered.common.event.tracking.context.transaction.effect.BroadcastInventoryChangesEffect) SpongeUserView(org.spongepowered.common.entity.player.SpongeUserView) Shadow(org.spongepowered.asm.mixin.Shadow) Packet(net.minecraft.network.protocol.Packet) GameType(net.minecraft.world.level.GameType) ServerLocation(org.spongepowered.api.world.server.ServerLocation) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) Ban(org.spongepowered.api.service.ban.Ban) SimpleDateFormat(java.text.SimpleDateFormat) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) MutableComponent(net.minecraft.network.chat.MutableComponent) UserBanList(net.minecraft.server.players.UserBanList) ServerScoreboard(net.minecraft.server.ServerScoreboard) SpongeIPBanList(org.spongepowered.common.service.server.ban.SpongeIPBanList) PerWorldBorderListener(org.spongepowered.common.server.PerWorldBorderListener) Nullable(javax.annotation.Nullable) Opcodes(org.objectweb.asm.Opcodes) Identity(net.kyori.adventure.identity.Identity) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) UnknownHostException(java.net.UnknownHostException) Cause(org.spongepowered.api.event.Cause) Audience(net.kyori.adventure.audience.Audience) LoginPermissions(org.spongepowered.common.entity.player.LoginPermissions) VecHelper(org.spongepowered.common.util.VecHelper) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) SocketAddress(java.net.SocketAddress) SpongeServer(org.spongepowered.common.SpongeServer) RespawnPlayerEvent(org.spongepowered.api.event.entity.living.player.RespawnPlayerEvent) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) EventContext(org.spongepowered.api.event.EventContext) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) SpongeUserWhiteList(org.spongepowered.common.service.server.whitelist.SpongeUserWhiteList) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) Subject(org.spongepowered.api.service.permission.Subject) At(org.spongepowered.asm.mixin.injection.At) User(org.spongepowered.api.entity.living.player.User) NetworkUtil(org.spongepowered.common.util.NetworkUtil) Sponge(org.spongepowered.api.Sponge) ChatType(net.minecraft.network.chat.ChatType) UUID(java.util.UUID) Final(org.spongepowered.asm.mixin.Final) Instant(java.time.Instant) ClientboundDisconnectPacket(net.minecraft.network.protocol.game.ClientboundDisconnectPacket) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) Optional(java.util.Optional) ClientboundRespawnPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundRespawnPacketAccessor) Level(net.minecraft.world.level.Level) UserWhiteList(net.minecraft.server.players.UserWhiteList) Constants(org.spongepowered.common.util.Constants) CustomBossEvents(net.minecraft.server.bossevents.CustomBossEvents) CompletableFuture(java.util.concurrent.CompletableFuture) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) WorldBorder(net.minecraft.world.level.border.WorldBorder) Component(net.kyori.adventure.text.Component) BorderChangeListener(net.minecraft.world.level.border.BorderChangeListener) Audiences(org.spongepowered.api.adventure.Audiences) Mutable(org.spongepowered.asm.mixin.Mutable) VanishableBridge(org.spongepowered.common.bridge.data.VanishableBridge) SpongeCommon(org.spongepowered.common.SpongeCommon) ClientboundLoginPacket(net.minecraft.network.protocol.game.ClientboundLoginPacket) ResourceKey(net.minecraft.resources.ResourceKey) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) Vector3d(org.spongepowered.math.vector.Vector3d) Slice(org.spongepowered.asm.mixin.injection.Slice) TextComponent(net.minecraft.network.chat.TextComponent) LocalAddress(io.netty.channel.local.LocalAddress) UnknownHostException(java.net.UnknownHostException) GameProfile(org.spongepowered.api.profile.GameProfile) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) Subject(org.spongepowered.api.service.permission.Subject) PermissionService(org.spongepowered.api.service.permission.PermissionService) MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) InetAddress(java.net.InetAddress)

Aggregations

LocalAddress (io.netty.channel.local.LocalAddress)116 Bootstrap (io.netty.bootstrap.Bootstrap)66 LocalChannel (io.netty.channel.local.LocalChannel)66 LocalServerChannel (io.netty.channel.local.LocalServerChannel)66 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)63 Channel (io.netty.channel.Channel)61 Test (org.junit.Test)47 Test (org.junit.jupiter.api.Test)39 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)32 EventLoopGroup (io.netty.channel.EventLoopGroup)32 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)31 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)28 ConnectException (java.net.ConnectException)27 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)27 Subscription (rx.Subscription)27 HttpInitiator (org.jocean.http.client.HttpClient.HttpInitiator)26 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)26 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)25 ChannelFuture (io.netty.channel.ChannelFuture)24 SSLException (javax.net.ssl.SSLException)22