Ejemplo n.º 1
0
        /// <summary>
        /// Registers a connecting peer
        /// </summary>
        /// <param name="peer">Peer</param>
        public void RegisterConnectingPeer(IInternalLocalPeer peer)
        {
            if (peer == null)
            {
                throw new ArgumentNullException(nameof(peer));
            }
            if (peer.InternalTargetConnector != this)
            {
                throw new ArgumentException("Target local connector of local peer must be the same instance as the callee.", nameof(peer));
            }
            IInternalLocalPeer new_peer = new LocalPeer(Guid.NewGuid(), this, peer.InternalOwningConnector);

            peerPeerLookup.Add(peer.GUID.ToString(), new_peer);
            localPeerConnectionAttemptMessages.Enqueue(new LocalPeerConnectionAttemptMessage(new_peer));
            peer.InternalOwningConnector.AcknowledgeConnectionAttempt(peer, new_peer);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connects to a local instance
        /// </summary>
        /// <param name="targetConnector">Target local connector</param>
        /// <returns>Peer</returns>
        public IPeer ConnectToLocal(ILocalConnector targetConnector)
        {
            if (targetConnector == null)
            {
                throw new ArgumentNullException(nameof(targetConnector));
            }
            if (targetConnector == this)
            {
                throw new ArgumentException("Target connector must be of another instance.", nameof(targetConnector));
            }
            if (!(targetConnector is IInternalLocalConnector target_connector))
            {
                throw new ArgumentException($"Target connector does not inherit from \"{ nameof(IInternalLocalConnector) }\".", nameof(target_connector));
            }
            IInternalLocalPeer ret = new LocalPeer(Guid.NewGuid(), this, target_connector);

            target_connector.RegisterConnectingPeer(ret);
            return(ret);
        }