Package protocols.membership.full
Class GossipBasedFullMembership
java.lang.Object
pt.unl.fct.di.novasys.babel.core.GenericProtocol
pt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
protocols.membership.full.GossipBasedFullMembership
public class GossipBasedFullMembership
extends pt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
Gossip-based full membership: every node tries to stay connected to
every other node. It is the foundation the broadcast and chat protocols build
on — they never deal with connections themselves; they just listen for the
shared Auto-discovery — why this extends
Rather than demanding a hard-coded contact, we let Babel's runtime find peers
for us. By extending
NeighborUp / NeighborDown notifications (from
babel-protocols-common) this protocol emits.
How membership grows
- We learn about a first peer — either from auto-discovery (see below) or a
configured
contact— and open a TCP connection to it. - Once connected, the peer is in our membership and we emit
NeighborUp. - Periodically we send a random connected peer a
MembershipSampleMessagecontaining a sample of who we know (plus ourselves). The receiver opens connections to any peers it didn't already know. Over a few rounds, everyone learns about (and connects to) everyone.
Auto-discovery — why this extends DiscoverableProtocol
Rather than demanding a hard-coded contact, we let Babel's runtime find peers
for us. By extending DiscoverableProtocol and implementing its hooks
(readyToStart(), needsDiscovery(), addContact(Host),
getContact(), start()), the runtime's multicast discovery
service announces our channel on the LAN and hands us a contact automatically.
Where multicast isn't available, the contact property is the fallback
(the same pattern HyParView uses):
contact=none→ I'm the first node; start immediately.contact=host:port→ seed directly from that node.- (absent) → wait passively for discovery to provide a contact.
Threading
Every handler here runs on this protocol's single Babel event-loop thread, so themembership/pending sets need no locking.-
Nested Class Summary
Nested classes/interfaces inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol
pt.unl.fct.di.novasys.babel.core.GenericProtocol.ProtocolMetricsBabelMetrics -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringOptional bootstrap contact, used when multicast discovery is unavailable.static final StringDefault forPAR_METRICS_INTERVAL:-1(disabled).static final StringDefault forPAR_SAMPLE_SIZE: 6 peers.static final StringDefault forPAR_SAMPLE_TIME: 2000 ms (2 s).static final StringIf > 0, the period in milliseconds at which the current membership view is written to the log (diagnostics, handy while learning).static final StringMaximum number of peers included in each gossip sample.static final StringTime between gossip rounds, in milliseconds.static final shortstatic final StringFields inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol
babel, babelSecurity -
Constructor Summary
ConstructorsConstructorDescriptionGossipBasedFullMembership(String channelName, Properties props, pt.unl.fct.di.novasys.network.data.Host self) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContact(pt.unl.fct.di.novasys.network.data.Host host) The runtime (or our own contact bootstrap) calls this with a peer to join through.pt.unl.fct.di.novasys.network.data.HostA peer the runtime can hand to others as a contact (so they can seed off us).voidinit(Properties props) booleanbooleanvoidstart()Called by the runtime once we are ready (have a seed, or are the first node).Methods inherited from class pt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
getMyself, isDiscoverable, setMyselfMethods inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol
addSecret, addSecret, addSecret, addSecret, cancelTimer, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, createChannel, createSecureChannel, createSecureChannel, createSecureChannel, createSecureChannelWithAliases, createSecureChannelWithAliases, createSecureChannelWithIdentities, createSecureChannelWithIdentities, createSecureChannelWithProtoIdentities, enableGenericMetrics, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateSecret, generateSecret, generateSecret, generateSecret, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, getChannelOrThrow, getDefaultChannel, getDefaultProtoIdentity, getDefaultProtoIdentityCrypt, getDefaultProtoSecret, getMillisSinceBabelStart, getOrGenerateDefaultProtoIdentity, getProtoId, getProtoName, hasProtocolThreadStarted, openConnection, openConnection, openConnection, openConnection, registerChannelEventHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageSerializer, registerMetric, registerReplyHandler, registerRequestHandler, registerSharedChannel, registerTimerHandler, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendReply, sendRequest, setDefaultChannel, setDefaultProtoIdentity, setDefaultProtoIdentity, setDefaultProtoSecret, setupPeriodicTimer, setupTimer, startEventThread, subscribeNotification, triggerNotification, unsubscribeNotification
-
Field Details
-
PROTOCOL_ID
public static final short PROTOCOL_ID- See Also:
-
PROTOCOL_NAME
- See Also:
-
PAR_SAMPLE_TIME
Time between gossip rounds, in milliseconds. On each round we send one random neighbour a sample of the peers we know about; lower values make the membership converge faster at the cost of more traffic.- See Also:
-
PAR_DEFAULT_SAMPLE_TIME
Default forPAR_SAMPLE_TIME: 2000 ms (2 s).- See Also:
-
PAR_SAMPLE_SIZE
Maximum number of peers included in each gossip sample. Larger samples spread knowledge faster but produce bigger messages.- See Also:
-
PAR_DEFAULT_SAMPLE_SIZE
Default forPAR_SAMPLE_SIZE: 6 peers.- See Also:
-
PAR_CONTACT
Optional bootstrap contact, used when multicast discovery is unavailable. Three forms:none— this is the first node; start immediately;host:port— seed by connecting to that existing node;- (absent) — wait passively for discovery to provide a contact.
none.- See Also:
-
PAR_METRICS_INTERVAL
If > 0, the period in milliseconds at which the current membership view is written to the log (diagnostics, handy while learning). Disabled otherwise.- See Also:
-
PAR_DEFAULT_METRICS_INTERVAL
Default forPAR_METRICS_INTERVAL:-1(disabled).- See Also:
-
-
Constructor Details
-
GossipBasedFullMembership
public GossipBasedFullMembership(String channelName, Properties props, pt.unl.fct.di.novasys.network.data.Host self) throws IOException, pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException - Throws:
IOExceptionpt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException
-
-
Method Details
-
init
public void init(Properties props) throws pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException, IOException - Specified by:
initin classpt.unl.fct.di.novasys.babel.core.GenericProtocol- Throws:
pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationExceptionIOException
-
start
public void start()Called by the runtime once we are ready (have a seed, or are the first node).- Specified by:
startin classpt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
-
readyToStart
public boolean readyToStart()- Specified by:
readyToStartin classpt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
-
needsDiscovery
public boolean needsDiscovery()- Specified by:
needsDiscoveryin classpt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
-
addContact
public void addContact(pt.unl.fct.di.novasys.network.data.Host host) The runtime (or our own contact bootstrap) calls this with a peer to join through.- Specified by:
addContactin classpt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
-
getContact
public pt.unl.fct.di.novasys.network.data.Host getContact()A peer the runtime can hand to others as a contact (so they can seed off us).- Specified by:
getContactin classpt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
-