Skip to content

Commit

Permalink
增加超时时间
Browse files Browse the repository at this point in the history
  • Loading branch information
takayama-lily committed Jun 4, 2021
1 parent d521bcb commit 9b1ee69
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/client-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Client.prototype.nextSeq = function() {
/**
* 发送一个包并返回响应包
*/
Client.prototype.send = function (packet, timeout = 5000) {
Client.prototype.send = function (packet, timeout = 5) {
++this.stat.sent_pkt_cnt;
const seq_id = this.seq_id;
return new Promise((resolve, reject) => {
Expand All @@ -33,7 +33,7 @@ Client.prototype.send = function (packet, timeout = 5000) {
++this.stat.lost_pkt_cnt;
reject(new TimeoutError());
this.emit("internal.timeout", { seq_id, packet });
}, timeout);
}, timeout * 1000);
this.handlers.set(seq_id, (data) => {
clearTimeout(id);
this.handlers.delete(seq_id);
Expand All @@ -56,8 +56,8 @@ Client.prototype.writeUni = function (cmd, body, seq = 0) {
/**
* 发送一个uni包并返回响应包
*/
Client.prototype.sendUni = function (cmd, body) {
return this.send(this._buildUniPacket(cmd, body));
Client.prototype.sendUni = function (cmd, body, timeout = 5) {
return this.send(this._buildUniPacket(cmd, body), timeout);
};

/**
Expand Down
9 changes: 9 additions & 0 deletions lib/client-net.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,12 @@ class Network extends net.Socket {
}

module.exports = Network;

/**
* 关于探索服务器:
* 由于tx服务器偶尔会抽风,若固定使用域名msfwifi.3g.qq.com连接,遇到抽风的IP会炸
* 探索服务器每次获得3个理论最优IP,一小时内只进行一次探索,除非IP已经用完
* 在连接后5分钟内若出现断线,则判断此IP抽风,将其排除
* 5分钟之外的断线则正常重连
* 同一线程中的所有客户端实例共用一个IP池
*/
6 changes: 3 additions & 3 deletions lib/core/friendlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function _initFL(start, limit, tmp) {
method: "GetFriendListReq",
};
const body = jce.encodeWrapper({ FL }, extra);
const blob = await this.sendUni("friendlist.getFriendGroupList", body);
const blob = await this.sendUni("friendlist.getFriendGroupList", body, 10);
const nested = jce.decode(blob);
for (let v of nested[7]) {
let age = 0, area = "unknown";
Expand Down Expand Up @@ -107,7 +107,7 @@ async function initGL() {
};
const body = jce.encodeWrapper({ GetTroopListReqV2Simplify }, extra);
try {
const blob = await this.sendUni("friendlist.GetTroopListReqV2", body);
const blob = await this.sendUni("friendlist.GetTroopListReqV2", body, 10);
const nested = jce.decode(blob);
const tmp = this.gl;
if (this.gl.size < 999)
Expand Down Expand Up @@ -154,7 +154,7 @@ async function __getGML(group_id, next_uin) {
method: "GetTroopMemberListReq",
};
const body = jce.encodeWrapper({ GTML }, extra);
const blob = await this.sendUni("friendlist.GetTroopMemberListReq", body);
const blob = await this.sendUni("friendlist.GetTroopMemberListReq", body, 10);
const nested = jce.decode(blob);
const map = new Map(), next = nested[4];
for (let v of nested[3]) {
Expand Down
4 changes: 2 additions & 2 deletions lib/oicq.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function kickoffListener(data) {
if (data.info.includes("如非本人操作")) {
sub_type = "kickoff";
if (this.config.kickoff) {
this.logger.warn("3秒后重新连接..");
this.logger.mark("3秒后重新连接..");
setTimeout(this.login.bind(this), 3000);
} else {
this.terminate();
Expand All @@ -144,7 +144,7 @@ function kickoffListener(data) {
this.terminate();
} else {
sub_type = "unknown";
this.logger.warn("3秒后重新连接..");
this.logger.mark("3秒后重新连接..");
setTimeout(this.login.bind(this), 3000);
}
this.em("system.offline." + sub_type, { message: data.info });
Expand Down

0 comments on commit 9b1ee69

Please sign in to comment.