Beispiel #1
0
        /// <summary>
        /// Broadcast message to all connected peers
        /// </summary>
        /// <param name="distributedMessage">Message to be sent</param>
        public void BroadcastMessage(DistributedMessage distributedMessage)
        {
            var id = idsRegister.ResolveId(distributedMessage.AddressKey);

            if (id != null)
            {
                idsRegister.PushId(distributedMessage);
                TimeManager.PushTimeDifference(distributedMessage);
                connectionManager.Broadcast(distributedMessage);
                return;
            }

            //Hold message until proper sender registers
            var key = distributedMessage.AddressKey;

            if (!awaitingOutgoingMessages.TryGetValue(key, out var messages))
            {
                messages = new List <AwaitingMessage>();
                awaitingOutgoingMessages.Add(key, messages);
            }

            var awaitingMessage = new AwaitingMessage()
            {
                EndPoint           = new IPEndPoint(IPAddress.Broadcast, connectionManager.Port),
                DistributedMessage = distributedMessage
            };

            messages.Add(awaitingMessage);
        }
Beispiel #2
0
        /// <summary>
        /// Broadcast message to all connected peers
        /// </summary>
        /// <param name="distributedMessage">Message to be sent</param>
        public void BroadcastMessage(DistributedMessage distributedMessage)
        {
            //Check if this message is forwarded, then don't send it back to the sender
            var connectedPeers = connectionManager.ConnectedPeers;

            if (connectedPeers.ContainsValue(distributedMessage.Sender))
            {
                foreach (var connectedPeer in connectedPeers)
                {
                    if (connectedPeer.Value != distributedMessage.Sender)
                    {
                        //Unicast a message copy to every peer excluding the sender
                        UnicastMessage(connectedPeer.Key, new DistributedMessage(distributedMessage));
                    }
                }

                return;
            }

            var id = idsRegister.ResolveId(distributedMessage.AddressKey);

            if (id != null)
            {
                idsRegister.PushId(distributedMessage);
                TimeManager.PushTimeDifference(distributedMessage);
                connectionManager.Broadcast(distributedMessage);
                return;
            }

            //Hold message until proper sender registers
            var key = distributedMessage.AddressKey;

            if (!awaitingOutgoingMessages.TryGetValue(key, out var messages))
            {
                messages = new List <AwaitingMessage>();
                awaitingOutgoingMessages.Add(key, messages);
            }

            var awaitingMessage = new AwaitingMessage()
            {
                EndPoint           = new IPEndPoint(IPAddress.Broadcast, connectionManager.Port),
                DistributedMessage = distributedMessage
            };

            messages.Add(awaitingMessage);
        }