📄 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;
import java.io.IOException;
import java.net.InetSocketAddress;
import edu.tsinghua.lumaqq.LumaQQ;
/**
* <pre>
* 代理验证器,完成验证任务的功能包装
* </pre>
*
* @author 马若劼
*/
public class ProxyVerifier {
/** Porter对象 */
private Porter porter;
/** 代理服务器 */
private IProxy proxy;
/**
* 构造函数
* @param handler 代理事件处理器
* @param proxyAddress 代理服务器地址
* @param type 代理服务器类型,可以为Socks5或者Http
* @param udp 协议,只对Socks5代理有效
*/
public ProxyVerifier(IProxyHandler handler, InetSocketAddress proxyAddress, String type, boolean udp) {
this(handler, proxyAddress, type, udp, null, null);
}
/**
* 构造函数
* @param handler 代理事件处理器
* @param proxyAddress 代理服务器地址
* @param type 代理服务器类型,可以为Socks5或者Http
* @param udp 协议,只对Socks5代理有效
* @param u 用户名
* @param p 密码
*/
public ProxyVerifier(IProxyHandler handler, InetSocketAddress proxyAddress, String type, boolean udp, String u, String p) {
// 创建porter
porter = new Porter();
// 创建proxy,对于不支持的代理类型,直接抛出验证失败
if(type.equalsIgnoreCase("Socks5")) {
// 得到一个随机服务器
InetSocketAddress serverAddress;
if(udp) {
String server = LumaQQ.udpServers[Utils.random().nextInt(LumaQQ.udpServers.length - 1)];
serverAddress = new InetSocketAddress(server, QQ.QQ_UDP_PORT);
} else {
String server = LumaQQ.tcpServers[Utils.random().nextInt(LumaQQ.tcpServers.length - 1)];
serverAddress = new InetSocketAddress(server, QQ.QQ_TCP_PORT);
}
// 创建代理类
proxy = new Socks5Proxy(porter, handler, u, p);
proxy.setClientPort(5678);
proxy.setProxyAddress(proxyAddress);
proxy.setServerAddress(serverAddress);
proxy.setUdp(udp);
} else if(type.equalsIgnoreCase("Http")) {
// 得到一个随机服务器
String server = LumaQQ.tcpServers[Utils.random().nextInt(LumaQQ.tcpServers.length - 1)];
InetSocketAddress serverAddress = new InetSocketAddress(server, QQ.QQ_HTTP_PORT);
proxy = new HttpProxy(porter, handler, u, p);
proxy.setProxyAddress(proxyAddress);
proxy.setServerAddress(serverAddress);
} else
handler.proxyAuthFail();
}
/**
* 启动验证
*/
public void start() {
proxy.start();
porter.start();
}
/**
* 释放资源
* @throws IOException
*/
public void dispose() throws IOException {
porter.shutdown();
proxy.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -