From 15d4f6354dcea5aef4c4a584ac64af49b73490f6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 12 Jul 2014 16:15:24 -0700 Subject: [PATCH] Fix mDNS recognition of PCs running GFE 2.1 --- .../limelight/nvstream/mdns/MdnsComputer.java | 16 ++----- .../nvstream/mdns/MdnsDiscoveryAgent.java | 48 +++---------------- 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/mdns/MdnsComputer.java b/moonlight-common/src/com/limelight/nvstream/mdns/MdnsComputer.java index 6c61414e..67242ca8 100644 --- a/moonlight-common/src/com/limelight/nvstream/mdns/MdnsComputer.java +++ b/moonlight-common/src/com/limelight/nvstream/mdns/MdnsComputer.java @@ -1,16 +1,13 @@ package com.limelight.nvstream.mdns; import java.net.InetAddress; -import java.util.UUID; public class MdnsComputer { private InetAddress ipAddr; - private UUID uniqueId; private String name; - public MdnsComputer(String name, UUID uniqueId, InetAddress addr) { + public MdnsComputer(String name, InetAddress addr) { this.name = name; - this.uniqueId = uniqueId; this.ipAddr = addr; } @@ -18,25 +15,20 @@ public class MdnsComputer { return name; } - public UUID getUniqueId() { - return uniqueId; - } - public InetAddress getAddress() { return ipAddr; } @Override public int hashCode() { - return uniqueId.hashCode(); + return name.hashCode(); } @Override public boolean equals(Object o) { if (o instanceof MdnsComputer) { MdnsComputer other = (MdnsComputer)o; - if (other.uniqueId.equals(uniqueId) && - other.ipAddr.equals(ipAddr) && + if (other.ipAddr.equals(ipAddr) && other.name.equals(name)) { return true; } @@ -47,6 +39,6 @@ public class MdnsComputer { @Override public String toString() { - return "["+name+" - "+uniqueId+" - "+ipAddr+"]"; + return "["+name+" - "+ipAddr+"]"; } } diff --git a/moonlight-common/src/com/limelight/nvstream/mdns/MdnsDiscoveryAgent.java b/moonlight-common/src/com/limelight/nvstream/mdns/MdnsDiscoveryAgent.java index 44224938..726b0ea6 100644 --- a/moonlight-common/src/com/limelight/nvstream/mdns/MdnsDiscoveryAgent.java +++ b/moonlight-common/src/com/limelight/nvstream/mdns/MdnsDiscoveryAgent.java @@ -6,13 +6,11 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Timer; import java.util.TimerTask; -import java.util.UUID; import com.jmdns.JmDNS; import com.jmdns.ServiceEvent; @@ -63,8 +61,13 @@ public class MdnsDiscoveryAgent { try { computer = parseMdnsResponse(event); + if (computer == null) { + LimeLog.info("mDNS: Invalid response for machine: "+event.getInfo().getName()); + return; + } } catch (UnsupportedEncodingException e) { // Invalid DNS response + LimeLog.info("mDNS: Invalid response for machine: "+event.getInfo().getName()); return; } @@ -77,54 +80,17 @@ public class MdnsDiscoveryAgent { } }; - private static ArrayList parseTxtBytes(byte[] txtBytes) throws UnsupportedEncodingException { - int i = 0; - ArrayList strings = new ArrayList(); - - while (i < txtBytes.length) { - int length = txtBytes[i++]; - - byte[] stringData = Arrays.copyOfRange(txtBytes, i, i+length); - strings.add(new String(stringData, "UTF-8")); - - i += length; - } - - return strings; - } - private static MdnsComputer parseMdnsResponse(ServiceEvent event) throws UnsupportedEncodingException { Inet4Address addrs[] = event.getInfo().getInet4Addresses(); if (addrs.length == 0) { + LimeLog.info("Missing addresses"); return null; } Inet4Address address = addrs[0]; String name = event.getInfo().getName(); - ArrayList txtStrs = parseTxtBytes(event.getInfo().getTextBytes()); - String uniqueId = null; - for (String txtStr : txtStrs) { - if (txtStr.startsWith("SERVICE_UNIQUEID=")) { - uniqueId = txtStr.substring(txtStr.indexOf("=")+1); - break; - } - } - if (uniqueId == null) { - return null; - } - - UUID uuid; - try { - // fromString() throws an exception for a - // malformed string - uuid = UUID.fromString(uniqueId); - } catch (IllegalArgumentException e) { - // UUID must be properly formed - return null; - } - - return new MdnsComputer(name, uuid, address); + return new MdnsComputer(name, address); } public MdnsDiscoveryAgent(MdnsDiscoveryListener listener) {