mediaonly filter

reverted tcptransport
This commit is contained in:
solarin 2020-04-11 18:59:59 +04:00
parent bc87d0aea7
commit a266b896d2
2 changed files with 23 additions and 29 deletions

View file

@ -18,39 +18,30 @@ namespace TLSharp.Core.Network
TcpClientConnectionHandler handler;
readonly string address;
readonly int port;
readonly IPAddress ipAddress;
readonly IPAddress ipAddress;
public TcpTransport(string address, int port, TcpClientConnectionHandler handler = null)
{
this.handler = handler;
this.address = address;
this.port = port;
ipAddress = IPAddress.Parse(address);
}
public async Task ConnectAsync()
{
if (handler == null)
{
if (tcpClient != null)
{
tcpClient.Close();
}
var ipAddress = IPAddress.Parse(address);
var endpoint = new IPEndPoint(ipAddress, port);
tcpClient = new TcpClient(ipAddress.AddressFamily);
try
{
await tcpClient.ConnectAsync(ipAddress, port);
} catch (Exception ex) {
throw new Exception ($"Problem when trying to connect to {ipAddress}:{port}; either there's no internet connection or the IP address version is not compatible (if the latter, consider using DataCenterIPVersion enum)",
tcpClient.Connect(endpoint);
}
catch (Exception ex)
{
throw new Exception($"Problem when trying to connect to {endpoint}; either there's no internet connection or the IP address version is not compatible (if the latter, consider using DataCenterIPVersion enum)",
ex);
}
}
else
tcpClient = handler(address, port);
sendCounter = 0;
if (tcpClient.Connected)
{
stream = tcpClient.GetStream();

View file

@ -65,22 +65,22 @@ namespace TLSharp.Core
this.apiId = apiId;
this.handler = handler;
this.dcIpVersion = dcIpVersion;
session = Session.TryLoadOrCreateNew(this.store, sessionUserId);
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
}
public async Task ConnectAsync(bool reconnect = false, CancellationToken token = default(CancellationToken))
{
token.ThrowIfCancellationRequested();
if (!transport.IsConnected)
{
// we must recreate the session because it might track dirty information
// of a connection that maybe was disconnected, reusing that session will cause errors
session = Session.TryLoadOrCreateNew(store, sessionUserId);
await transport.ConnectAsync();
}
//if (!transport.IsConnected)
//{
// // we must recreate the session because it might track dirty information
// // of a connection that maybe was disconnected, reusing that session will cause errors
// session = Session.TryLoadOrCreateNew(store, sessionUserId);
// await transport.ConnectAsync();
//}
session = Session.TryLoadOrCreateNew(store, sessionUserId);
transport = new TcpTransport(session.DataCenter.Address, session.DataCenter.Port, this.handler);
if (session.AuthKey == null || reconnect)
{
@ -131,6 +131,8 @@ namespace TLSharp.Core
else
dcs = dcOptions.Where(d => d.Id == dcId); // any
dcs = dcs.Where(d => !d.MediaOnly);//.AsEnumerable();
TLDcOption dc;
if (dcIpVersion != DataCenterIPVersion.Default)
{
@ -144,8 +146,9 @@ namespace TLSharp.Core
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);
session.DataCenter = dataCenter;
session.Save();
await ConnectAsync(true, token).ConfigureAwait(false);