예제 #1
0
        internal void MeshNetworkRequest(Connection connection, BinaryNumber networkId, Stream channel)
        {
            MeshNetwork network = null;

            lock (_networks)
            {
                if (_networks.ContainsKey(networkId))
                {
                    network = _networks[networkId];
                }
            }

            if (network == null)
            {
                if (!networkId.Equals(_maskedUserId))
                {
                    //no network found
                    channel.Dispose();
                    return;
                }

                //private network connection invitation attempt
                if (!_allowInboundInvitations || (_allowOnlyLocalInboundInvitations && ((connection.RemotePeerEP.AddressFamily == AddressFamily.Unspecified) || !NetUtilities.IsPrivateIP((connection.RemotePeerEP as IPEndPoint).Address))))
                {
                    //not allowed
                    channel.Dispose();
                    return;
                }

                //accept invitation
                network = MeshNetwork.AcceptPrivateNetworkInvitation(_connectionManager, connection, channel);

                //add network
                lock (_networks)
                {
                    _networks.Add(network.NetworkId, network);
                }

                //notify UI
                RaiseEventInvitationReceived(network);
            }
            else
            {
                network.AcceptConnectionAndJoinNetwork(connection, channel);
            }
        }