Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
2d947949
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2d947949
编写于
8月 03, 2019
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
netty
上级
288f02b0
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
0 addition
and
1089 deletion
+0
-1089
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/file/FileServer.java
...main/java/org/hongxi/whatsmars/netty/file/FileServer.java
+0
-89
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/file/FileServerHandler.java
...va/org/hongxi/whatsmars/netty/file/FileServerHandler.java
+0
-73
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/http/cors/HttpCorsServer.java
.../org/hongxi/whatsmars/netty/http/cors/HttpCorsServer.java
+0
-104
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/http/cors/HttpCorsServerInitializer.java
.../whatsmars/netty/http/cors/HttpCorsServerInitializer.java
+0
-96
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/http/cors/OkResponseHandler.java
...g/hongxi/whatsmars/netty/http/cors/OkResponseHandler.java
+0
-37
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxy.java
...n/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxy.java
+0
-51
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxyBackendHandler.java
...gxi/whatsmars/netty/proxy/HexDumpProxyBackendHandler.java
+0
-57
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxyFrontendHandler.java
...xi/whatsmars/netty/proxy/HexDumpProxyFrontendHandler.java
+0
-100
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxyInitializer.java
...hongxi/whatsmars/netty/proxy/HexDumpProxyInitializer.java
+0
-39
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/DirectClientHandler.java
...ongxi/whatsmars/netty/socksproxy/DirectClientHandler.java
+0
-41
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/RelayHandler.java
...a/org/hongxi/whatsmars/netty/socksproxy/RelayHandler.java
+0
-58
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServer.java
...va/org/hongxi/whatsmars/netty/socksproxy/SocksServer.java
+0
-44
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerConnectHandler.java
...whatsmars/netty/socksproxy/SocksServerConnectHandler.java
+0
-149
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerHandler.java
...hongxi/whatsmars/netty/socksproxy/SocksServerHandler.java
+0
-85
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerInitializer.java
...xi/whatsmars/netty/socksproxy/SocksServerInitializer.java
+0
-32
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerUtils.java
...g/hongxi/whatsmars/netty/socksproxy/SocksServerUtils.java
+0
-34
未找到文件。
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/file/FileServer.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.file
;
import
io.netty.bootstrap.ServerBootstrap
;
import
io.netty.channel.*
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.channel.socket.nio.NioServerSocketChannel
;
import
io.netty.handler.codec.LineBasedFrameDecoder
;
import
io.netty.handler.codec.string.StringDecoder
;
import
io.netty.handler.codec.string.StringEncoder
;
import
io.netty.handler.logging.LogLevel
;
import
io.netty.handler.logging.LoggingHandler
;
import
io.netty.handler.ssl.SslContext
;
import
io.netty.handler.ssl.SslContextBuilder
;
import
io.netty.handler.ssl.util.SelfSignedCertificate
;
import
io.netty.handler.stream.ChunkedWriteHandler
;
import
io.netty.util.CharsetUtil
;
/**
* Server that accept the path of a file an echo back its content.
*/
public
final
class
FileServer
{
static
final
boolean
SSL
=
System
.
getProperty
(
"ssl"
)
!=
null
;
// Use the same default port with the telnet example so that we can use the telnet client example to access it.
static
final
int
PORT
=
Integer
.
parseInt
(
System
.
getProperty
(
"port"
,
SSL
?
"8992"
:
"8023"
));
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// Configure SSL.
final
SslContext
sslCtx
;
if
(
SSL
)
{
SelfSignedCertificate
ssc
=
new
SelfSignedCertificate
();
sslCtx
=
SslContextBuilder
.
forServer
(
ssc
.
certificate
(),
ssc
.
privateKey
()).
build
();
}
else
{
sslCtx
=
null
;
}
// Configure the server.
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
(
1
);
EventLoopGroup
workerGroup
=
new
NioEventLoopGroup
();
try
{
ServerBootstrap
b
=
new
ServerBootstrap
();
b
.
group
(
bossGroup
,
workerGroup
)
.
channel
(
NioServerSocketChannel
.
class
)
.
option
(
ChannelOption
.
SO_BACKLOG
,
100
)
.
handler
(
new
LoggingHandler
(
LogLevel
.
INFO
))
.
childHandler
(
new
ChannelInitializer
<
SocketChannel
>()
{
@Override
public
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
ChannelPipeline
p
=
ch
.
pipeline
();
if
(
sslCtx
!=
null
)
{
p
.
addLast
(
sslCtx
.
newHandler
(
ch
.
alloc
()));
}
p
.
addLast
(
new
StringEncoder
(
CharsetUtil
.
UTF_8
),
new
LineBasedFrameDecoder
(
8192
),
new
StringDecoder
(
CharsetUtil
.
UTF_8
),
new
ChunkedWriteHandler
(),
new
FileServerHandler
());
}
});
// Start the server.
ChannelFuture
f
=
b
.
bind
(
PORT
).
sync
();
// Wait until the server socket is closed.
f
.
channel
().
closeFuture
().
sync
();
}
finally
{
// Shut down all event loops to terminate all threads.
bossGroup
.
shutdownGracefully
();
workerGroup
.
shutdownGracefully
();
}
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/file/FileServerHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2014 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.file
;
import
io.netty.channel.ChannelFutureListener
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.DefaultFileRegion
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
io.netty.handler.ssl.SslHandler
;
import
io.netty.handler.stream.ChunkedFile
;
import
java.io.RandomAccessFile
;
public
class
FileServerHandler
extends
SimpleChannelInboundHandler
<
String
>
{
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
{
ctx
.
writeAndFlush
(
"HELLO: Type the path of the file to retrieve.\n"
);
}
@Override
public
void
channelRead0
(
ChannelHandlerContext
ctx
,
String
msg
)
throws
Exception
{
RandomAccessFile
raf
=
null
;
long
length
=
-
1
;
try
{
raf
=
new
RandomAccessFile
(
msg
,
"r"
);
length
=
raf
.
length
();
}
catch
(
Exception
e
)
{
ctx
.
writeAndFlush
(
"ERR: "
+
e
.
getClass
().
getSimpleName
()
+
": "
+
e
.
getMessage
()
+
'\n'
);
return
;
}
finally
{
if
(
length
<
0
&&
raf
!=
null
)
{
raf
.
close
();
}
}
ctx
.
write
(
"OK: "
+
raf
.
length
()
+
'\n'
);
if
(
ctx
.
pipeline
().
get
(
SslHandler
.
class
)
==
null
)
{
// SSL not enabled - can use zero-copy file transfer.
ctx
.
write
(
new
DefaultFileRegion
(
raf
.
getChannel
(),
0
,
length
));
}
else
{
// SSL enabled - cannot use zero-copy file transfer.
ctx
.
write
(
new
ChunkedFile
(
raf
));
}
ctx
.
writeAndFlush
(
"\n"
);
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
cause
.
printStackTrace
();
if
(
ctx
.
channel
().
isActive
())
{
ctx
.
writeAndFlush
(
"ERR: "
+
cause
.
getClass
().
getSimpleName
()
+
": "
+
cause
.
getMessage
()
+
'\n'
).
addListener
(
ChannelFutureListener
.
CLOSE
);
}
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/http/cors/HttpCorsServer.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.http.cors
;
import
io.netty.bootstrap.ServerBootstrap
;
import
io.netty.channel.EventLoopGroup
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.channel.socket.nio.NioServerSocketChannel
;
import
io.netty.handler.logging.LogLevel
;
import
io.netty.handler.logging.LoggingHandler
;
import
io.netty.handler.ssl.SslContext
;
import
io.netty.handler.ssl.SslContextBuilder
;
import
io.netty.handler.ssl.util.SelfSignedCertificate
;
/**
* This example server aims to demonstrate
* <a href="http://www.w3.org/TR/cors/">Cross Origin Resource Sharing</a> (CORS) in Netty.
* It does not have a client like most of the other examples, but instead has
* a html page that is loaded to try out CORS support in a web browser.
* <p>
*
* CORS is configured in {@link HttpCorsServerInitializer} and by updating the config you can
* try out various combinations, like using a specific origin instead of a
* wildcard origin ('*').
* <p>
*
* The file {@code src/main/resources/cors/cors.html} contains a very basic example client
* which can be used to try out different configurations. For example, you can add
* custom headers to force a CORS preflight request to make the request fail. Then
* to enable a successful request, configure the CorsHandler to allow that/those
* request headers.
*
* <h2>Testing CORS</h2>
* You can either load the file {@code src/main/resources/cors/cors.html} using a web server
* or load it from the file system using a web browser.
*
* <h3>Using a web server</h3>
* To test CORS support you can serve the file {@code src/main/resources/cors/cors.html}
* using a web server. You can then add a new host name to your systems hosts file, for
* example if you are on Linux you may update /etc/hosts to add an additional name
* for you local system:
* <pre>
* 127.0.0.1 localhost domain1.com
* </pre>
* Now, you should be able to access {@code http://domain1.com/cors.html} depending on how you
* have configured you local web server the exact url may differ.
*
* <h3>Using a web browser</h3>
* Open the file {@code src/main/resources/cors/cors.html} in a web browser. You should see
* loaded page and in the text area the following message:
* <pre>
* 'CORS is not working'
* </pre>
*
* If you inspect the headers being sent using your browser you'll see that the 'Origin'
* request header is {@code 'null'}. This is expected and happens when you load a file from the
* local file system. Netty can handle this by configuring the CorsHandler which is done
* in the {@link HttpCorsServerInitializer}.
*
*/
public
final
class
HttpCorsServer
{
static
final
boolean
SSL
=
System
.
getProperty
(
"ssl"
)
!=
null
;
static
final
int
PORT
=
Integer
.
parseInt
(
System
.
getProperty
(
"port"
,
SSL
?
"8443"
:
"8080"
));
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// Configure SSL.
final
SslContext
sslCtx
;
if
(
SSL
)
{
SelfSignedCertificate
ssc
=
new
SelfSignedCertificate
();
sslCtx
=
SslContextBuilder
.
forServer
(
ssc
.
certificate
(),
ssc
.
privateKey
()).
build
();
}
else
{
sslCtx
=
null
;
}
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
(
1
);
EventLoopGroup
workerGroup
=
new
NioEventLoopGroup
();
try
{
ServerBootstrap
b
=
new
ServerBootstrap
();
b
.
group
(
bossGroup
,
workerGroup
)
.
channel
(
NioServerSocketChannel
.
class
)
.
handler
(
new
LoggingHandler
(
LogLevel
.
INFO
))
.
childHandler
(
new
HttpCorsServerInitializer
(
sslCtx
));
b
.
bind
(
PORT
).
sync
().
channel
().
closeFuture
().
sync
();
}
finally
{
bossGroup
.
shutdownGracefully
();
workerGroup
.
shutdownGracefully
();
}
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/http/cors/HttpCorsServerInitializer.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.http.cors
;
import
io.netty.channel.ChannelInitializer
;
import
io.netty.channel.ChannelPipeline
;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.handler.codec.http.HttpObjectAggregator
;
import
io.netty.handler.codec.http.HttpRequestDecoder
;
import
io.netty.handler.codec.http.HttpResponseEncoder
;
import
io.netty.handler.codec.http.cors.CorsConfig
;
import
io.netty.handler.codec.http.cors.CorsConfigBuilder
;
import
io.netty.handler.codec.http.cors.CorsHandler
;
import
io.netty.handler.ssl.SslContext
;
import
io.netty.handler.stream.ChunkedWriteHandler
;
/**
* Please refer to the {@link CorsConfig} javadocs for information about all the
* configuration options available.
*
* Below are some of configuration discussed in this example:
* <h3>Support only a specific origin</h3>
* To support a single origin instead of the wildcard use the following:
* <pre>
* CorsConfig corsConfig = CorsConfig.withOrigin("http://domain1.com")
* </pre>
*
* <h3>Enable loading from the file system</h3>
* To enable the server to handle an origin specified as 'null', which happens
* when a web browser loads a file from the local file system use the following:
* <pre>
* corsConfig.isNullOriginAllowed()
* </pre>
*
* <h3>Enable request headers</h3>
* To enable additional request headers:
* <pre>
* corsConfig.allowedRequestHeaders("custom-request-header")
* </pre>
*
* <h3>Expose response headers</h3>
* By default a browser only exposes the following simple header:
* <ul>
* <li>Cache-Control</li>
* <li>Content-Language</li>
* <li>Content-Type</li>
* <li>Expires</li>
* <li>Last-Modified</li>
* <li>Pragma</li>
* </ul>
* Any of the above response headers can be retrieved by:
* <pre>
* xhr.getResponseHeader("Content-Type");
* </pre>
* If you need to get access to other headers this must be enabled by the server, for example:
* <pre>
* corsConfig.exposedHeaders("custom-response-header");
* </pre>
*/
public
class
HttpCorsServerInitializer
extends
ChannelInitializer
<
SocketChannel
>
{
private
final
SslContext
sslCtx
;
public
HttpCorsServerInitializer
(
SslContext
sslCtx
)
{
this
.
sslCtx
=
sslCtx
;
}
@Override
public
void
initChannel
(
SocketChannel
ch
)
{
CorsConfig
corsConfig
=
CorsConfigBuilder
.
forAnyOrigin
().
allowNullOrigin
().
allowCredentials
().
build
();
ChannelPipeline
pipeline
=
ch
.
pipeline
();
if
(
sslCtx
!=
null
)
{
pipeline
.
addLast
(
sslCtx
.
newHandler
(
ch
.
alloc
()));
}
pipeline
.
addLast
(
new
HttpResponseEncoder
());
pipeline
.
addLast
(
new
HttpRequestDecoder
());
pipeline
.
addLast
(
new
HttpObjectAggregator
(
65536
));
pipeline
.
addLast
(
new
ChunkedWriteHandler
());
pipeline
.
addLast
(
new
CorsHandler
(
corsConfig
));
pipeline
.
addLast
(
new
OkResponseHandler
());
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/http/cors/OkResponseHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version
* 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package
org.hongxi.whatsmars.netty.http.cors
;
import
io.netty.channel.ChannelFutureListener
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
io.netty.handler.codec.http.DefaultFullHttpResponse
;
import
io.netty.handler.codec.http.FullHttpResponse
;
import
io.netty.handler.codec.http.HttpResponseStatus
;
import
io.netty.handler.codec.http.HttpVersion
;
/**
* A simple handler which will simple return a successful Http
* response for any request.
*/
public
class
OkResponseHandler
extends
SimpleChannelInboundHandler
<
Object
>
{
@Override
public
void
channelRead0
(
ChannelHandlerContext
ctx
,
Object
msg
)
{
final
FullHttpResponse
response
=
new
DefaultFullHttpResponse
(
HttpVersion
.
HTTP_1_1
,
HttpResponseStatus
.
OK
);
response
.
headers
().
set
(
"custom-response-header"
,
"Some value"
);
ctx
.
writeAndFlush
(
response
).
addListener
(
ChannelFutureListener
.
CLOSE
);
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxy.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.proxy
;
import
io.netty.bootstrap.ServerBootstrap
;
import
io.netty.channel.ChannelOption
;
import
io.netty.channel.EventLoopGroup
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.channel.socket.nio.NioServerSocketChannel
;
import
io.netty.handler.logging.LogLevel
;
import
io.netty.handler.logging.LoggingHandler
;
public
final
class
HexDumpProxy
{
static
final
int
LOCAL_PORT
=
Integer
.
parseInt
(
System
.
getProperty
(
"localPort"
,
"8443"
));
static
final
String
REMOTE_HOST
=
System
.
getProperty
(
"remoteHost"
,
"www.google.com"
);
static
final
int
REMOTE_PORT
=
Integer
.
parseInt
(
System
.
getProperty
(
"remotePort"
,
"443"
));
public
static
void
main
(
String
[]
args
)
throws
Exception
{
System
.
err
.
println
(
"Proxying *:"
+
LOCAL_PORT
+
" to "
+
REMOTE_HOST
+
':'
+
REMOTE_PORT
+
" ..."
);
// Configure the bootstrap.
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
(
1
);
EventLoopGroup
workerGroup
=
new
NioEventLoopGroup
();
try
{
ServerBootstrap
b
=
new
ServerBootstrap
();
b
.
group
(
bossGroup
,
workerGroup
)
.
channel
(
NioServerSocketChannel
.
class
)
.
handler
(
new
LoggingHandler
(
LogLevel
.
INFO
))
.
childHandler
(
new
HexDumpProxyInitializer
(
REMOTE_HOST
,
REMOTE_PORT
))
.
childOption
(
ChannelOption
.
AUTO_READ
,
false
)
.
bind
(
LOCAL_PORT
).
sync
().
channel
().
closeFuture
().
sync
();
}
finally
{
bossGroup
.
shutdownGracefully
();
workerGroup
.
shutdownGracefully
();
}
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxyBackendHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.proxy
;
import
io.netty.channel.*
;
public
class
HexDumpProxyBackendHandler
extends
ChannelInboundHandlerAdapter
{
private
final
Channel
inboundChannel
;
public
HexDumpProxyBackendHandler
(
Channel
inboundChannel
)
{
this
.
inboundChannel
=
inboundChannel
;
}
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
{
ctx
.
read
();
}
@Override
public
void
channelRead
(
final
ChannelHandlerContext
ctx
,
Object
msg
)
{
inboundChannel
.
writeAndFlush
(
msg
).
addListener
(
new
ChannelFutureListener
()
{
@Override
public
void
operationComplete
(
ChannelFuture
future
)
{
if
(
future
.
isSuccess
())
{
ctx
.
channel
().
read
();
}
else
{
future
.
channel
().
close
();
}
}
});
}
@Override
public
void
channelInactive
(
ChannelHandlerContext
ctx
)
{
HexDumpProxyFrontendHandler
.
closeOnFlush
(
inboundChannel
);
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
cause
.
printStackTrace
();
HexDumpProxyFrontendHandler
.
closeOnFlush
(
ctx
.
channel
());
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxyFrontendHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.proxy
;
import
io.netty.bootstrap.Bootstrap
;
import
io.netty.buffer.Unpooled
;
import
io.netty.channel.*
;
public
class
HexDumpProxyFrontendHandler
extends
ChannelInboundHandlerAdapter
{
private
final
String
remoteHost
;
private
final
int
remotePort
;
// As we use inboundChannel.eventLoop() when building the Bootstrap this does not need to be volatile as
// the outboundChannel will use the same EventLoop (and therefore Thread) as the inboundChannel.
private
Channel
outboundChannel
;
public
HexDumpProxyFrontendHandler
(
String
remoteHost
,
int
remotePort
)
{
this
.
remoteHost
=
remoteHost
;
this
.
remotePort
=
remotePort
;
}
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
{
final
Channel
inboundChannel
=
ctx
.
channel
();
// Start the connection attempt.
Bootstrap
b
=
new
Bootstrap
();
b
.
group
(
inboundChannel
.
eventLoop
())
.
channel
(
ctx
.
channel
().
getClass
())
.
handler
(
new
HexDumpProxyBackendHandler
(
inboundChannel
))
.
option
(
ChannelOption
.
AUTO_READ
,
false
);
ChannelFuture
f
=
b
.
connect
(
remoteHost
,
remotePort
);
outboundChannel
=
f
.
channel
();
f
.
addListener
(
new
ChannelFutureListener
()
{
@Override
public
void
operationComplete
(
ChannelFuture
future
)
{
if
(
future
.
isSuccess
())
{
// connection complete start to read first data
inboundChannel
.
read
();
}
else
{
// Close the connection if the connection attempt has failed.
inboundChannel
.
close
();
}
}
});
}
@Override
public
void
channelRead
(
final
ChannelHandlerContext
ctx
,
Object
msg
)
{
if
(
outboundChannel
.
isActive
())
{
outboundChannel
.
writeAndFlush
(
msg
).
addListener
(
new
ChannelFutureListener
()
{
@Override
public
void
operationComplete
(
ChannelFuture
future
)
{
if
(
future
.
isSuccess
())
{
// was able to flush out data, start to read the next chunk
ctx
.
channel
().
read
();
}
else
{
future
.
channel
().
close
();
}
}
});
}
}
@Override
public
void
channelInactive
(
ChannelHandlerContext
ctx
)
{
if
(
outboundChannel
!=
null
)
{
closeOnFlush
(
outboundChannel
);
}
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
cause
.
printStackTrace
();
closeOnFlush
(
ctx
.
channel
());
}
/**
* Closes the specified channel after all queued write requests are flushed.
*/
static
void
closeOnFlush
(
Channel
ch
)
{
if
(
ch
.
isActive
())
{
ch
.
writeAndFlush
(
Unpooled
.
EMPTY_BUFFER
).
addListener
(
ChannelFutureListener
.
CLOSE
);
}
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/proxy/HexDumpProxyInitializer.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.proxy
;
import
io.netty.channel.ChannelInitializer
;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.handler.logging.LogLevel
;
import
io.netty.handler.logging.LoggingHandler
;
public
class
HexDumpProxyInitializer
extends
ChannelInitializer
<
SocketChannel
>
{
private
final
String
remoteHost
;
private
final
int
remotePort
;
public
HexDumpProxyInitializer
(
String
remoteHost
,
int
remotePort
)
{
this
.
remoteHost
=
remoteHost
;
this
.
remotePort
=
remotePort
;
}
@Override
public
void
initChannel
(
SocketChannel
ch
)
{
ch
.
pipeline
().
addLast
(
new
LoggingHandler
(
LogLevel
.
INFO
),
new
HexDumpProxyFrontendHandler
(
remoteHost
,
remotePort
));
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/DirectClientHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.socksproxy
;
import
io.netty.channel.Channel
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelInboundHandlerAdapter
;
import
io.netty.util.concurrent.Promise
;
public
final
class
DirectClientHandler
extends
ChannelInboundHandlerAdapter
{
private
final
Promise
<
Channel
>
promise
;
public
DirectClientHandler
(
Promise
<
Channel
>
promise
)
{
this
.
promise
=
promise
;
}
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
{
ctx
.
pipeline
().
remove
(
this
);
promise
.
setSuccess
(
ctx
.
channel
());
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
throwable
)
{
promise
.
setFailure
(
throwable
);
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/RelayHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.socksproxy
;
import
io.netty.buffer.Unpooled
;
import
io.netty.channel.Channel
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelInboundHandlerAdapter
;
import
io.netty.util.ReferenceCountUtil
;
public
final
class
RelayHandler
extends
ChannelInboundHandlerAdapter
{
private
final
Channel
relayChannel
;
public
RelayHandler
(
Channel
relayChannel
)
{
this
.
relayChannel
=
relayChannel
;
}
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
{
ctx
.
writeAndFlush
(
Unpooled
.
EMPTY_BUFFER
);
}
@Override
public
void
channelRead
(
ChannelHandlerContext
ctx
,
Object
msg
)
{
if
(
relayChannel
.
isActive
())
{
relayChannel
.
writeAndFlush
(
msg
);
}
else
{
ReferenceCountUtil
.
release
(
msg
);
}
}
@Override
public
void
channelInactive
(
ChannelHandlerContext
ctx
)
{
if
(
relayChannel
.
isActive
())
{
SocksServerUtils
.
closeOnFlush
(
relayChannel
);
}
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
cause
.
printStackTrace
();
ctx
.
close
();
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServer.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.socksproxy
;
import
io.netty.bootstrap.ServerBootstrap
;
import
io.netty.channel.EventLoopGroup
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.channel.socket.nio.NioServerSocketChannel
;
import
io.netty.handler.logging.LogLevel
;
import
io.netty.handler.logging.LoggingHandler
;
public
final
class
SocksServer
{
static
final
int
PORT
=
Integer
.
parseInt
(
System
.
getProperty
(
"port"
,
"1080"
));
public
static
void
main
(
String
[]
args
)
throws
Exception
{
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
(
1
);
EventLoopGroup
workerGroup
=
new
NioEventLoopGroup
();
try
{
ServerBootstrap
b
=
new
ServerBootstrap
();
b
.
group
(
bossGroup
,
workerGroup
)
.
channel
(
NioServerSocketChannel
.
class
)
.
handler
(
new
LoggingHandler
(
LogLevel
.
INFO
))
.
childHandler
(
new
SocksServerInitializer
());
b
.
bind
(
PORT
).
sync
().
channel
().
closeFuture
().
sync
();
}
finally
{
bossGroup
.
shutdownGracefully
();
workerGroup
.
shutdownGracefully
();
}
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerConnectHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.socksproxy
;
import
io.netty.bootstrap.Bootstrap
;
import
io.netty.channel.*
;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
io.netty.handler.codec.socksx.SocksMessage
;
import
io.netty.handler.codec.socksx.v4.DefaultSocks4CommandResponse
;
import
io.netty.handler.codec.socksx.v4.Socks4CommandRequest
;
import
io.netty.handler.codec.socksx.v4.Socks4CommandStatus
;
import
io.netty.handler.codec.socksx.v5.DefaultSocks5CommandResponse
;
import
io.netty.handler.codec.socksx.v5.Socks5CommandRequest
;
import
io.netty.handler.codec.socksx.v5.Socks5CommandStatus
;
import
io.netty.util.concurrent.Future
;
import
io.netty.util.concurrent.FutureListener
;
import
io.netty.util.concurrent.Promise
;
@ChannelHandler
.
Sharable
public
final
class
SocksServerConnectHandler
extends
SimpleChannelInboundHandler
<
SocksMessage
>
{
private
final
Bootstrap
b
=
new
Bootstrap
();
@Override
public
void
channelRead0
(
final
ChannelHandlerContext
ctx
,
final
SocksMessage
message
)
throws
Exception
{
if
(
message
instanceof
Socks4CommandRequest
)
{
final
Socks4CommandRequest
request
=
(
Socks4CommandRequest
)
message
;
Promise
<
Channel
>
promise
=
ctx
.
executor
().
newPromise
();
promise
.
addListener
(
new
FutureListener
<
Channel
>()
{
@Override
public
void
operationComplete
(
final
Future
<
Channel
>
future
)
throws
Exception
{
final
Channel
outboundChannel
=
future
.
getNow
();
if
(
future
.
isSuccess
())
{
ChannelFuture
responseFuture
=
ctx
.
channel
().
writeAndFlush
(
new
DefaultSocks4CommandResponse
(
Socks4CommandStatus
.
SUCCESS
));
responseFuture
.
addListener
(
new
ChannelFutureListener
()
{
@Override
public
void
operationComplete
(
ChannelFuture
channelFuture
)
{
ctx
.
pipeline
().
remove
(
SocksServerConnectHandler
.
this
);
outboundChannel
.
pipeline
().
addLast
(
new
RelayHandler
(
ctx
.
channel
()));
ctx
.
pipeline
().
addLast
(
new
RelayHandler
(
outboundChannel
));
}
});
}
else
{
ctx
.
channel
().
writeAndFlush
(
new
DefaultSocks4CommandResponse
(
Socks4CommandStatus
.
REJECTED_OR_FAILED
));
SocksServerUtils
.
closeOnFlush
(
ctx
.
channel
());
}
}
});
final
Channel
inboundChannel
=
ctx
.
channel
();
b
.
group
(
inboundChannel
.
eventLoop
())
.
channel
(
NioSocketChannel
.
class
)
.
option
(
ChannelOption
.
CONNECT_TIMEOUT_MILLIS
,
10000
)
.
option
(
ChannelOption
.
SO_KEEPALIVE
,
true
)
.
handler
(
new
DirectClientHandler
(
promise
));
b
.
connect
(
request
.
dstAddr
(),
request
.
dstPort
()).
addListener
(
new
ChannelFutureListener
()
{
@Override
public
void
operationComplete
(
ChannelFuture
future
)
throws
Exception
{
if
(
future
.
isSuccess
())
{
// Connection established use handler provided results
}
else
{
// Close the connection if the connection attempt has failed.
ctx
.
channel
().
writeAndFlush
(
new
DefaultSocks4CommandResponse
(
Socks4CommandStatus
.
REJECTED_OR_FAILED
)
);
SocksServerUtils
.
closeOnFlush
(
ctx
.
channel
());
}
}
});
}
else
if
(
message
instanceof
Socks5CommandRequest
)
{
final
Socks5CommandRequest
request
=
(
Socks5CommandRequest
)
message
;
Promise
<
Channel
>
promise
=
ctx
.
executor
().
newPromise
();
promise
.
addListener
(
new
FutureListener
<
Channel
>()
{
@Override
public
void
operationComplete
(
final
Future
<
Channel
>
future
)
throws
Exception
{
final
Channel
outboundChannel
=
future
.
getNow
();
if
(
future
.
isSuccess
())
{
ChannelFuture
responseFuture
=
ctx
.
channel
().
writeAndFlush
(
new
DefaultSocks5CommandResponse
(
Socks5CommandStatus
.
SUCCESS
,
request
.
dstAddrType
(),
request
.
dstAddr
(),
request
.
dstPort
()));
responseFuture
.
addListener
(
new
ChannelFutureListener
()
{
@Override
public
void
operationComplete
(
ChannelFuture
channelFuture
)
{
ctx
.
pipeline
().
remove
(
SocksServerConnectHandler
.
this
);
outboundChannel
.
pipeline
().
addLast
(
new
RelayHandler
(
ctx
.
channel
()));
ctx
.
pipeline
().
addLast
(
new
RelayHandler
(
outboundChannel
));
}
});
}
else
{
ctx
.
channel
().
writeAndFlush
(
new
DefaultSocks5CommandResponse
(
Socks5CommandStatus
.
FAILURE
,
request
.
dstAddrType
()));
SocksServerUtils
.
closeOnFlush
(
ctx
.
channel
());
}
}
});
final
Channel
inboundChannel
=
ctx
.
channel
();
b
.
group
(
inboundChannel
.
eventLoop
())
.
channel
(
NioSocketChannel
.
class
)
.
option
(
ChannelOption
.
CONNECT_TIMEOUT_MILLIS
,
10000
)
.
option
(
ChannelOption
.
SO_KEEPALIVE
,
true
)
.
handler
(
new
DirectClientHandler
(
promise
));
b
.
connect
(
request
.
dstAddr
(),
request
.
dstPort
()).
addListener
(
new
ChannelFutureListener
()
{
@Override
public
void
operationComplete
(
ChannelFuture
future
)
throws
Exception
{
if
(
future
.
isSuccess
())
{
// Connection established use handler provided results
}
else
{
// Close the connection if the connection attempt has failed.
ctx
.
channel
().
writeAndFlush
(
new
DefaultSocks5CommandResponse
(
Socks5CommandStatus
.
FAILURE
,
request
.
dstAddrType
()));
SocksServerUtils
.
closeOnFlush
(
ctx
.
channel
());
}
}
});
}
else
{
ctx
.
close
();
}
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
throws
Exception
{
SocksServerUtils
.
closeOnFlush
(
ctx
.
channel
());
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerHandler.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.socksproxy
;
import
io.netty.channel.ChannelHandler
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
io.netty.handler.codec.socksx.SocksMessage
;
import
io.netty.handler.codec.socksx.v4.Socks4CommandRequest
;
import
io.netty.handler.codec.socksx.v4.Socks4CommandType
;
import
io.netty.handler.codec.socksx.v5.*
;
@ChannelHandler
.
Sharable
public
final
class
SocksServerHandler
extends
SimpleChannelInboundHandler
<
SocksMessage
>
{
public
static
final
SocksServerHandler
INSTANCE
=
new
SocksServerHandler
();
private
SocksServerHandler
()
{
}
@Override
public
void
channelRead0
(
ChannelHandlerContext
ctx
,
SocksMessage
socksRequest
)
throws
Exception
{
switch
(
socksRequest
.
version
())
{
case
SOCKS4a:
Socks4CommandRequest
socksV4CmdRequest
=
(
Socks4CommandRequest
)
socksRequest
;
if
(
socksV4CmdRequest
.
type
()
==
Socks4CommandType
.
CONNECT
)
{
ctx
.
pipeline
().
addLast
(
new
SocksServerConnectHandler
());
ctx
.
pipeline
().
remove
(
this
);
ctx
.
fireChannelRead
(
socksRequest
);
}
else
{
ctx
.
close
();
}
break
;
case
SOCKS5:
if
(
socksRequest
instanceof
Socks5InitialRequest
)
{
// auth support example
//ctx.pipeline().addFirst(new Socks5PasswordAuthRequestDecoder());
//ctx.write(new DefaultSocks5AuthMethodResponse(Socks5AuthMethod.PASSWORD));
ctx
.
pipeline
().
addFirst
(
new
Socks5CommandRequestDecoder
());
ctx
.
write
(
new
DefaultSocks5InitialResponse
(
Socks5AuthMethod
.
NO_AUTH
));
}
else
if
(
socksRequest
instanceof
Socks5PasswordAuthRequest
)
{
ctx
.
pipeline
().
addFirst
(
new
Socks5CommandRequestDecoder
());
ctx
.
write
(
new
DefaultSocks5PasswordAuthResponse
(
Socks5PasswordAuthStatus
.
SUCCESS
));
}
else
if
(
socksRequest
instanceof
Socks5CommandRequest
)
{
Socks5CommandRequest
socks5CmdRequest
=
(
Socks5CommandRequest
)
socksRequest
;
if
(
socks5CmdRequest
.
type
()
==
Socks5CommandType
.
CONNECT
)
{
ctx
.
pipeline
().
addLast
(
new
SocksServerConnectHandler
());
ctx
.
pipeline
().
remove
(
this
);
ctx
.
fireChannelRead
(
socksRequest
);
}
else
{
ctx
.
close
();
}
}
else
{
ctx
.
close
();
}
break
;
case
UNKNOWN:
ctx
.
close
();
break
;
}
}
@Override
public
void
channelReadComplete
(
ChannelHandlerContext
ctx
)
{
ctx
.
flush
();
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
throwable
)
{
throwable
.
printStackTrace
();
SocksServerUtils
.
closeOnFlush
(
ctx
.
channel
());
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerInitializer.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.socksproxy
;
import
io.netty.channel.ChannelInitializer
;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.handler.codec.socksx.SocksPortUnificationServerHandler
;
import
io.netty.handler.logging.LogLevel
;
import
io.netty.handler.logging.LoggingHandler
;
public
final
class
SocksServerInitializer
extends
ChannelInitializer
<
SocketChannel
>
{
@Override
public
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
ch
.
pipeline
().
addLast
(
new
LoggingHandler
(
LogLevel
.
DEBUG
),
new
SocksPortUnificationServerHandler
(),
SocksServerHandler
.
INSTANCE
);
}
}
whatsmars-rpc/whatsmars-netty/src/main/java/org/hongxi/whatsmars/netty/socksproxy/SocksServerUtils.java
已删除
100755 → 0
浏览文件 @
288f02b0
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package
org.hongxi.whatsmars.netty.socksproxy
;
import
io.netty.buffer.Unpooled
;
import
io.netty.channel.Channel
;
import
io.netty.channel.ChannelFutureListener
;
public
final
class
SocksServerUtils
{
/**
* Closes the specified channel after all queued write requests are flushed.
*/
public
static
void
closeOnFlush
(
Channel
ch
)
{
if
(
ch
.
isActive
())
{
ch
.
writeAndFlush
(
Unpooled
.
EMPTY_BUFFER
).
addListener
(
ChannelFutureListener
.
CLOSE
);
}
}
private
SocksServerUtils
()
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录