• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SocksInitRequestDecoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.handler.codec.socks.SocksInitRequestDecoder的典型用法代码示例。如果您正苦于以下问题:Java SocksInitRequestDecoder类的具体用法?Java SocksInitRequestDecoder怎么用?Java SocksInitRequestDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SocksInitRequestDecoder类属于io.netty.handler.codec.socks包,在下文中一共展示了SocksInitRequestDecoder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: start

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
public void start() {
    Configuration config = Configuration.INSTANCE;
    InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        socketChannel.pipeline()
                                .addLast("logging", new LoggingHandler(LogLevel.DEBUG))
                                .addLast(new SocksInitRequestDecoder())
                                .addLast(new SocksMessageEncoder())
                                .addLast(new Socks5Handler())
                                .addLast(Status.TRAFFIC_HANDLER);
                    }
                });
        log.info("\tStartup {}-{}-client [{}{}]", Constants.APP_NAME, Constants.APP_VERSION, config.getMode(), config.getMode().equals("socks5") ? "" : ":" + config.getProtocol());
        new Thread(() -> new UdpServer().start()).start();
        ChannelFuture future = bootstrap.bind(config.getLocalHost(), config.getLocalPort()).sync();
        future.addListener(future1 -> log.info("\tTCP listening at {}:{}...", config.getLocalHost(), config.getLocalPort()));
        future.channel().closeFuture().sync();
    } catch (Exception e) {
        log.error("\tSocket bind failure ({})", e.getMessage());
    } finally {
        log.info("\tShutting down");
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:ZhangJiupeng,项目名称:AgentX,代码行数:34,代码来源:XClient.java


示例2: initChannel

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
	ChannelPipeline p = socketChannel.pipeline();
	p.addLast(new SocksInitRequestDecoder());
	p.addLast(socksMessageEncoder);
	p.addLast(socksServerHandler);
	p.addLast(trafficHandler);
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:9,代码来源:SocksServerInitializer.java


示例3: initChannel

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline p = socketChannel.pipeline();
    p.addLast(new SocksInitRequestDecoder());
    p.addLast(socksMessageEncoder);
    p.addLast(socksServerHandler);
}
 
开发者ID:zhoulifu,项目名称:ss-java,代码行数:8,代码来源:SocksServerInitializer.java


示例4: initChannel

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline p = socketChannel.pipeline();
    //Socks request decode it will remove itself
    p.addLast(new SocksInitRequestDecoder());
    //socks encode
    p.addLast(new SocksMessageEncoder());
    //process SocksRequest
    p.addLast(new SocksRequestHandler());
    // connect to Shadow Socks
    p.addLast(new ConnectRelayHandler(instance.getAddress(), instance.getPort(), () -> new ShadowSocksClientInitializer(shadowSocksContext)));

}
 
开发者ID:lujianbo,项目名称:moonlight-ss,代码行数:14,代码来源:SocksServerInitializer.java


示例5: initChannel

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline channelPipeline = socketChannel.pipeline();
    channelPipeline.addLast(SocksInitRequestDecoder.getName(), new SocksInitRequestDecoder());
    channelPipeline.addLast(SocksMessageEncoder.getName(), socksMessageEncoder);
    channelPipeline.addLast(SocksServerHandler.getName(), socksServerHandler);
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:8,代码来源:SocksServerInitializer.java


