📄 proxyverifier.java
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.qq.net;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.DatagramChannel;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Util;
/**
* <pre>
* 代理验证器,完成验证任务的功能包装
* </pre>
*
* @author 马若劼
*/
public class ProxyVerifier {
/** Porter对象 */
private Porter porter;
/** 代理服务器 */
private IProxy proxy;
/** true表示我们需要关闭porter */
private boolean disposePorter;
/**
* 构造函数
* @param handler 代理事件处理器
* @param proxyAddress 代理服务器地址
* @param type 代理服务器类型,可以为Socks5或者Http
* @param udp 协议,只对Socks5代理有效
* @param u 用户名
* @param p 密码
* @throws IOException
*/
public ProxyVerifier(Porter p, IProxyHandler handler, InetSocketAddress proxyAddress, String type, boolean udp, String user, String pass) throws IOException {
// 创建porter
disposePorter = false;
porter = p;
if(porter == null) {
porter = new Porter();
disposePorter = true;
}
// 创建proxy,对于不支持的代理类型,直接抛出验证失败
if(type.equalsIgnoreCase("Socks5")) {
// 得到一个随机服务器
InetSocketAddress serverAddress;
if(udp) {
String server = LumaQQ.udpServers[Util.random().nextInt(LumaQQ.udpServers.length)];
serverAddress = new InetSocketAddress(server, QQ.QQ_UDP_PORT);
} else {
String server = LumaQQ.tcpServers[Util.random().nextInt(LumaQQ.tcpServers.length)];
serverAddress = new InetSocketAddress(server, QQ.QQ_TCP_PORT);
}
// 创建代理类
if(udp) {
DatagramChannel dc = DatagramChannel.open();
dc.configureBlocking(false);
proxy = new Socks5Proxy(porter, handler, user, pass, dc);
} else
proxy = new Socks5Proxy(porter, handler, user, pass);
proxy.setClientPort(5678);
proxy.setProxyAddress(proxyAddress);
proxy.setRemoteAddress(serverAddress);
porter.wakeup(proxy);
} else if(type.equalsIgnoreCase("Http")) {
// 得到一个随机服务器
String server = LumaQQ.tcpServers[Util.random().nextInt(LumaQQ.tcpServers.length - 1)];
InetSocketAddress serverAddress = new InetSocketAddress(server, QQ.QQ_HTTP_PORT);
proxy = new HttpProxy(porter, handler, user, pass);
proxy.setProxyAddress(proxyAddress);
proxy.setRemoteAddress(serverAddress);
porter.wakeup(proxy);
} else
handler.proxyAuthFail();
}
/**
* 启动验证
*/
public void start() {
if(disposePorter)
porter.start();
proxy.start();
}
/**
* 释放资源
* @throws IOException
*/
public void dispose() throws IOException {
porter.deregister(proxy);
if(disposePorter)
porter.shutdown();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -