/// <summary> /// Acknowledges connection attempt /// </summary> /// <param name="peer">Peer</param> /// <param name="newPeer">New peer</param> public void AcknowledgeConnectionAttempt(IInternalLocalPeer peer, IInternalLocalPeer newPeer) { if (peer == null) { throw new ArgumentNullException(nameof(peer)); } if (newPeer == null) { throw new ArgumentNullException(nameof(newPeer)); } if (peer.InternalOwningConnector != this) { throw new ArgumentException("Owning local connector of local peer must be the same instance as the callee.", nameof(peer)); } if (newPeer.TargetConnector != this) { throw new ArgumentException("Target local connector of new local peer must be the same instance as the callee.", nameof(newPeer)); } string key = newPeer.GUID.ToString(); if (!peerPeerLookup.ContainsKey(key)) { peerPeerLookup.Add(key, peer); localPeerConnectionAttemptMessages.Enqueue(new LocalPeerConnectionAttemptMessage(peer)); } }
/// <summary> /// Disconnects a peer /// </summary> /// <param name="peer">Peer</param> public void DisconnectPeer(IInternalLocalPeer peer) { if (peer == null) { throw new ArgumentNullException(nameof(peer)); } if (peer.InternalOwningConnector != this) { throw new ArgumentException("Owning local connector of local peer must be the same instance as the callee.", nameof(peer)); } localPeerDisconnectionMessages.Enqueue(new LocalPeerDisconnectionMessage(peer)); peer.InternalTargetConnector.NotifyPeerDisconnection(peer); }
/// <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); }
/// <summary> /// Notifies peer disconnection /// </summary> /// <param name="peer">Peer</param> public void NotifyPeerDisconnection(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)); } string key = peer.GUID.ToString(); if (peerPeerLookup.ContainsKey(key)) { localPeerDisconnectionMessages.Enqueue(new LocalPeerDisconnectionMessage(peerPeerLookup[key])); } }