Exemple #1
0
        /// <summary>
        /// Acquires an appropriate event envelope.
        /// </summary>
        /// <returns></returns>
        private static MeshEvent Create(MeshEventType type)
        {
            // Get the appropriate packet
            switch (type)
            {
            case MeshEventType.Error:
            case MeshEventType.Ping:
            case MeshEventType.PingAck:
            case MeshEventType.HandshakeAck:
                return(MeshEvent.Acquire());

            case MeshEventType.Handshake:
                return(MeshHandshake.Acquire());

            case MeshEventType.GossipDigest:
            case MeshEventType.GossipSince:
            case MeshEventType.GossipUpdate:
                return(MeshGossip.Acquire());

            case MeshEventType.Subscribe:
            case MeshEventType.Unsubscribe:
            case MeshEventType.Custom:
                return(MeshEmitterEvent.Acquire());

            default:
                throw new InvalidOperationException("Unknown mesh packet");
            }
        }
Exemple #2
0
 /// <summary>
 /// Handles the command.
 /// </summary>
 /// <param name="channel">The channel sending the command.</param>
 /// <param name="command">The command received.</param>
 private static void OnGossipSince(Connection channel, MeshGossip gossip)
 {
     // We received a gossip request, send them a gossip update since the requested version
     channel.Send(
         MeshGossip.Acquire(Service.Registry.Collection, (ReplicatedVersion)gossip.State)
         );
 }
Exemple #3
0
        /// <summary>
        /// Sends a mesh gossip through the specified channel.
        /// </summary>
        /// <param name="server">The channel to send the mesh gossip to.</param>
        internal static void SendMeshGossipDigest(this IServer server)
        {
            var provider = Service.Providers.Resolve <MeshProvider>();

            if (provider == null)
            {
                return;
            }

            // Compute the digest first
            var digest = Service.Registry.GetMembership().Version.Digest();

            // Send the digest around
            server.Send(MeshGossip.Acquire(digest));
        }
Exemple #4
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="channel">The channel sending the command.</param>
        /// <param name="command">The command received.</param>
        private static void OnGossipDigest(Connection channel, MeshGossip gossip)
        {
            // this message contains a digest
            var digest = (ReplicatedVersionDigest)gossip.State;

            // Do we have the same digest?
            var ourVersion = Service.Registry.Version;
            var ourDigest  = ourVersion.Digest();

            if (ourDigest != digest.Value)
            {
                // Digests didn't match, we should ask for some gossip!
                //Console.WriteLine("Digest: {0} vs {1}", ourDigest, digest.Value);
                channel.Send(
                    MeshGossip.Acquire(ourVersion)
                    );
            }
        }