Skip to content

Commit

Permalink
ignore IPv6 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalatt committed Jan 22, 2019
1 parent c8dfa4f commit fccb7f2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Telega/TelegramClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ public static async Task<TelegramClient> Connect(
}


IPEndPoint FindDcEndpoint(int dcId) => _dcOptions
.Filter(x => x.Id == dcId)
.Map(dc => new IPEndPoint(IPAddress.Parse(dc.IpAddress), dc.Port))
.Find(x => x.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
.IfNone(() => throw new TgInternalException($"Can not find an IPv4 endpoint for DC {dcId}.", None));

// TODO: fix
internal async Task SetAuthorized(User user)
{
Expand All @@ -161,8 +167,7 @@ async Task ReconnectToDc(int dcId)

var exported = !IsAuthorized ? null : await _transport.Call(new ExportAuthorization(dcId: dcId));

var dc = _dcOptions.First(d => d.Id == dcId);
_session.Endpoint = new IPEndPoint(IPAddress.Parse(dc.IpAddress), dc.Port);
_session.Endpoint = FindDcEndpoint(dcId);
_session.AuthKey = null;
await Connect();

Expand Down Expand Up @@ -202,16 +207,11 @@ internal async Task<TelegramClient> GetFileClient<T>(ITgFunc<T> func)
var dcId = e.Dc;
if (!_fileClients.TryGetValue(dcId, out var fileClient))
{
var ep = _dcOptions
.Find(x => x.Id == dcId)
.IfNone(() => throw new TgInternalException($"can not find DC {dcId}", None))
.Apply(dc => new IPEndPoint(IPAddress.Parse(dc.IpAddress), dc.Port));

fileClient = await Connect(
apiId: _apiId,
apiHash: _apiHash,
store: new FakeSessionStore(),
endpoint: ep
endpoint: FindDcEndpoint(dcId)
);

var exported = await Call(new ExportAuthorization(dcId: dcId));
Expand Down

0 comments on commit fccb7f2

Please sign in to comment.