Skip to content

Commit ac69b24

Browse files
committed
repair GetTurnServerInfo
1 parent feeae6e commit ac69b24

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

libsignal-service-dotnet/SignalServiceAccountManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public SignalServiceAccountManager(SignalServiceConfiguration configuration,
5454
/// <param name="configuration">The URL configuration for the Signal Service</param>
5555
/// <param name="token">The cancellation token for the ProvisioningSocket</param>
5656
/// <param name="userAgent">A string which identifies the client software</param>
57-
public SignalServiceAccountManager(SignalServiceConfiguration configuration, CancellationToken token, string userAgent)
57+
public SignalServiceAccountManager(SignalServiceConfiguration configuration, string userAgent)
5858
{
5959
Configuration = configuration;
6060
UserAgent = userAgent;
@@ -348,9 +348,9 @@ public void RemoveDevice(long deviceId)
348348
/// TODO
349349
/// </summary>
350350
/// <returns></returns>
351-
public TurnServerInfo GetTurnServerInfo()
351+
public async Task<TurnServerInfo> GetTurnServerInfo(CancellationToken token)
352352
{
353-
return this.PushServiceSocket.GetTurnServerInfo();
353+
return await this.PushServiceSocket.GetTurnServerInfo(token);
354354
}
355355

356356
/// <summary>

libsignal-service-dotnet/push/PushServiceSocket.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public async Task<int> FinishNewDeviceRegistration(CancellationToken token, Stri
9494
{
9595
ConfirmCodeMessage javaJson = new ConfirmCodeMessage(signalingKey, supportsSms, fetchesMessages, registrationId, deviceName);
9696
string json = JsonUtil.ToJson(javaJson);
97-
string responseText = await MakeServiceRequestAsync(string.Format(DEVICE_PATH, code), "PUT", json);
97+
string responseText = await MakeServiceRequestAsync(token, string.Format(DEVICE_PATH, code), "PUT", json);
9898
DeviceId response = JsonUtil.FromJson<DeviceId>(responseText);
9999
return response.NewDeviceId;
100100
}
@@ -479,9 +479,10 @@ public ContactTokenDetails GetContactTokenDetails(string contactToken)// throws
479479
}
480480
}
481481

482-
public TurnServerInfo GetTurnServerInfo()
482+
public async Task<TurnServerInfo> GetTurnServerInfo(CancellationToken token)
483483
{
484-
throw new NotImplementedException();
484+
string response = await MakeServiceRequestAsync(token, TURN_SERVER_INFO, "GET", null);
485+
return JsonUtil.FromJson<TurnServerInfo>(response);
485486
}
486487

487488
public void SetSoTimeoutMillis(long soTimeoutMillis)
@@ -615,18 +616,19 @@ private string MakeServiceRequest(string urlFragment, string method, string body
615616
{
616617
try
617618
{
618-
return MakeServiceRequestAsync(urlFragment, method, body).Result;
619+
var dummy = new CancellationTokenSource();
620+
return MakeServiceRequestAsync(dummy.Token, urlFragment, method, body).Result;
619621
}
620622
catch (AggregateException e)
621623
{
622624
throw e.InnerException;
623625
}
624626
}
625627

626-
private async Task<string> MakeServiceRequestAsync(string urlFragment, string method, string body)
628+
private async Task<string> MakeServiceRequestAsync(CancellationToken token, string urlFragment, string method, string body)
627629
//throws NonSuccessfulResponseCodeException, PushNetworkException
628630
{
629-
HttpResponseMessage connection = GetServiceConnection(urlFragment, method, body);
631+
HttpResponseMessage connection = await GetServiceConnectionAsync(token, urlFragment, method, body);
630632
HttpStatusCode responseCode;
631633
string responseMessage;
632634
string responseBody;
@@ -719,7 +721,7 @@ private bool Func(HttpRequestMessage a, X509Certificate2 b, X509Chain c, SslPoli
719721
return true;
720722
}
721723

722-
private HttpResponseMessage GetServiceConnection(string urlFragment, string method, string body)
724+
private async Task<HttpResponseMessage> GetServiceConnectionAsync(CancellationToken token, string urlFragment, string method, string body)
723725
{
724726
try
725727
{
@@ -753,7 +755,6 @@ private HttpResponseMessage GetServiceConnection(string urlFragment, string meth
753755
if (body != null)
754756
{
755757
content = new StringContent(body, Encoding.UTF8, "application/json");
756-
Debug.WriteLine(body);
757758
}
758759
else
759760
{
@@ -762,16 +763,16 @@ private HttpResponseMessage GetServiceConnection(string urlFragment, string meth
762763
switch (method)
763764
{
764765
case "POST":
765-
return connection.PostAsync(uri, content).Result;
766+
return await connection.PostAsync(uri, content, token);
766767

767768
case "PUT":
768-
return connection.PutAsync(uri, content).Result;
769+
return await connection.PutAsync(uri, content, token);
769770

770771
case "DELETE":
771-
return connection.DeleteAsync(uri).Result;
772+
return await connection.DeleteAsync(uri, token);
772773

773774
case "GET":
774-
return connection.GetAsync(uri).Result;
775+
return await connection.GetAsync(uri, token);
775776

776777
default:
777778
throw new Exception("Unknown method: " + method);

0 commit comments

Comments
 (0)