[ntcore] Add hidden subscribe option (#6376)

This allows creating subscribers that aren't communicated with the network.
This commit is contained in:
Peter Johnson
2024-02-17 00:40:14 -08:00
committed by GitHub
parent 0cdab55e5b
commit a8a352ed8c
7 changed files with 59 additions and 11 deletions

View File

@@ -15,7 +15,8 @@ public class PubSubOption {
disableRemote,
disableLocal,
excludePublisher,
excludeSelf
excludeSelf,
hidden
}
PubSubOption(Kind kind, boolean value) {
@@ -149,6 +150,18 @@ public class PubSubOption {
return new PubSubOption(Kind.excludeSelf, enabled);
}
/**
* For subscriptions, don't share the existence of the subscription with the network. Note this
* means updates will not be received from the network unless another subscription overlaps with
* this one, and the subscription will not appear in metatopics.
*
* @param enabled True to enable, false to disable
* @return option
*/
public static PubSubOption hidden(boolean enabled) {
return new PubSubOption(Kind.hidden, enabled);
}
final Kind m_kind;
final boolean m_bValue;
final int m_iValue;

View File

@@ -42,6 +42,9 @@ public class PubSubOptions {
case excludeSelf:
excludeSelf = option.m_bValue;
break;
case hidden:
hidden = option.m_bValue;
break;
default:
break;
}
@@ -58,7 +61,8 @@ public class PubSubOptions {
boolean prefixMatch,
boolean disableRemote,
boolean disableLocal,
boolean excludeSelf) {
boolean excludeSelf,
boolean hidden) {
this.pollStorage = pollStorage;
this.periodic = periodic;
this.excludePublisher = excludePublisher;
@@ -69,6 +73,7 @@ public class PubSubOptions {
this.disableRemote = disableRemote;
this.disableLocal = disableLocal;
this.excludeSelf = excludeSelf;
this.hidden = hidden;
}
/** Default value of periodic. */
@@ -123,4 +128,11 @@ public class PubSubOptions {
/** For entries, don't queue (for readQueue) value updates for the entry's internal publisher. */
public boolean excludeSelf;
/**
* For subscriptions, don't share the existence of the subscription with the network. Note this
* means updates will not be received from the network unless another subscription overlaps with
* this one, and the subscription will not appear in metatopics.
*/
public boolean hidden;
}

View File

@@ -611,7 +611,7 @@ LocalStorage::SubscriberData* LocalStorage::Impl::AddLocalSubscriber(
"published as '{}')",
topic->name, config.typeStr, topic->typeStr);
}
if (m_network) {
if (m_network && !subscriber->config.hidden) {
DEBUG4("-> NetworkSubscribe({})", topic->name);
m_network->Subscribe(subscriber->handle, {{topic->name}}, config);
}
@@ -640,7 +640,7 @@ LocalStorage::Impl::RemoveLocalSubscriber(NT_Subscriber subHandle) {
listener.getSecond()->subscriber = nullptr;
}
}
if (m_network) {
if (m_network && !subscriber->config.hidden) {
m_network->Unsubscribe(subscriber->handle);
}
}
@@ -676,7 +676,7 @@ LocalStorage::MultiSubscriberData* LocalStorage::Impl::AddMultiSubscriber(
}
}
}
if (m_network) {
if (m_network && !subscriber->options.hidden) {
DEBUG4("-> NetworkSubscribe");
m_network->Subscribe(subscriber->handle, subscriber->prefixes,
subscriber->options);
@@ -696,7 +696,7 @@ LocalStorage::Impl::RemoveMultiSubscriber(NT_MultiSubscriber subHandle) {
listener.getSecond()->multiSubscriber = nullptr;
}
}
if (m_network) {
if (m_network && !subscriber->options.hidden) {
m_network->Unsubscribe(subscriber->handle);
}
}
@@ -1128,12 +1128,16 @@ void LocalStorage::Impl::StartNetwork(net::NetworkInterface* network) {
}
}
for (auto&& subscriber : m_subscribers) {
network->Subscribe(subscriber->handle, {{subscriber->topic->name}},
subscriber->config);
if (!subscriber->config.hidden) {
network->Subscribe(subscriber->handle, {{subscriber->topic->name}},
subscriber->config);
}
}
for (auto&& subscriber : m_multiSubscribers) {
network->Subscribe(subscriber->handle, subscriber->prefixes,
subscriber->options);
if (!subscriber->options.hidden) {
network->Subscribe(subscriber->handle, subscriber->prefixes,
subscriber->options);
}
}
}

View File

@@ -139,6 +139,7 @@ static nt::PubSubOptions FromJavaPubSubOptions(JNIEnv* env, jobject joptions) {
FIELD(disableRemote, "Z");
FIELD(disableLocal, "Z");
FIELD(excludeSelf, "Z");
FIELD(hidden, "Z");
#undef FIELD
@@ -154,7 +155,8 @@ static nt::PubSubOptions FromJavaPubSubOptions(JNIEnv* env, jobject joptions) {
FIELD(bool, Boolean, prefixMatch),
FIELD(bool, Boolean, disableRemote),
FIELD(bool, Boolean, disableLocal),
FIELD(bool, Boolean, excludeSelf)};
FIELD(bool, Boolean, excludeSelf),
FIELD(bool, Boolean, hidden)};
#undef GET
#undef FIELD

View File

@@ -126,6 +126,7 @@ static PubSubOptions ConvertToCpp(const NT_PubSubOptions* in) {
out.disableRemote = in->disableRemote;
out.disableLocal = in->disableLocal;
out.excludeSelf = in->excludeSelf;
out.hidden = in->hidden;
return out;
}

View File

@@ -367,6 +367,14 @@ struct NT_PubSubOptions {
* internal publisher.
*/
NT_Bool excludeSelf;
/**
* For subscriptions, don't share the existence of the subscription with the
* network. Note this means updates will not be received from the network
* unless another subscription overlaps with this one, and the subscription
* will not appear in metatopics.
*/
NT_Bool hidden;
};
/**

View File

@@ -374,6 +374,14 @@ struct PubSubOptions {
* internal publisher.
*/
bool excludeSelf = false;
/**
* For subscriptions, don't share the existence of the subscription with the
* network. Note this means updates will not be received from the network
* unless another subscription overlaps with this one, and the subscription
* will not appear in metatopics.
*/
bool hidden = false;
};
/**