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
42 protected override async Task SendAsync(byte[] Message, IPEndPoint Destination)
43 {
44 using (HttpClient HttpClient = new HttpClient()
45 {
46 Timeout = TimeSpan.FromMilliseconds(10000)
47 })
48 {
49 using (HttpRequestMessage Request = new HttpRequestMessage()
50 {
51 RequestUri = this.uri,
52 Method = HttpMethod.Post
53 })
54 {
55 Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/dns-message"));
56 Request.Content = new ByteArrayContent(Message);
57 Request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/dns-message");
58
59 HttpResponseMessage Response = await HttpClient.SendAsync(Request);
60
61 if (Response.IsSuccessStatusCode)
62 {
63 byte[] Bin = await Response.Content.ReadAsByteArrayAsync();
64
65 await this.ReceiveBinary(Bin);
66
67 try
68 {
70 await this.ProcessIncomingMessage(DnsResponse);
71 }
72 catch (Exception ex)
73 {
74 Log.Error("Unable to process DNS packet: " + ex.Message);
75 }
76 }
77 else
78 {
79 ushort ID = Message[0];
80 ID <<= 8;
81 ID |= Message[1];
82
83 await this.ProcessMessageFailure(ID);
84 }
85 }
86 }
87 }
88
89 }
90}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
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:682
Task Exception(Exception Exception)
Called to inform the viewer of an exception state.
Task ReceiveBinary(byte[] Data)
Called when binary data has been received.
Abstract base class for DNS clients.
Definition: DnsClient.cs:21
virtual void Init()
Called when DNS client is ready to be initialized.
Definition: DnsClient.cs:63
virtual async Task ProcessIncomingMessage(DnsMessage Message)
Processes an incoming message.
Definition: DnsClient.cs:181
virtual async Task ProcessMessageFailure(ushort ID)
Request resulted in a failure.
Definition: DnsClient.cs:205
Implements a DNS over HTTPS (DoH)-based client.
DnsHttpsClient(Uri Uri)
Implements a DNS over HTTPS (DoH)-based client.
override async Task SendAsync(byte[] Message, IPEndPoint Destination)
Sends a message to a destination.