mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
white spaces again....
This commit is contained in:
parent
d9c2cdfd18
commit
365fe6775e
|
|
@ -31,14 +31,25 @@ namespace TLSharp.Core
|
||||||
private Session session;
|
private Session session;
|
||||||
private List<TLDcOption> dcOptions;
|
private List<TLDcOption> dcOptions;
|
||||||
private TcpClientConnectionHandler handler;
|
private TcpClientConnectionHandler handler;
|
||||||
|
private DataCenterIPVersion dcIpVersion;
|
||||||
|
|
||||||
public Session Session
|
public Session Session
|
||||||
{
|
{
|
||||||
get { return session; }
|
get { return session; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new TelegramClient
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiId">The API ID provided by Telegram. Get one at https://my.telegram.org </param>
|
||||||
|
/// <param name="apiHash">The API Hash provided by Telegram. Get one at https://my.telegram.org </param>
|
||||||
|
/// <param name="store">An ISessionStore object that will handle the session</param>
|
||||||
|
/// <param name="sessionUserId">The name of the session that tracks login info about this TelegramClient connection</param>
|
||||||
|
/// <param name="handler">A delegate to invoke when a connection is needed and that will return a TcpClient that will be used to connect</param>
|
||||||
|
/// <param name="dcIpVersion">Indicates the preferred IpAddress version to use to connect to a Telegram server</param>
|
||||||
public TelegramClient(int apiId, string apiHash,
|
public TelegramClient(int apiId, string apiHash,
|
||||||
ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null)
|
ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null,
|
||||||
|
DataCenterIPVersion dcIpVersion = DataCenterIPVersion.Default)
|
||||||
{
|
{
|
||||||
if (apiId == default(int))
|
if (apiId == default(int))
|
||||||
throw new MissingApiConfigurationException("API_ID");
|
throw new MissingApiConfigurationException("API_ID");
|
||||||
|
|
@ -51,6 +62,7 @@ namespace TLSharp.Core
|
||||||
this.apiHash = apiHash;
|
this.apiHash = apiHash;
|
||||||
this.apiId = apiId;
|
this.apiId = apiId;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
this.dcIpVersion = dcIpVersion;
|
||||||
|
|
||||||
session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
||||||
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
|
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
|
||||||
|
|
@ -101,7 +113,21 @@ namespace TLSharp.Core
|
||||||
exported = await SendRequestAsync<TLExportedAuthorization>(exportAuthorization, token).ConfigureAwait(false);
|
exported = await SendRequestAsync<TLExportedAuthorization>(exportAuthorization, token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dc = dcOptions.First(d => d.Id == dcId);
|
var dcs = dcOptions.Where(d => d.Id == dcId
|
||||||
|
&& (
|
||||||
|
(dcIpVersion == DataCenterIPVersion.Default) // any
|
||||||
|
|| (d.Ipv6 && dcIpVersion == DataCenterIPVersion.OnlyIPv6) // selects only ipv6 addresses
|
||||||
|
|| (!d.Ipv6 && dcIpVersion == DataCenterIPVersion.OnlyIPv4) // selects only ipv4 addresses
|
||||||
|
|| dcIpVersion == DataCenterIPVersion.PreferIPv4 // we can take both types of address
|
||||||
|
|| dcIpVersion == DataCenterIPVersion.PreferIPv6 // we can take both types of address
|
||||||
|
)
|
||||||
|
).OrderBy(d => d.Ipv6);
|
||||||
|
|
||||||
|
if (dcs.Count() == 0)
|
||||||
|
throw new Exception($"Telegram server didn't provide us with any IPAddress that matches your preferences. If you chose OnlyIPvX, try switch to PreferIPvX instead.");
|
||||||
|
|
||||||
|
var dc = dcIpVersion == DataCenterIPVersion.PreferIPv4 ? dcs.First() : dcs.Last(); // ipv4 addresses are at the beginning of the list because it was ordered
|
||||||
|
|
||||||
var dataCenter = new DataCenter (dcId, dc.IpAddress, dc.Port);
|
var dataCenter = new DataCenter (dcId, dc.IpAddress, dc.Port);
|
||||||
|
|
||||||
transport = new TcpTransport(dc.IpAddress, dc.Port, handler);
|
transport = new TcpTransport(dc.IpAddress, dc.Port, handler);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue