main: Moved HIP02 lookup to its own task

This commit is contained in:
Nathan Woodburn 2023-06-24 11:28:30 +10:00
parent 843f824b2f
commit cbf1bc3e38
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -1639,17 +1639,8 @@ namespace FireWallet
// Store TLSA hash
public string TLSA { get; set; }
private async void textBoxSendingTo_Leave(object sender, EventArgs e)
public async Task<string> HIP02Lookup(string domain)
{
labelSendingError.Hide();
labelHIPArrow.Hide();
labelSendingHIPAddress.Hide();
if (textBoxSendingTo.Text == "") return;
if (textBoxSendingTo.Text.Substring(0, 1) == "@")
{
string domain = textBoxSendingTo.Text.Substring(1);
try
{
IPAddress iPAddress = null;
@ -1659,7 +1650,6 @@ namespace FireWallet
// Create an instance of LookupClient using the custom options
string ip = "127.0.0.1";
int port = 5350;
if (UserSettings.ContainsKey("hip-02-ip"))
{
ip = UserSettings["hip-02-ip"];
@ -1684,8 +1674,7 @@ namespace FireWallet
options.Recursion = true;
options.UseCache = false;
options.RequestDnsSecRecords = true;
options.Timeout = TimeSpan.FromSeconds(5);
options.Timeout = httpClient.Timeout;
var client = new LookupClient(options);
// Perform the DNS lookup for the specified domain using DNSSec
@ -1701,7 +1690,7 @@ namespace FireWallet
labelSendingError.Show();
labelSendingError.Text = "HIP-02 lookup failed";
AddLog("No IP found");
return;
return "ERROR";
}
// Get TLSA record
@ -1731,7 +1720,7 @@ namespace FireWallet
labelSendingError.Text = "HIP-02 lookup failed";
AddLog("HTTPS get failed");
AddLog(response.Content.ReadAsStringAsync().Result);
return;
return "ERROR";
}
// Response
@ -1741,29 +1730,46 @@ namespace FireWallet
if (await ValidAddress(address))
{
labelSendingHIPAddress.Text = address;
labelSendingHIPAddress.Show();
labelHIPArrow.Show();
return address;
}
else
{
labelSendingError.Show();
labelSendingError.Text = "Invalid Address";
AddLog("Invalid Address\n" + address);
return "ERROR";
}
}
}
catch (Exception ex)
{
AddLog("HIP-02 lookup error");
AddLog(ex.Message);
return "ERROR";
}
}
private async void textBoxSendingTo_Leave(object sender, EventArgs e)
{
labelSendingError.Hide();
labelHIPArrow.Hide();
labelSendingHIPAddress.Hide();
if (textBoxSendingTo.Text == "") return;
if (textBoxSendingTo.Text.Substring(0, 1) == "@")
{
string domain = textBoxSendingTo.Text.Substring(1);
string address = await HIP02Lookup(domain);
if (address == "ERROR")
{
labelSendingError.Show();
labelSendingError.Text = "HIP-02 lookup failed";
} else
{
labelSendingHIPAddress.Text = address;
labelSendingHIPAddress.Show();
labelHIPArrow.Show();
}
}
else
{