示例6: enableSocks

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
private void enableSocks(ChannelHandlerContext ctx, ByteBuf msg) {
    ChannelPipeline pipeline = ctx.pipeline();
    pipeline.addFirst(socksProxyHandler);
    pipeline.addFirst(socksMessageEncoder);
    pipeline.addFirst(new SocksInitRequestDecoder());

    // re-unify (with SOCKS enabled)
    ctx.pipeline().fireChannelRead(msg);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:10,代码来源:PortUnificationHandler.java


示例7: shouldSwitchToSOCKS

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Test
    public void shouldSwitchToSOCKS() throws IOException, InterruptedException {
        // given - embedded channel
        short localPort = 1234;
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(new MockServerUnificationInitializer(mock(LifeCycle.class), new HttpStateHandler(mock(Scheduler.class)), null));
//        embeddedChannel.attr(HTTP_CONNECT_SOCKET).set(new InetSocketAddress(localPort));

        // and - no SOCKS handlers
        assertThat(embeddedChannel.pipeline().get(SocksProxyHandler.class), is(nullValue()));
        assertThat(embeddedChannel.pipeline().get(SocksMessageEncoder.class), is(nullValue()));
        assertThat(embeddedChannel.pipeline().get(SocksInitRequestDecoder.class), is(nullValue()));

        // when - SOCKS INIT message
        embeddedChannel.writeInbound(Unpooled.wrappedBuffer(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x02,                                        // 1 authentication method
            (byte) 0x00,                                        // NO_AUTH
            (byte) 0x02,                                        // AUTH_PASSWORD
        }));


        // then - INIT response
        assertThat(ByteBufUtil.hexDump((ByteBuf) embeddedChannel.readOutbound()), is(Hex.encodeHexString(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x00,                                        // NO_AUTH
        })));

        // and then - should add SOCKS handlers first
        assertThat(String.valueOf(embeddedChannel.pipeline().names()), embeddedChannel.pipeline().names(), contains(
            "SocksCmdRequestDecoder#0",
            "SocksMessageEncoder#0",
            "SocksProxyHandler#0",
            "MockServerUnificationInitializer#0",
            "DefaultChannelPipeline$TailContext#0"
        ));
    }
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:37,代码来源:HttpProxyUnificationInitializerTest.java


示例8: initChannel

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
	ch.pipeline().addLast(new SocksInitRequestDecoder()).addLast(new SocksCmdRequestDecoder()).addLast(new IdleStateHandler(this.idleRead, this.idleWrite, this.idleAll)).addLast(this.channelHandlerBuilder.build());
}
 
开发者ID:KimShen,项目名称:sissi,代码行数:5,代码来源:Socks5ProxyServerHandlerChannelInitializer.java


示例9: shouldHandleErrorsDuringSOCKSConnection

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Test
    public void shouldHandleErrorsDuringSOCKSConnection() {
        // given - embedded channel
        short localPort = 1234;
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(new MockServerUnificationInitializer(mock(LifeCycle.class), new HttpStateHandler(mock(Scheduler.class)), null));
//        embeddedChannel.attr(HTTP_CONNECT_SOCKET).set(new InetSocketAddress(localPort));

        // and - no SOCKS handlers
        assertThat(embeddedChannel.pipeline().get(SocksProxyHandler.class), is(nullValue()));
        assertThat(embeddedChannel.pipeline().get(SocksMessageEncoder.class), is(nullValue()));
        assertThat(embeddedChannel.pipeline().get(SocksInitRequestDecoder.class), is(nullValue()));

        // when - SOCKS INIT message
        embeddedChannel.writeInbound(Unpooled.wrappedBuffer(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x02,                                        // 1 authentication method
            (byte) 0x00,                                        // NO_AUTH
            (byte) 0x02,                                        // AUTH_PASSWORD
        }));


        // then - INIT response
        assertThat(ByteBufUtil.hexDump((ByteBuf) embeddedChannel.readOutbound()), is(Hex.encodeHexString(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x00,                                        // NO_AUTH
        })));

        // and then - should add SOCKS handlers first
        if (new MockServerLogger().isEnabled(TRACE)) {
            assertThat(String.valueOf(embeddedChannel.pipeline().names()), embeddedChannel.pipeline().names(), contains(
                "LoggingHandler#0",
                "SocksCmdRequestDecoder#0",
                "SocksMessageEncoder#0",
                "SocksProxyHandler#0",
                "MockServerUnificationInitializer#0",
                "DefaultChannelPipeline$TailContext#0"
            ));
        } else {
            assertThat(String.valueOf(embeddedChannel.pipeline().names()), embeddedChannel.pipeline().names(), contains(
                "SocksCmdRequestDecoder#0",
                "SocksMessageEncoder#0",
                "SocksProxyHandler#0",
                "MockServerUnificationInitializer#0",
                "DefaultChannelPipeline$TailContext#0"
            ));
        }

        // and when - SOCKS CONNECT command
        embeddedChannel.writeInbound(Unpooled.wrappedBuffer(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x01,                                        // command type CONNECT
            (byte) 0x00,                                        // reserved (must be 0x00)
            (byte) 0x01,                                        // address type IPv4
            (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01, // ip address
            (byte) (localPort & 0xFF00), (byte) localPort       // port
        }));

        // then - CONNECT response
        assertThat(ByteBufUtil.hexDump((ByteBuf) embeddedChannel.readOutbound()), is(Hex.encodeHexString(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x01,                                        // general failure (caused by connection failure)
            (byte) 0x00,                                        // reserved (must be 0x00)
            (byte) 0x01,                                        // address type IPv4
            (byte) 0x7f, (byte) 0x00, (byte) 0x00, (byte) 0x01, // ip address
            (byte) (localPort & 0xFF00), (byte) localPort       // port
        })));

        // then - channel is closed after error
        assertThat(embeddedChannel.isOpen(), is(false));
    }
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:71,代码来源:HttpProxyUnificationInitializerSOCKSErrorTest.java


