fix(share): carry the transport in the share and assign payloads
The share payload was host:port:shine and carried no transport at all, so a
shared client fell back to its baked-in protoType. Share instances also skip
ApplyProtoSwitch (ClientDll.cpp:810), so a client upgraded to WSS was shared
to a TLS front end as raw TCP and looped on HTTP/1.1 400.
Extend both payloads with an optional trailing transport field:
share : host:port:shine[:transport]
assign : host:port:days:shine[:transport]
The field is omitted when the source protocol is not TCP/WS/WSS, so HTTP/UDP/
KCP hosts keep their previous behaviour instead of being silently downgraded
to plain TCP.
- server: add SelectedShareTransport(), share it between OnOnlineShare and
OnOnlineAssignTo, and accept a tcp:// ws:// wss:// prefix in the address.
- client: parse the field on both paths and persist the assigned value to
settings/master_transport, clearing it when the field is absent.
- share_list: dedup on host:port instead of the whole record, so re-sharing
a host with a different transport replaces the stale entry.
- assign: guard bToken[_MAX_PATH] against the longer payload.
- lang: translate the reworded prompt and the three new messages in en_US,
zh_TW and de_DE.
Transport is pinned at share time and does not follow a later protocol switch
on the master link; the m_bShared gate stays as-is on purpose.
This commit is contained in:
1 parent
951b4072e5
commit
454d25d37f
10 files changed
+266
-22
No files matched your search
@@ -1238,12 +1238,32 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
if (ulLength > 2) {
|
||||
// 解析末尾协议段(Shine=0 / HELL=1,旧命令无此段则 -1 沿用烘焙值)
|
||||
int shareProto = -1;
|
||||
// 分享链路的传输方式(PROTO_TCP / PROTO_WS / PROTO_WSS)。旧服务端不带这
|
||||
// 一段,保持 -1 = 沿用出包时烘焙的传输,与改造前完全一致。
|
||||
int shareTransport = -1;
|
||||
{
|
||||
auto pv = StringToVector((char*)szBuffer + 2, ':', 5);
|
||||
if (szBuffer[1] == SHARE_TYPE_YAMA && pv.size() >= 3 && (pv[2] == "0" || pv[2] == "1"))
|
||||
shareProto = atoi(pv[2].c_str());
|
||||
else if (szBuffer[1] == SHARE_TYPE_YAMA_FOREVER && pv.size() >= 4 && (pv[3] == "0" || pv[3] == "1"))
|
||||
shareProto = atoi(pv[3].c_str());
|
||||
if (szBuffer[1] == SHARE_TYPE_YAMA) {
|
||||
if (pv.size() >= 3 && (pv[2] == "0" || pv[2] == "1"))
|
||||
shareProto = atoi(pv[2].c_str());
|
||||
// 传输段固定跟在 Shine 段之后(第 4 段)。只认三个合法值:atoi 对非法
|
||||
// 串返回 0(正是 PROTO_TCP),不校验就会把脏数据当成「直连」,把一条
|
||||
// 本该走 WSS 的链路静默降级。
|
||||
if (pv.size() >= 4 && (pv[3] == std::to_string(PROTO_TCP)
|
||||
|| pv[3] == std::to_string(PROTO_WS)
|
||||
|| pv[3] == std::to_string(PROTO_WSS)))
|
||||
shareTransport = atoi(pv[3].c_str());
|
||||
}
|
||||
else if (szBuffer[1] == SHARE_TYPE_YAMA_FOREVER) {
|
||||
// 转移的载荷是 host:port:days:shine[:transport],Shine 在 pv[3],
|
||||
// 传输在 pv[4](与分享的 pv[2]/pv[3] 差一位)。
|
||||
if (pv.size() >= 4 && (pv[3] == "0" || pv[3] == "1"))
|
||||
shareProto = atoi(pv[3].c_str());
|
||||
if (pv.size() >= 5 && (pv[4] == std::to_string(PROTO_TCP)
|
||||
|| pv[4] == std::to_string(PROTO_WS)
|
||||
|| pv[4] == std::to_string(PROTO_WSS)))
|
||||
shareTransport = atoi(pv[4].c_str());
|
||||
}
|
||||
}
|
||||
switch (szBuffer[1]) {
|
||||
case SHARE_TYPE_YAMA_FOREVER: {
|
||||
@@ -1257,6 +1277,12 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
m_cfg->SetStr("settings", "port", v[1]);
|
||||
if (shareProto == PROTOCOL_SHINE || shareProto == PROTOCOL_HELL)
|
||||
m_cfg->SetStr("settings", "master_proto", std::to_string(shareProto));
|
||||
// 转移目标链路的传输方式(新服务端才下发)。没带这一段就清空,否则会
|
||||
// 沿用上一次转移留下的值,把一条本该直连的链路继续按 WSS 去连。
|
||||
if (shareTransport >= 0)
|
||||
m_cfg->SetStr("settings", "master_transport", std::to_string(shareTransport));
|
||||
else
|
||||
m_cfg->SetStr("settings", "master_transport", "");
|
||||
float days = atof(v[2].c_str());
|
||||
if (days > 0) {
|
||||
auto valid_to = time(0) + days*86400;
|
||||
@@ -1277,14 +1303,34 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
auto share = v[0] + ":" + v[1];
|
||||
if (shareProto == PROTOCOL_SHINE || shareProto == PROTOCOL_HELL)
|
||||
share += ":" + std::to_string(shareProto);
|
||||
// 传输段必须排在 Shine 段之后:share_list 的第 3 段是 Shine,没写
|
||||
// Shine 就把传输塞进第 3 段,重启后会被当成 Shine 解析。
|
||||
if (shareTransport >= 0 && (shareProto == PROTOCOL_SHINE || shareProto == PROTOCOL_HELL))
|
||||
share += ":" + std::to_string(shareTransport);
|
||||
auto list = m_cfg->GetStr("settings", "share_list");
|
||||
auto shareList = list.empty() ? std::vector<std::string>{} : StringToVector(list, '|');
|
||||
if (VectorContains(shareList, share)) break;
|
||||
// 去重按 host:port 比,不按整条记录比。同一条分享目标换了传输方式
|
||||
// (出包烘焙的 TCP → 重新分享成 WSS)时第 3/4 段会变,整条比会把它
|
||||
// 判成「新条目」,于是同一目标留下两条记录 → 同一 clientID 起两个分享
|
||||
// 实例,登录时互相踢。老记录(3 段、没有传输段)也在这一步被替换。
|
||||
const std::string shareKey = v[0] + ":" + v[1];
|
||||
bool identical = false;
|
||||
for (size_t k = 0; k < shareList.size(); ++k) {
|
||||
auto ev = StringToVector(shareList[k], ':', 2);
|
||||
if (ev[0] + ":" + ev[1] == shareKey && shareList[k] == share)
|
||||
identical = true;
|
||||
}
|
||||
if (identical) break; // 同样的记录已在分享,重复命令不再起一个实例
|
||||
for (size_t k = 0; k < shareList.size(); ) {
|
||||
auto ev = StringToVector(shareList[k], ':', 2);
|
||||
if (ev[0] + ":" + ev[1] == shareKey) shareList.erase(shareList.begin() + k);
|
||||
else ++k;
|
||||
}
|
||||
shareList.push_back(share);
|
||||
m_cfg->SetStr("settings", "share_list", VectorJoin(shareList, '|'));
|
||||
Mprintf("Share client to new master: %s\n", share.c_str());
|
||||
}
|
||||
auto a = NewClientStartArg((char*)szBuffer + 2, IsSharedRunning, TRUE, shareProto);
|
||||
auto a = NewClientStartArg((char*)szBuffer + 2, IsSharedRunning, TRUE, shareProto, shareTransport);
|
||||
if (nullptr!=a) CloseHandle(__CreateThread(0, 0, StartClientApp, a, 0, 0));
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user