本文整理汇总了Java中io.netty.handler.codec.socks.SocksCmdRequest类的典型用法代码示例。如果您正苦于以下问题:Java SocksCmdRequest类的具体用法?Java SocksCmdRequest怎么用?Java SocksCmdRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocksCmdRequest类属于io.netty.handler.codec.socks包,在下文中一共展示了SocksCmdRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEncodedTargetAddress
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
private ByteBuf getEncodedTargetAddress(ByteBufAllocator allocator, boolean resolve) throws ProxyConnectException {
InetSocketAddress remoteAddress = destinationAddress();
SocksAddressType remoteAddressType;
String remoteHost;
if (!resolve || remoteAddress.isUnresolved()) {
remoteAddressType = SocksAddressType.DOMAIN;
remoteHost = remoteAddress.getHostString();
} else {
remoteHost = remoteAddress.getAddress().getHostAddress();
if (NetUtil.isValidIpV4Address(remoteHost)) {
remoteAddressType = SocksAddressType.IPv4;
} else if (NetUtil.isValidIpV6Address(remoteHost)) {
remoteAddressType = SocksAddressType.IPv6;
} else {
throw new ProxyConnectException("unknown address type: " + StringUtil.simpleClassName(remoteHost));
}
}
int remotePort = remoteAddress.getPort();
SocksCmdRequest request = new SocksCmdRequest(SocksCmdType.UNKNOWN, remoteAddressType, remoteHost, remotePort);
return SSocksAddressEncoder.INSTANCE.encode(allocator, request);
}
示例2: encode
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
public ByteBuf encode(ByteBufAllocator allocator, SocksCmdRequest msg) {
if (LOG.isTraceEnabled()) {
LOG.trace("encode target address");
}
ByteBuf buf = allocator.directBuffer();
msg.encodeAsByteBuf(buf);
buf.skipBytes(3);
if (LOG.isTraceEnabled()) {
byte[] bytes = new byte[buf.readableBytes()];
buf.getBytes(buf.readerIndex(), bytes);
}
return buf;
}
示例3: getIpAddr
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
/**
* 获取远程ip地址
* @param request
* @return
*/
private String getIpAddr(SocksCmdRequest request) {
if(isProxy) {
return config.get_ipAddr();
} else {
return request.host();
}
}
示例4: getPort
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
/**
* 获取远程端口
* @param request
* @return
*/
private int getPort(SocksCmdRequest request) {
if(isProxy) {
return config.get_port();
} else {
return request.port();
}
}
示例5: sendConnectRemoteMessage
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
/**
* localserver和remoteserver进行connect发送的数据
*
* @param request
* @param outboundChannel
*/
private void sendConnectRemoteMessage(SocksCmdRequest request,
Channel outboundChannel) {
ByteBuf buff = Unpooled.buffer();
request.encodeAsByteBuf(buff);
if (buff.hasArray()) {
int len = buff.readableBytes();
byte[] arr = new byte[len];
buff.getBytes(0, arr);
byte[] data = remoteByte(arr);
sendRemote(data, data.length, outboundChannel);
}
}
示例6: channelRead0
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx,
SocksRequest socksRequest) throws Exception {
switch (socksRequest.requestType()) {
case INIT: {
logger.info("localserver init");
ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
break;
}
case AUTH:
ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
break;
case CMD:
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
if (req.cmdType() == SocksCmdType.CONNECT) {
logger.info("localserver connect");
ctx.pipeline().addLast(new SocksServerConnectHandler(config));
ctx.pipeline().remove(this);
ctx.fireChannelRead(socksRequest);
} else {
ctx.close();
}
break;
case UNKNOWN:
ctx.close();
break;
}
}
示例7: channelRead0
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx,
SocksRequest socksRequest) throws Exception {
switch (socksRequest.requestType()) {
case INIT: {
ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
break;
}
case AUTH:
ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
break;
case CMD:
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
if (req.cmdType() == SocksCmdType.CONNECT) {
ctx.pipeline().addLast(new ShadowsocksServerConnectHandler());
ctx.pipeline().remove(this);
ctx.fireChannelRead(socksRequest);
} else {
ctx.close();
}
break;
case UNKNOWN:
ctx.close();
break;
}
}
示例8: encode
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, SocksCmdRequest msg,
ByteBuf out) throws Exception {
msg.encodeAsByteBuf(out);
out.skipBytes(3); // Simply skip first 3 bytes
ctx.pipeline().remove(this);
}
示例9: channelRead0
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
switch (socksRequest.requestType()) {
case INIT: {
// auth support example
//ctx.pipeline().addFirst(new SocksAuthRequestDecoder());
//ctx.write(new SocksInitResponse(SocksAuthScheme.AUTH_PASSWORD));
ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
break;
}
case AUTH:
ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
break;
case CMD:
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
if (req.cmdType() == SocksCmdType.CONNECT) {
ctx.pipeline().addLast(new SocksServerConnectHandler());
ctx.pipeline().remove(this);
ctx.fireChannelRead(socksRequest);
} else {
ctx.close();
}
break;
case UNKNOWN:
ctx.close();
break;
}
}
示例10: channelRead0
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
switch (socksRequest.requestType()) {
case INIT: {
// auth support example
// ctx.pipeline().addFirst("socksAuthRequestDecoder",new SocksAuthRequestDecoder());
// ctx.write(new SocksInitResponse(SocksMessage.SocksAuthScheme.AUTH_PASSWORD));
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
break;
}
case AUTH:
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
break;
case CMD:
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
if (req.cmdType() == SocksCmdType.CONNECT) {
ctx.pipeline().addLast(SocksServerConnectHandler.getName(), new SocksServerConnectHandler());
ctx.pipeline().remove(this);
ctx.fireChannelRead(socksRequest);
} else {
ctx.close();
}
break;
case UNKNOWN:
ctx.close();
break;
}
}
示例11: messageReceived
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
switch (socksRequest.requestType()) {
case INIT: {
// auth support example
// ctx.pipeline().addFirst("socksAuthRequestDecoder",new SocksAuthRequestDecoder());
// ctx.write(new SocksInitResponse(SocksMessage.SocksAuthScheme.AUTH_PASSWORD));
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
break;
}
case AUTH:
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
break;
case CMD:
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
if (req.cmdType() == SocksCmdType.CONNECT) {
ctx.pipeline().addLast(SocksServerConnectHandler.getName(), new SocksServerConnectHandler());
ctx.pipeline().remove(this);
ctx.fireChannelRead(socksRequest);
} else {
ctx.close();
}
break;
case UNKNOWN:
ctx.close();
break;
}
}
示例12: prepare
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
private ChannelHandlerContext prepare(final ChannelHandlerContext ctx, Object msg, ChannelFuture future) throws IOException {
if (msg.getClass() == SocksCmdRequest.class) {
SocksCmdRequest cmd = SocksCmdRequest.class.cast(msg);
return Socks5ProxyServerHandlerBuilder.this.exchangerContext.exists(cmd.host()) ? this.activate(Socks5ProxyServerHandlerBuilder.this.exchangerContext.activate(cmd.host()), future, ctx) : this.wait(cmd, ctx);
}
return ctx;
}
示例13: getSuccessResponse
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
private SocksCmdResponse getSuccessResponse(SocksCmdRequest request) {
return new SocksCmdResponse(SocksCmdStatus.SUCCESS,
request.addressType());
}
示例14: getFailureResponse
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
private SocksCmdResponse getFailureResponse(SocksCmdRequest request) {
return new SocksCmdResponse(SocksCmdStatus.FAILURE,
request.addressType());
}
示例15: wait
import io.netty.handler.codec.socks.SocksCmdRequest; //导入依赖的package包/类
/**
* 禁止关闭接收方,cascade = false
*
* @param cmd
* @param ctx
* @return
* @throws IOException
*/
private ChannelHandlerContext wait(SocksCmdRequest cmd, ChannelHandlerContext ctx) throws IOException {
ctx.attr(Socks5ProxyServerHandlerBuilder.this.exchanger).set(Socks5ProxyServerHandlerBuilder.this.exchangerContext.wait(cmd.host(), false, new NetworkTransfer(ctx)));
return ctx;
}