[mdns] exclude mDNS advertiser code from standalone build test
service-connectivity-mdns-standalone-build-test builds the mDNS discovery and advertisement implementation against API level 21. This stops the advertisement code from calling new NsdServiceInfo public or private APIs which are required by Thread. This commit removes the mDNS advertisement code from the standalone build to loose the check given this will never be used by GMS Core. Bug: 265095929 Test: verified that it can build with aosp/2608627 Change-Id: I32cfce7b994d51a4b4ec468e9f79ffc2be6635ff
This commit is contained in:
@@ -102,7 +102,12 @@ java_library {
|
|||||||
],
|
],
|
||||||
exclude_srcs: [
|
exclude_srcs: [
|
||||||
"src/com/android/server/connectivity/mdns/internal/SocketNetlinkMonitor.java",
|
"src/com/android/server/connectivity/mdns/internal/SocketNetlinkMonitor.java",
|
||||||
"src/com/android/server/connectivity/mdns/SocketNetLinkMonitorFactory.java"
|
"src/com/android/server/connectivity/mdns/SocketNetLinkMonitorFactory.java",
|
||||||
|
"src/com/android/server/connectivity/mdns/MdnsAdvertiser.java",
|
||||||
|
"src/com/android/server/connectivity/mdns/MdnsAnnouncer.java",
|
||||||
|
"src/com/android/server/connectivity/mdns/MdnsInterfaceAdvertiser.java",
|
||||||
|
"src/com/android/server/connectivity/mdns/MdnsProber.java",
|
||||||
|
"src/com/android/server/connectivity/mdns/MdnsRecordRepository.java",
|
||||||
],
|
],
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"net-utils-device-common-mdns-standalone-build-test",
|
"net-utils-device-common-mdns-standalone-build-test",
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class MdnsAnnouncer extends MdnsPacketRepeater<MdnsAnnouncer.BaseAnnounce
|
|||||||
@NonNull MdnsReplySender replySender,
|
@NonNull MdnsReplySender replySender,
|
||||||
@Nullable PacketRepeaterCallback<BaseAnnouncementInfo> cb,
|
@Nullable PacketRepeaterCallback<BaseAnnouncementInfo> cb,
|
||||||
@NonNull SharedLog sharedLog) {
|
@NonNull SharedLog sharedLog) {
|
||||||
super(looper, replySender, cb, sharedLog);
|
super(looper, replySender, cb, sharedLog, MdnsAdvertiser.DBG);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Notify MdnsRecordRepository that the records were announced for that service ID,
|
// TODO: Notify MdnsRecordRepository that the records were announced for that service ID,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.server.connectivity.mdns;
|
|||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
@@ -42,6 +43,10 @@ public final class MdnsConstants {
|
|||||||
public static final String SUBTYPE_PREFIX = "_";
|
public static final String SUBTYPE_PREFIX = "_";
|
||||||
private static final String MDNS_IPV4_HOST_ADDRESS = "224.0.0.251";
|
private static final String MDNS_IPV4_HOST_ADDRESS = "224.0.0.251";
|
||||||
private static final String MDNS_IPV6_HOST_ADDRESS = "FF02::FB";
|
private static final String MDNS_IPV6_HOST_ADDRESS = "FF02::FB";
|
||||||
|
public static final InetSocketAddress IPV6_SOCKET_ADDR = new InetSocketAddress(
|
||||||
|
getMdnsIPv6Address(), MDNS_PORT);
|
||||||
|
public static final InetSocketAddress IPV4_SOCKET_ADDR = new InetSocketAddress(
|
||||||
|
getMdnsIPv4Address(), MDNS_PORT);
|
||||||
private static InetAddress mdnsAddress;
|
private static InetAddress mdnsAddress;
|
||||||
private MdnsConstants() {
|
private MdnsConstants() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public class MdnsInterfaceAdvertiser implements MulticastPacketReader.PacketHand
|
|||||||
@NonNull SharedLog sharedLog) {
|
@NonNull SharedLog sharedLog) {
|
||||||
return new MdnsReplySender(looper, socket, packetCreationBuffer,
|
return new MdnsReplySender(looper, socket, packetCreationBuffer,
|
||||||
sharedLog.forSubComponent(
|
sharedLog.forSubComponent(
|
||||||
MdnsReplySender.class.getSimpleName() + "/" + interfaceTag));
|
MdnsReplySender.class.getSimpleName() + "/" + interfaceTag), DBG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see MdnsAnnouncer */
|
/** @see MdnsAnnouncer */
|
||||||
@@ -370,7 +370,7 @@ public class MdnsInterfaceAdvertiser implements MulticastPacketReader.PacketHand
|
|||||||
// happen when the incoming packet has answer records (not a question), so there will be no
|
// happen when the incoming packet has answer records (not a question), so there will be no
|
||||||
// answer. One exception is simultaneous probe tiebreaking (rfc6762 8.2), in which case the
|
// answer. One exception is simultaneous probe tiebreaking (rfc6762 8.2), in which case the
|
||||||
// conflicting service is still probing and won't reply either.
|
// conflicting service is still probing and won't reply either.
|
||||||
final MdnsRecordRepository.ReplyInfo answers = mRecordRepository.getReply(packet, src);
|
final MdnsReplyInfo answers = mRecordRepository.getReply(packet, src);
|
||||||
|
|
||||||
if (answers == null) return;
|
if (answers == null) return;
|
||||||
mReplySender.queueReply(answers);
|
mReplySender.queueReply(answers);
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package com.android.server.connectivity.mdns;
|
package com.android.server.connectivity.mdns;
|
||||||
|
|
||||||
import static com.android.server.connectivity.mdns.MdnsRecordRepository.IPV4_ADDR;
|
import static com.android.server.connectivity.mdns.MdnsConstants.IPV4_SOCKET_ADDR;
|
||||||
import static com.android.server.connectivity.mdns.MdnsRecordRepository.IPV6_ADDR;
|
import static com.android.server.connectivity.mdns.MdnsConstants.IPV6_SOCKET_ADDR;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -38,9 +38,8 @@ import java.net.InetSocketAddress;
|
|||||||
*/
|
*/
|
||||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||||
public abstract class MdnsPacketRepeater<T extends MdnsPacketRepeater.Request> {
|
public abstract class MdnsPacketRepeater<T extends MdnsPacketRepeater.Request> {
|
||||||
private static final boolean DBG = MdnsAdvertiser.DBG;
|
|
||||||
private static final InetSocketAddress[] ALL_ADDRS = new InetSocketAddress[] {
|
private static final InetSocketAddress[] ALL_ADDRS = new InetSocketAddress[] {
|
||||||
IPV4_ADDR, IPV6_ADDR
|
IPV4_SOCKET_ADDR, IPV6_SOCKET_ADDR
|
||||||
};
|
};
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -51,6 +50,7 @@ public abstract class MdnsPacketRepeater<T extends MdnsPacketRepeater.Request> {
|
|||||||
private final PacketRepeaterCallback<T> mCb;
|
private final PacketRepeaterCallback<T> mCb;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SharedLog mSharedLog;
|
private final SharedLog mSharedLog;
|
||||||
|
private final boolean mEnableDebugLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status callback from {@link MdnsPacketRepeater}.
|
* Status callback from {@link MdnsPacketRepeater}.
|
||||||
@@ -111,7 +111,7 @@ public abstract class MdnsPacketRepeater<T extends MdnsPacketRepeater.Request> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final MdnsPacket packet = request.getPacket(index);
|
final MdnsPacket packet = request.getPacket(index);
|
||||||
if (DBG) {
|
if (mEnableDebugLog) {
|
||||||
mSharedLog.v("Sending packets for iteration " + index + " out of "
|
mSharedLog.v("Sending packets for iteration " + index + " out of "
|
||||||
+ request.getNumSends() + " for ID " + msg.what);
|
+ request.getNumSends() + " for ID " + msg.what);
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ public abstract class MdnsPacketRepeater<T extends MdnsPacketRepeater.Request> {
|
|||||||
// likely not to be available since the device is in deep sleep anyway.
|
// likely not to be available since the device is in deep sleep anyway.
|
||||||
final long delay = request.getDelayMs(nextIndex);
|
final long delay = request.getDelayMs(nextIndex);
|
||||||
sendMessageDelayed(obtainMessage(msg.what, nextIndex, 0, request), delay);
|
sendMessageDelayed(obtainMessage(msg.what, nextIndex, 0, request), delay);
|
||||||
if (DBG) mSharedLog.v("Scheduled next packet in " + delay + "ms");
|
if (mEnableDebugLog) mSharedLog.v("Scheduled next packet in " + delay + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call onSent after scheduling the next run, to allow the callback to cancel it
|
// Call onSent after scheduling the next run, to allow the callback to cancel it
|
||||||
@@ -145,15 +145,17 @@ public abstract class MdnsPacketRepeater<T extends MdnsPacketRepeater.Request> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected MdnsPacketRepeater(@NonNull Looper looper, @NonNull MdnsReplySender replySender,
|
protected MdnsPacketRepeater(@NonNull Looper looper, @NonNull MdnsReplySender replySender,
|
||||||
@Nullable PacketRepeaterCallback<T> cb, @NonNull SharedLog sharedLog) {
|
@Nullable PacketRepeaterCallback<T> cb, @NonNull SharedLog sharedLog,
|
||||||
|
boolean enableDebugLog) {
|
||||||
mHandler = new ProbeHandler(looper);
|
mHandler = new ProbeHandler(looper);
|
||||||
mReplySender = replySender;
|
mReplySender = replySender;
|
||||||
mCb = cb;
|
mCb = cb;
|
||||||
mSharedLog = sharedLog;
|
mSharedLog = sharedLog;
|
||||||
|
mEnableDebugLog = enableDebugLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startSending(int id, @NonNull T request, long initialDelayMs) {
|
protected void startSending(int id, @NonNull T request, long initialDelayMs) {
|
||||||
if (DBG) {
|
if (mEnableDebugLog) {
|
||||||
mSharedLog.v("Starting send with id " + id + ", request "
|
mSharedLog.v("Starting send with id " + id + ", request "
|
||||||
+ request.getClass().getSimpleName() + ", delay " + initialDelayMs);
|
+ request.getClass().getSimpleName() + ", delay " + initialDelayMs);
|
||||||
}
|
}
|
||||||
@@ -172,7 +174,7 @@ public abstract class MdnsPacketRepeater<T extends MdnsPacketRepeater.Request> {
|
|||||||
// all in the handler queue; unless this method is called from a message, but the current
|
// all in the handler queue; unless this method is called from a message, but the current
|
||||||
// message cannot be cancelled.
|
// message cannot be cancelled.
|
||||||
if (mHandler.hasMessages(id)) {
|
if (mHandler.hasMessages(id)) {
|
||||||
if (DBG) {
|
if (mEnableDebugLog) {
|
||||||
mSharedLog.v("Stopping send on id " + id);
|
mSharedLog.v("Stopping send on id " + id);
|
||||||
}
|
}
|
||||||
mHandler.removeMessages(id);
|
mHandler.removeMessages(id);
|
||||||
|
|||||||
@@ -40,9 +40,8 @@ public class MdnsProber extends MdnsPacketRepeater<MdnsProber.ProbingInfo> {
|
|||||||
private static final long CONFLICT_RETRY_DELAY_MS = 5_000L;
|
private static final long CONFLICT_RETRY_DELAY_MS = 5_000L;
|
||||||
|
|
||||||
public MdnsProber(@NonNull Looper looper, @NonNull MdnsReplySender replySender,
|
public MdnsProber(@NonNull Looper looper, @NonNull MdnsReplySender replySender,
|
||||||
@NonNull PacketRepeaterCallback<ProbingInfo> cb,
|
@NonNull PacketRepeaterCallback<ProbingInfo> cb, @NonNull SharedLog sharedLog) {
|
||||||
@NonNull SharedLog sharedLog) {
|
super(looper, replySender, cb, sharedLog, MdnsAdvertiser.DBG);
|
||||||
super(looper, replySender, cb, sharedLog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Probing request to send with {@link MdnsProber}. */
|
/** Probing request to send with {@link MdnsProber}. */
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.server.connectivity.mdns;
|
package com.android.server.connectivity.mdns;
|
||||||
|
|
||||||
|
import static com.android.server.connectivity.mdns.MdnsConstants.IPV4_SOCKET_ADDR;
|
||||||
|
import static com.android.server.connectivity.mdns.MdnsConstants.IPV6_SOCKET_ADDR;
|
||||||
import static com.android.server.connectivity.mdns.MdnsConstants.NO_PACKET;
|
import static com.android.server.connectivity.mdns.MdnsConstants.NO_PACKET;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
@@ -79,11 +81,6 @@ public class MdnsRecordRepository {
|
|||||||
private static final String[] DNS_SD_SERVICE_TYPE =
|
private static final String[] DNS_SD_SERVICE_TYPE =
|
||||||
new String[] { "_services", "_dns-sd", "_udp", LOCAL_TLD };
|
new String[] { "_services", "_dns-sd", "_udp", LOCAL_TLD };
|
||||||
|
|
||||||
public static final InetSocketAddress IPV6_ADDR = new InetSocketAddress(
|
|
||||||
MdnsConstants.getMdnsIPv6Address(), MdnsConstants.MDNS_PORT);
|
|
||||||
public static final InetSocketAddress IPV4_ADDR = new InetSocketAddress(
|
|
||||||
MdnsConstants.getMdnsIPv4Address(), MdnsConstants.MDNS_PORT);
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Random mDelayGenerator = new Random();
|
private final Random mDelayGenerator = new Random();
|
||||||
// Map of service unique ID -> records for service
|
// Map of service unique ID -> records for service
|
||||||
@@ -454,37 +451,6 @@ public class MdnsRecordRepository {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Info about a reply to be sent.
|
|
||||||
*/
|
|
||||||
public static class ReplyInfo {
|
|
||||||
@NonNull
|
|
||||||
public final List<MdnsRecord> answers;
|
|
||||||
@NonNull
|
|
||||||
public final List<MdnsRecord> additionalAnswers;
|
|
||||||
public final long sendDelayMs;
|
|
||||||
@NonNull
|
|
||||||
public final InetSocketAddress destination;
|
|
||||||
|
|
||||||
public ReplyInfo(
|
|
||||||
@NonNull List<MdnsRecord> answers,
|
|
||||||
@NonNull List<MdnsRecord> additionalAnswers,
|
|
||||||
long sendDelayMs,
|
|
||||||
@NonNull InetSocketAddress destination) {
|
|
||||||
this.answers = answers;
|
|
||||||
this.additionalAnswers = additionalAnswers;
|
|
||||||
this.sendDelayMs = sendDelayMs;
|
|
||||||
this.destination = destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "{ReplyInfo to " + destination + ", answers: " + answers.size()
|
|
||||||
+ ", additionalAnswers: " + additionalAnswers.size()
|
|
||||||
+ ", sendDelayMs " + sendDelayMs + "}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the reply to send to an incoming packet.
|
* Get the reply to send to an incoming packet.
|
||||||
*
|
*
|
||||||
@@ -492,7 +458,7 @@ public class MdnsRecordRepository {
|
|||||||
* @param src The source address of the incoming packet.
|
* @param src The source address of the incoming packet.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public ReplyInfo getReply(MdnsPacket packet, InetSocketAddress src) {
|
public MdnsReplyInfo getReply(MdnsPacket packet, InetSocketAddress src) {
|
||||||
final long now = SystemClock.elapsedRealtime();
|
final long now = SystemClock.elapsedRealtime();
|
||||||
final boolean replyUnicast = (packet.flags & MdnsConstants.QCLASS_UNICAST) != 0;
|
final boolean replyUnicast = (packet.flags & MdnsConstants.QCLASS_UNICAST) != 0;
|
||||||
final ArrayList<MdnsRecord> additionalAnswerRecords = new ArrayList<>();
|
final ArrayList<MdnsRecord> additionalAnswerRecords = new ArrayList<>();
|
||||||
@@ -543,9 +509,9 @@ public class MdnsRecordRepository {
|
|||||||
if (replyUnicast) {
|
if (replyUnicast) {
|
||||||
dest = src;
|
dest = src;
|
||||||
} else if (src.getAddress() instanceof Inet4Address) {
|
} else if (src.getAddress() instanceof Inet4Address) {
|
||||||
dest = IPV4_ADDR;
|
dest = IPV4_SOCKET_ADDR;
|
||||||
} else {
|
} else {
|
||||||
dest = IPV6_ADDR;
|
dest = IPV6_SOCKET_ADDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the list of answer records from their RecordInfo
|
// Build the list of answer records from their RecordInfo
|
||||||
@@ -559,7 +525,7 @@ public class MdnsRecordRepository {
|
|||||||
answerRecords.add(info.record);
|
answerRecords.add(info.record);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ReplyInfo(answerRecords, additionalAnswerRecords, delayMs, dest);
|
return new MdnsReplyInfo(answerRecords, additionalAnswerRecords, delayMs, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.server.connectivity.mdns;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Info about a mDNS reply to be sent.
|
||||||
|
*/
|
||||||
|
public final class MdnsReplyInfo {
|
||||||
|
@NonNull
|
||||||
|
public final List<MdnsRecord> answers;
|
||||||
|
@NonNull
|
||||||
|
public final List<MdnsRecord> additionalAnswers;
|
||||||
|
public final long sendDelayMs;
|
||||||
|
@NonNull
|
||||||
|
public final InetSocketAddress destination;
|
||||||
|
|
||||||
|
public MdnsReplyInfo(
|
||||||
|
@NonNull List<MdnsRecord> answers,
|
||||||
|
@NonNull List<MdnsRecord> additionalAnswers,
|
||||||
|
long sendDelayMs,
|
||||||
|
@NonNull InetSocketAddress destination) {
|
||||||
|
this.answers = answers;
|
||||||
|
this.additionalAnswers = additionalAnswers;
|
||||||
|
this.sendDelayMs = sendDelayMs;
|
||||||
|
this.destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{MdnsReplyInfo to " + destination + ", answers: " + answers.size()
|
||||||
|
+ ", additionalAnswers: " + additionalAnswers.size()
|
||||||
|
+ ", sendDelayMs " + sendDelayMs + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,6 @@ import android.os.Looper;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
|
||||||
import com.android.net.module.util.SharedLog;
|
import com.android.net.module.util.SharedLog;
|
||||||
import com.android.server.connectivity.mdns.MdnsRecordRepository.ReplyInfo;
|
|
||||||
import com.android.server.connectivity.mdns.util.MdnsUtils;
|
import com.android.server.connectivity.mdns.util.MdnsUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -45,7 +44,6 @@ import java.util.Collections;
|
|||||||
*/
|
*/
|
||||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||||
public class MdnsReplySender {
|
public class MdnsReplySender {
|
||||||
private static final boolean DBG = MdnsAdvertiser.DBG;
|
|
||||||
private static final int MSG_SEND = 1;
|
private static final int MSG_SEND = 1;
|
||||||
private static final int PACKET_NOT_SENT = 0;
|
private static final int PACKET_NOT_SENT = 0;
|
||||||
private static final int PACKET_SENT = 1;
|
private static final int PACKET_SENT = 1;
|
||||||
@@ -58,24 +56,27 @@ public class MdnsReplySender {
|
|||||||
private final byte[] mPacketCreationBuffer;
|
private final byte[] mPacketCreationBuffer;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SharedLog mSharedLog;
|
private final SharedLog mSharedLog;
|
||||||
|
private final boolean mEnableDebugLog;
|
||||||
|
|
||||||
public MdnsReplySender(@NonNull Looper looper, @NonNull MdnsInterfaceSocket socket,
|
public MdnsReplySender(@NonNull Looper looper, @NonNull MdnsInterfaceSocket socket,
|
||||||
@NonNull byte[] packetCreationBuffer, @NonNull SharedLog sharedLog) {
|
@NonNull byte[] packetCreationBuffer, @NonNull SharedLog sharedLog,
|
||||||
|
boolean enableDebugLog) {
|
||||||
mHandler = new SendHandler(looper);
|
mHandler = new SendHandler(looper);
|
||||||
mSocket = socket;
|
mSocket = socket;
|
||||||
mPacketCreationBuffer = packetCreationBuffer;
|
mPacketCreationBuffer = packetCreationBuffer;
|
||||||
mSharedLog = sharedLog;
|
mSharedLog = sharedLog;
|
||||||
|
mEnableDebugLog = enableDebugLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue a reply to be sent when its send delay expires.
|
* Queue a reply to be sent when its send delay expires.
|
||||||
*/
|
*/
|
||||||
public void queueReply(@NonNull ReplyInfo reply) {
|
public void queueReply(@NonNull MdnsReplyInfo reply) {
|
||||||
ensureRunningOnHandlerThread(mHandler);
|
ensureRunningOnHandlerThread(mHandler);
|
||||||
// TODO: implement response aggregation (RFC 6762 6.4)
|
// TODO: implement response aggregation (RFC 6762 6.4)
|
||||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SEND, reply), reply.sendDelayMs);
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SEND, reply), reply.sendDelayMs);
|
||||||
|
|
||||||
if (DBG) {
|
if (mEnableDebugLog) {
|
||||||
mSharedLog.v("Scheduling " + reply);
|
mSharedLog.v("Scheduling " + reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,8 +119,8 @@ public class MdnsReplySender {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(@NonNull Message msg) {
|
public void handleMessage(@NonNull Message msg) {
|
||||||
final ReplyInfo replyInfo = (ReplyInfo) msg.obj;
|
final MdnsReplyInfo replyInfo = (MdnsReplyInfo) msg.obj;
|
||||||
if (DBG) mSharedLog.v("Sending " + replyInfo);
|
if (mEnableDebugLog) mSharedLog.v("Sending " + replyInfo);
|
||||||
|
|
||||||
final int flags = 0x8400; // Response, authoritative (rfc6762 18.4)
|
final int flags = 0x8400; // Response, authoritative (rfc6762 18.4)
|
||||||
final MdnsPacket packet = new MdnsPacket(flags,
|
final MdnsPacket packet = new MdnsPacket(flags,
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ class MdnsAnnouncerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAnnounce() {
|
fun testAnnounce() {
|
||||||
val replySender = MdnsReplySender( thread.looper, socket, buffer, sharedLog)
|
val replySender = MdnsReplySender(
|
||||||
|
thread.looper, socket, buffer, sharedLog, true /* enableDebugLog */)
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val cb = mock(MdnsPacketRepeater.PacketRepeaterCallback::class.java)
|
val cb = mock(MdnsPacketRepeater.PacketRepeaterCallback::class.java)
|
||||||
as MdnsPacketRepeater.PacketRepeaterCallback<BaseAnnouncementInfo>
|
as MdnsPacketRepeater.PacketRepeaterCallback<BaseAnnouncementInfo>
|
||||||
|
|||||||
@@ -190,8 +190,8 @@ class MdnsInterfaceAdvertiserTest {
|
|||||||
fun testReplyToQuery() {
|
fun testReplyToQuery() {
|
||||||
addServiceAndFinishProbing(TEST_SERVICE_ID_1, TEST_SERVICE_1)
|
addServiceAndFinishProbing(TEST_SERVICE_ID_1, TEST_SERVICE_1)
|
||||||
|
|
||||||
val mockReply = mock(MdnsRecordRepository.ReplyInfo::class.java)
|
val testReply = MdnsReplyInfo(emptyList(), emptyList(), 0, InetSocketAddress(0))
|
||||||
doReturn(mockReply).`when`(repository).getReply(any(), any())
|
doReturn(testReply).`when`(repository).getReply(any(), any())
|
||||||
|
|
||||||
// Query obtained with:
|
// Query obtained with:
|
||||||
// scapy.raw(scapy.DNS(
|
// scapy.raw(scapy.DNS(
|
||||||
@@ -216,7 +216,7 @@ class MdnsInterfaceAdvertiserTest {
|
|||||||
assertContentEquals(arrayOf("_testservice", "_tcp", "local"), it.questions[0].name)
|
assertContentEquals(arrayOf("_testservice", "_tcp", "local"), it.questions[0].name)
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(replySender).queueReply(mockReply)
|
verify(replySender).queueReply(testReply)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -119,7 +119,8 @@ class MdnsProberTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testProbe() {
|
fun testProbe() {
|
||||||
val replySender = MdnsReplySender(thread.looper, socket, buffer, sharedLog)
|
val replySender = MdnsReplySender(
|
||||||
|
thread.looper, socket, buffer, sharedLog, true /* enableDebugLog */)
|
||||||
val prober = TestProber(thread.looper, replySender, cb, sharedLog)
|
val prober = TestProber(thread.looper, replySender, cb, sharedLog)
|
||||||
val probeInfo = TestProbeInfo(
|
val probeInfo = TestProbeInfo(
|
||||||
listOf(makeServiceRecord(TEST_SERVICE_NAME_1, 37890)))
|
listOf(makeServiceRecord(TEST_SERVICE_NAME_1, 37890)))
|
||||||
@@ -143,7 +144,8 @@ class MdnsProberTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testProbeMultipleRecords() {
|
fun testProbeMultipleRecords() {
|
||||||
val replySender = MdnsReplySender(thread.looper, socket, buffer, sharedLog)
|
val replySender = MdnsReplySender(
|
||||||
|
thread.looper, socket, buffer, sharedLog, true /* enableDebugLog */)
|
||||||
val prober = TestProber(thread.looper, replySender, cb, sharedLog)
|
val prober = TestProber(thread.looper, replySender, cb, sharedLog)
|
||||||
val probeInfo = TestProbeInfo(listOf(
|
val probeInfo = TestProbeInfo(listOf(
|
||||||
makeServiceRecord(TEST_SERVICE_NAME_1, 37890),
|
makeServiceRecord(TEST_SERVICE_NAME_1, 37890),
|
||||||
@@ -181,7 +183,8 @@ class MdnsProberTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testStopProbing() {
|
fun testStopProbing() {
|
||||||
val replySender = MdnsReplySender(thread.looper, socket, buffer, sharedLog)
|
val replySender = MdnsReplySender(
|
||||||
|
thread.looper, socket, buffer, sharedLog, true /* enableDebugLog */)
|
||||||
val prober = TestProber(thread.looper, replySender, cb, sharedLog)
|
val prober = TestProber(thread.looper, replySender, cb, sharedLog)
|
||||||
val probeInfo = TestProbeInfo(
|
val probeInfo = TestProbeInfo(
|
||||||
listOf(makeServiceRecord(TEST_SERVICE_NAME_1, 37890)),
|
listOf(makeServiceRecord(TEST_SERVICE_NAME_1, 37890)),
|
||||||
|
|||||||
Reference in New Issue
Block a user