@@ -7,6 +7,7 @@ import io.netty.channel.ChannelOption
7
7
import io.netty.channel.EventLoopGroup
8
8
import io.netty.channel.nio.NioEventLoopGroup
9
9
import io.netty.channel.socket.SocketChannel
10
+ import io.netty.channel.socket.nio.NioDatagramChannel
10
11
import io.netty.channel.socket.nio.NioServerSocketChannel
11
12
import io.netty.channel.socket.nio.NioSocketChannel
12
13
import io.netty.handler.codec.socks.SocksCmdRequestDecoder
@@ -39,16 +40,23 @@ class ServerStrap {
39
40
return new Thread (r, " childGroup-" + atomicLong. getAndIncrement())
40
41
}
41
42
})
42
- private Bootstrap childConnectBootstrap = new Bootstrap (). with {
43
- EventLoopGroup group = new NioEventLoopGroup (0 , new ThreadFactory () {
44
- private AtomicLong atomicLong = new AtomicLong ()
43
+ private EventLoopGroup childConnectGroup = new NioEventLoopGroup (0 , new ThreadFactory () {
44
+ private AtomicLong atomicLong = new AtomicLong ()
45
45
46
+ @Override
47
+ Thread newThread (Runnable r ) {
48
+ return new Thread (r, " childConnectGroup-" + atomicLong. getAndIncrement())
49
+ }
50
+ })
51
+ private Bootstrap childConnectBootstrap = new Bootstrap (). with {
52
+ it. group(childConnectGroup). channel(NioSocketChannel . class). handler(new ChannelInitializer<SocketChannel > () {
46
53
@Override
47
- Thread newThread (Runnable r ) {
48
- return new Thread (r, " childConnectGroup-" + atomicLong. getAndIncrement())
54
+ protected void initChannel (SocketChannel socketChannel ) throws Exception {
49
55
}
50
- })
51
- it. group(group). channel(NioSocketChannel . class). handler(new ChannelInitializer<SocketChannel > () {
56
+ }). option(ChannelOption . CONNECT_TIMEOUT_MILLIS , 30000 )
57
+ }
58
+ private Bootstrap childUdpConnectBootstrap = new Bootstrap (). with {
59
+ it. group(childConnectGroup). channel(NioDatagramChannel . class). handler(new ChannelInitializer<SocketChannel > () {
52
60
@Override
53
61
protected void initChannel (SocketChannel socketChannel ) throws Exception {
54
62
}
@@ -62,14 +70,15 @@ class ServerStrap {
62
70
serverBootstrapTemplate. childHandler(new ChannelInitializer<SocketChannel > () {
63
71
@Override
64
72
protected void initChannel (SocketChannel ch ) throws Exception {
65
- ch. pipeline()
73
+ def channel = ch. pipeline()
66
74
.addLast(new SocksMessageEncoder ())
67
75
.addLast(new SocksInitRequestDecoder ())
68
76
.addLast(new InitHandler ())
69
77
.addLast(new SocksCmdRequestDecoder ())
70
78
.addLast(new CmdHandler ())
71
79
.channel()
72
- .attr(ChannelAttrKey . BOOTSTRAP ). set(childConnectBootstrap)
80
+ channel. attr(ChannelAttrKey . BOOTSTRAP ). set(childConnectBootstrap)
81
+ channel. attr(ChannelAttrKey . BOOTSTRAP_UDP ). set(childUdpConnectBootstrap)
73
82
}
74
83
})
75
84
serverBootstrapTemplate. bind(port). sync(). channel(). closeFuture(). await()
0 commit comments