Files
duplicati/Duplicati/Library/Backend/Telegram/InMemorySessionStore.cs
T

41 lines
1.2 KiB
C#
Raw Normal View History

2020-09-02 22:51:14 +04:00
using System.Collections.Concurrent;
using TLSharp.Core;
namespace Duplicati.Library.Backend
{
public class InMemorySessionStore : ISessionStore
{
2020-09-03 23:07:30 +04:00
private readonly ConcurrentDictionary<string, byte[]> m_phoneSessionBytesMap = new ConcurrentDictionary<string, byte[]>();
private readonly ConcurrentDictionary<string, string> m_phonePhoneCodeHashMap = new ConcurrentDictionary<string, string>();
2020-09-02 22:51:14 +04:00
public void Save(Session session)
{
2020-09-03 23:07:30 +04:00
m_phoneSessionBytesMap[session.SessionUserId] = session.ToBytes();
2020-09-02 22:51:14 +04:00
}
2020-09-03 23:07:30 +04:00
public Session Load(string phone)
2020-09-02 22:51:14 +04:00
{
2020-09-03 23:07:30 +04:00
if (m_phoneSessionBytesMap.TryGetValue(phone, out var sessionBytes))
2020-09-02 22:51:14 +04:00
{
2020-09-03 23:07:30 +04:00
return Session.FromBytes(sessionBytes, this, phone);
2020-09-02 22:51:14 +04:00
}
return null;
}
2020-09-03 23:07:30 +04:00
public void SetPhoneHash(string phone, string phoneCodeHash)
2020-09-02 22:51:14 +04:00
{
2020-09-03 23:07:30 +04:00
m_phonePhoneCodeHashMap[phone] = phoneCodeHash;
2020-09-02 22:51:14 +04:00
}
2020-09-03 23:07:30 +04:00
public string GetPhoneHash(string phone)
2020-09-02 22:51:14 +04:00
{
2020-09-03 23:07:30 +04:00
if (m_phonePhoneCodeHashMap.TryGetValue(phone, out var result))
2020-09-02 22:51:14 +04:00
{
return result;
}
return null;
}
}
}