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 NeighborUp / NeighborDown notifications (from babel-protocols-common) this protocol emits.

How membership grows

  1. We learn about a first peer — either from auto-discovery (see below) or a configured contact — and open a TCP connection to it.
  2. Once connected, the peer is in our membership and we emit NeighborUp.
  3. Periodically we send a random connected peer a MembershipSampleMessage containing 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 the membership/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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Optional bootstrap contact, used when multicast discovery is unavailable.
    static final String
    Default for PAR_METRICS_INTERVAL: -1 (disabled).
    static final String
    Default for PAR_SAMPLE_SIZE: 6 peers.
    static final String
    Default for PAR_SAMPLE_TIME: 2000 ms (2 s).
    static final String
    If > 0, the period in milliseconds at which the current membership view is written to the log (diagnostics, handy while learning).
    static final String
    Maximum number of peers included in each gossip sample.
    static final String
    Time between gossip rounds, in milliseconds.
    static final short
     
    static final String
     

    Fields inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    babel, babelSecurity
  • Constructor Summary

    Constructors
    Constructor
    Description
    GossipBasedFullMembership(String channelName, Properties props, pt.unl.fct.di.novasys.network.data.Host self)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    pt.unl.fct.di.novasys.network.data.Host
    A peer the runtime can hand to others as a contact (so they can seed off us).
    void
     
    boolean
     
    boolean
     
    void
    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, setMyself

    Methods 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROTOCOL_ID

      public static final short PROTOCOL_ID
      See Also:
    • PROTOCOL_NAME

      public static final String PROTOCOL_NAME
      See Also:
    • PAR_SAMPLE_TIME

      public static final String 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

      public static final String PAR_DEFAULT_SAMPLE_TIME
      Default for PAR_SAMPLE_TIME: 2000 ms (2 s).
      See Also:
    • PAR_SAMPLE_SIZE

      public static final String 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

      public static final String PAR_DEFAULT_SAMPLE_SIZE
      Default for PAR_SAMPLE_SIZE: 6 peers.
      See Also:
    • PAR_CONTACT

      public static final String 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.
      Intentionally has no default constant: the absent case is itself a valid, distinct mode (wait for discovery), so we must be able to tell it apart from an explicit none.
      See Also:
    • PAR_METRICS_INTERVAL

      public static final String 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

      public static final String PAR_DEFAULT_METRICS_INTERVAL
      Default for PAR_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:
      IOException
      pt.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:
      init in class pt.unl.fct.di.novasys.babel.core.GenericProtocol
      Throws:
      pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException
      IOException
    • start

      public void start()
      Called by the runtime once we are ready (have a seed, or are the first node).
      Specified by:
      start in class pt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
    • readyToStart

      public boolean readyToStart()
      Specified by:
      readyToStart in class pt.unl.fct.di.novasys.babel.core.DiscoverableProtocol
    • needsDiscovery

      public boolean needsDiscovery()
      Specified by:
      needsDiscovery in class pt.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:
      addContact in class pt.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:
      getContact in class pt.unl.fct.di.novasys.babel.core.DiscoverableProtocol