示例#1
0
        private static void ProcessSimpleTextMessage(GossipNode node, GossipConnection connection, GossipMessage message)
        {
            var rawMessage = message as RawGossipMessage;

            if (rawMessage == null)
            {
                return;
            }
            if (rawMessage.MessageType == 1)
            {
                Debug.WriteLine(String.Format("Node Info: {0}", node.NodeConfig.Tags.First()));
                Debug.WriteLine(String.Format("Node received: {0}", node.NodeConfig.NodeId.ToHexStringLower()));
                Debug.WriteLine("Message Size: {0} bytes", rawMessage.Size);
                Debug.WriteLine(String.Format("Message String: {0}", Encoding.UTF8.GetString(rawMessage.Buffer)));
            }
        }
        public void describe_connection_with_successful_authentication()
        {
            var clusterConfig = new GossipClusterConfig {
                ClusterKey = Encoding.UTF8.GetBytes("ClusterKey")
            };
            var nodeConfig = new GossipNodeConfig(new IPEndPoint(IPAddress.Loopback, NodePort));

            using (var node = new GossipNode(nodeConfig, clusterConfig))
            {
                var  signal        = new ManualResetEventSlim(false);
                bool?authenticated = null;
                node.OnClientConnectionAuthenticationFailed    += (n, c) => { authenticated = false; signal.Set(); };
                node.OnClientConnectionAuthenticationSucceeded += (n, c) => { authenticated = true; signal.Set(); };
                node.StartListening();
                using (GossipConnection.ConnectAsync(nodeConfig.NodeId, nodeConfig.BindToEndPoint, node.Authenticator, c => signal.Set()))
                {
                    signal.Wait();
                    Assert.That(authenticated == true);
                }
            }
        }
示例#3
0
        private void ProcessInfo(GossipNode node, GossipConnection connection, GossipMessage message)
        {
            var    rawMessage = message as RawGossipMessage;
            string msg        = Encoding.UTF8.GetString(rawMessage.Buffer);

            if (msg == "")
            {
                Console.WriteLine("First Handshake");

                JoinCluster(node.NodeConfig.BindToEndPoint);
                string senMsg = JsonConvert.SerializeObject(RingInfos);

                Gossip.Cluster.BroadcastMessageAsync(new RawGossipMessage(1, Encoding.UTF8.GetBytes(senMsg))).Wait();
            }
            else
            {
                Console.WriteLine("Second Handshake");

                var ringInfos = JsonConvert.DeserializeObject <List <RingInfo> >(msg);

                RingInfos = ringInfos;
            }
        }