Skip to content

Commit

Permalink
feat(ServiceDiscovery): log request and response
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jul 21, 2018
1 parent 7b2e909 commit f0d3d6b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Spike/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void Main(string[] args)
var sd = new ServiceDiscovery(mdns);
sd.Advertise(new ServiceProfile("x1", "_xservice._tcp", 5011));
sd.Advertise(new ServiceProfile("x2", "_xservice._tcp", 666));
var z1 = new ServiceProfile("z1", "_zservice._tcp", 5012);
var z1 = new ServiceProfile("z1", "_zservice.udp", 5012);
z1.AddProperty("foo", "bar");
sd.Advertise(z1);

Expand Down
2 changes: 1 addition & 1 deletion src/Mdns.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<ItemGroup>
<PackageReference Include="Common.Logging" Version="3.4.1" />
<PackageReference Include="Makaretu.Dns" Version="0.13.3" />
<PackageReference Include="Makaretu.Dns" Version="0.13.4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard14'">
Expand Down
10 changes: 9 additions & 1 deletion src/ServiceDiscovery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Makaretu.Dns.Resolving;
using Common.Logging;
using Makaretu.Dns.Resolving;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,6 +14,8 @@ namespace Makaretu.Dns
/// <seealso href="https://tools.ietf.org/html/rfc6763">RFC 6763 DNS-Based Service Discovery</seealso>
public class ServiceDiscovery : IDisposable
{
static readonly ILog log = LogManager.GetLogger(typeof(ServiceDiscovery));

/// <summary>
/// The service discovery service name.
/// </summary>
Expand Down Expand Up @@ -136,6 +139,9 @@ void OnAnswer(object sender, MessageEventArgs e)
void OnQuery(object sender, MessageEventArgs e)
{
var request = e.Message;

if (log.IsDebugEnabled)
log.Debug($"got query for {request.Questions[0].Name} {request.Questions[0].Type}");
var response = NameServer.ResolveAsync(request).Result;
if (response.Status == MessageStatus.NoError)
{
Expand All @@ -147,6 +153,8 @@ void OnQuery(object sender, MessageEventArgs e)
}

Mdns.SendAnswer(response);
if (log.IsDebugEnabled)
log.Debug($"sent answer {response.Answers[0]}");
//Console.WriteLine($"Response time {(DateTime.Now - request.CreationTime).TotalMilliseconds}ms");
}
}
Expand Down

0 comments on commit f0d3d6b

Please # to comment.