Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DnsHttpsClient.cs
1using System;
2using System.Net;
3using System.Net.Http;
4using System.Net.Http.Headers;
5using System.Threading.Tasks;
6using Waher.Events;
7
9{
14 {
15 private Uri uri;
16
21 : base()
22 {
23 this.uri = Uri;
24 this.Init();
25 }
26
30 public Uri Uri
31 {
32 get => this.uri;
33 set => this.uri = value;
34 }
35
44 protected override async Task SendAsync(bool ConstantBuffer, byte[] Message, IPEndPoint Destination)
45 {
46 using (HttpClient HttpClient = new HttpClient()
47 {
48 Timeout = TimeSpan.FromMilliseconds(10000)
49 })
50 {
51 using (HttpRequestMessage Request = new HttpRequestMessage()
52 {
53 RequestUri = this.uri,
54 Method = HttpMethod.Post
55 })
56 {
57 Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/dns-message"));
58 Request.Content = new ByteArrayContent(Message);
59 Request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/dns-message");
60
61 HttpResponseMessage Response = await HttpClient.SendAsync(Request);
62
63 if (Response.IsSuccessStatusCode)
64 {
65 byte[] Bin = await Response.Content.ReadAsByteArrayAsync();
66
67 this.ReceiveBinary(true, Bin);
68
69 try
70 {
72 await this.ProcessIncomingMessage(DnsResponse);
73 }
74 catch (Exception ex)
75 {
76 Log.Error("Unable to process DNS packet: " + ex.Message);
77 }
78 }
79 else
80 {
81 ushort ID = Message[0];
82 ID <<= 8;
83 ID |= Message[1];
84
85 await this.ProcessMessageFailure(ID);
86 }
87 }
88 }
89 }
90
91 }
92}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
Definition: Log.cs:692
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(int Count)
Called when binary data has been received.
Abstract base class for DNS clients.
Definition: DnsClient.cs:22
virtual void Init()
Called when DNS client is ready to be initialized.
Definition: DnsClient.cs:65
virtual async Task ProcessIncomingMessage(DnsMessage Message)
Processes an incoming message.
Definition: DnsClient.cs:188
virtual async Task ProcessMessageFailure(ushort ID)
Request resulted in a failure.
Definition: DnsClient.cs:212
Implements a DNS over HTTPS (DoH)-based client.
DnsHttpsClient(Uri Uri)
Implements a DNS over HTTPS (DoH)-based client.
override async Task SendAsync(bool ConstantBuffer, byte[] Message, IPEndPoint Destination)
Sends a message to a destination.