示例10: shouldSwitchToSOCKS

import io.netty.handler.codec.socks.SocksInitRequestDecoder; //导入依赖的package包/类
@Test
    public void shouldSwitchToSOCKS() throws IOException, InterruptedException {
        // given - embedded channel
        short localPort = 1234;
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(new MockServerUnificationInitializer(mock(LifeCycle.class), new HttpStateHandler(mock(Scheduler.class)), null));
//        embeddedChannel.attr(HTTP_CONNECT_SOCKET).set(new InetSocketAddress(localPort));

        // and - no SOCKS handlers
        assertThat(embeddedChannel.pipeline().get(SocksProxyHandler.class), is(nullValue()));
        assertThat(embeddedChannel.pipeline().get(SocksMessageEncoder.class), is(nullValue()));
        assertThat(embeddedChannel.pipeline().get(SocksInitRequestDecoder.class), is(nullValue()));

        // when - SOCKS INIT message
        embeddedChannel.writeInbound(Unpooled.wrappedBuffer(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x02,                                        // 1 authentication method
            (byte) 0x00,                                        // NO_AUTH
            (byte) 0x02,                                        // AUTH_PASSWORD
        }));


        // then - INIT response
        assertThat(ByteBufUtil.hexDump((ByteBuf) embeddedChannel.readOutbound()), is(Hex.encodeHexString(new byte[]{
            (byte) 0x05,                                        // SOCKS5
            (byte) 0x00,                                        // NO_AUTH
        })));

        // and then - should add SOCKS handlers first
        if (new MockServerLogger().isEnabled(TRACE)) {
            assertThat(String.valueOf(embeddedChannel.pipeline().names()), embeddedChannel.pipeline().names(), contains(
                "LoggingHandler#0",
                "SocksCmdRequestDecoder#0",
                "SocksMessageEncoder#0",
                "SocksProxyHandler#0",
                "MockServerUnificationInitializer#0",
                "DefaultChannelPipeline$TailContext#0"
            ));
        } else {
            assertThat(String.valueOf(embeddedChannel.pipeline().names()), embeddedChannel.pipeline().names(), contains(
                "SocksCmdRequestDecoder#0",
                "SocksMessageEncoder#0",
                "SocksProxyHandler#0",
                "MockServerUnificationInitializer#0",
                "DefaultChannelPipeline$TailContext#0"
            ));
        }
    }
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:48,代码来源:DirectProxyUnificationHandlerTest.java



注:本文中的io.netty.handler.codec.socks.SocksInitRequestDecoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AlertDialog类代码示例发布时间:2022-05-22
下一篇:
Java Log类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap