mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 03:52:48 +00:00
Fix mDNS recognition of PCs running GFE 2.1
This commit is contained in:
parent
77cea99b35
commit
15d4f6354d
@ -1,16 +1,13 @@
|
|||||||
package com.limelight.nvstream.mdns;
|
package com.limelight.nvstream.mdns;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MdnsComputer {
|
public class MdnsComputer {
|
||||||
private InetAddress ipAddr;
|
private InetAddress ipAddr;
|
||||||
private UUID uniqueId;
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public MdnsComputer(String name, UUID uniqueId, InetAddress addr) {
|
public MdnsComputer(String name, InetAddress addr) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.uniqueId = uniqueId;
|
|
||||||
this.ipAddr = addr;
|
this.ipAddr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,25 +15,20 @@ public class MdnsComputer {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUniqueId() {
|
|
||||||
return uniqueId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetAddress getAddress() {
|
public InetAddress getAddress() {
|
||||||
return ipAddr;
|
return ipAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return uniqueId.hashCode();
|
return name.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof MdnsComputer) {
|
if (o instanceof MdnsComputer) {
|
||||||
MdnsComputer other = (MdnsComputer)o;
|
MdnsComputer other = (MdnsComputer)o;
|
||||||
if (other.uniqueId.equals(uniqueId) &&
|
if (other.ipAddr.equals(ipAddr) &&
|
||||||
other.ipAddr.equals(ipAddr) &&
|
|
||||||
other.name.equals(name)) {
|
other.name.equals(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -47,6 +39,6 @@ public class MdnsComputer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "["+name+" - "+uniqueId+" - "+ipAddr+"]";
|
return "["+name+" - "+ipAddr+"]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,11 @@ import java.net.Inet4Address;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.jmdns.JmDNS;
|
import com.jmdns.JmDNS;
|
||||||
import com.jmdns.ServiceEvent;
|
import com.jmdns.ServiceEvent;
|
||||||
@ -63,8 +61,13 @@ public class MdnsDiscoveryAgent {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
computer = parseMdnsResponse(event);
|
computer = parseMdnsResponse(event);
|
||||||
|
if (computer == null) {
|
||||||
|
LimeLog.info("mDNS: Invalid response for machine: "+event.getInfo().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
// Invalid DNS response
|
// Invalid DNS response
|
||||||
|
LimeLog.info("mDNS: Invalid response for machine: "+event.getInfo().getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,54 +80,17 @@ public class MdnsDiscoveryAgent {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static ArrayList<String> parseTxtBytes(byte[] txtBytes) throws UnsupportedEncodingException {
|
|
||||||
int i = 0;
|
|
||||||
ArrayList<String> strings = new ArrayList<String>();
|
|
||||||
|
|
||||||
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 {
|
private static MdnsComputer parseMdnsResponse(ServiceEvent event) throws UnsupportedEncodingException {
|
||||||
Inet4Address addrs[] = event.getInfo().getInet4Addresses();
|
Inet4Address addrs[] = event.getInfo().getInet4Addresses();
|
||||||
if (addrs.length == 0) {
|
if (addrs.length == 0) {
|
||||||
|
LimeLog.info("Missing addresses");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Inet4Address address = addrs[0];
|
Inet4Address address = addrs[0];
|
||||||
String name = event.getInfo().getName();
|
String name = event.getInfo().getName();
|
||||||
ArrayList<String> 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 new MdnsComputer(name, address);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MdnsDiscoveryAgent(MdnsDiscoveryListener listener) {
|
public MdnsDiscoveryAgent(MdnsDiscoveryListener listener) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user