Avoid using obsolete DataCenter info on alt-DC connect

This commit is contained in:
Wizou 2025-08-09 02:43:43 +02:00
parent 7faa3873f8
commit e16e39bfba
3 changed files with 17 additions and 7 deletions

View file

@ -46,7 +46,7 @@ jobs:
env: env:
JSON: | JSON: |
{ {
"status": "success", "complete": true, "commitMessage": ${{ toJSON(github.event.head_commit.message) }}, "status": "success", "complete": true, "commitMessage": ${{ toJSON(env.RELEASE_NOTES) }},
"message": "{ \"commitId\": \"${{ github.sha }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"repoName\": \"${{ github.repository }}\"}" "message": "{ \"commitId\": \"${{ github.sha }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"repoName\": \"${{ github.repository }}\"}"
} }
run: | run: |

View file

@ -58,7 +58,7 @@ jobs:
env: env:
JSON: | JSON: |
{ {
"status": "success", "complete": true, "commitMessage": ${{ toJSON(github.event.head_commit.message) }}, "status": "success", "complete": true, "commitMessage": ${{ toJSON(env.RELEASE_NOTES) }},
"message": "{ \"commitId\": \"${{ github.sha }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"repoName\": \"${{ github.repository }}\"}" "message": "{ \"commitId\": \"${{ github.sha }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"repoName\": \"${{ github.repository }}\"}"
} }
run: | run: |

View file

@ -277,9 +277,8 @@ namespace WTelegram
private Session.DCSession GetOrCreateDCSession(int dcId, DcOption.Flags flags) private Session.DCSession GetOrCreateDCSession(int dcId, DcOption.Flags flags)
{ {
if (_session.DCSessions.TryGetValue(dcId, out var dcSession) && dcSession.AuthKey != null) if (_session.DCSessions.TryGetValue(dcId, out var dcSession) && dcSession.Client != null)
if (dcSession.Client != null || dcSession.DataCenter.flags == flags) return dcSession; // we have already a connected session with this DC, use it
return dcSession; // if we have already a session with this DC and we are connected or it is a perfect match, use it
if (dcSession == null && _session.DCSessions.TryGetValue(-dcId, out dcSession) && dcSession.AuthKey != null) if (dcSession == null && _session.DCSessions.TryGetValue(-dcId, out dcSession) && dcSession.AuthKey != null)
{ {
// we have already negociated an AuthKey with this DC // we have already negociated an AuthKey with this DC
@ -295,9 +294,10 @@ namespace WTelegram
dcId = Math.Abs(dcId); dcId = Math.Abs(dcId);
} }
var dcOptions = GetDcOptions(Math.Abs(dcId), flags); var dcOptions = GetDcOptions(Math.Abs(dcId), flags);
var dcOption = dcOptions.FirstOrDefault() ?? throw new WTException($"Could not find adequate dc_option for DC {dcId}"); var dcOption = dcOptions.FirstOrDefault();
dcSession ??= new(); // create new session only if not already existing dcSession ??= new(); // create new session only if not already existing
dcSession.DataCenter = dcOption; if (dcOption != null) dcSession.DataCenter = dcOption;
else if (dcSession.DataCenter == null) throw new WTException($"Could not find adequate dc_option for DC {dcId}");
return _session.DCSessions[dcId] = dcSession; return _session.DCSessions[dcId] = dcSession;
} }
@ -1630,6 +1630,16 @@ namespace WTelegram
got503 = true; got503 = true;
goto retry; goto retry;
} }
else if (code == 401 && message == "SESSION_REVOKED" && !IsMainDC) // need to renegociate alt-DC auth
{
lock (_session)
{
_session.DCSessions.Remove(_dcSession.DcID);
if (_session.MainDC != -_dcSession.DcID) _session.DCSessions.Remove(-_dcSession.DcID);
_session.Save();
}
await DisposeAsync();
}
else if (code == 400 && message == "CONNECTION_NOT_INITED") else if (code == 400 && message == "CONNECTION_NOT_INITED")
{ {
await InitConnection(); await InitConnection();