// internal method to return an existing PeerNode or create a new one with the given settings
        public static PeerNodeImplementation Get(Uri listenUri, Registration registration)
        {
            if (listenUri == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("listenUri");

            if (listenUri.Scheme != PeerStrings.Scheme)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("listenUri", SR.GetString(SR.InvalidUriScheme,
                    listenUri.Scheme, PeerStrings.Scheme));
            }

            // build base uri
            Uri baseUri = new UriBuilder(PeerStrings.Scheme, listenUri.Host).Uri;

            lock (peerNodes)
            {
                PeerNodeImplementation peerNodeImpl = null;
                PeerNodeImplementation peerNode = null;
                if (peerNodes.TryGetValue(baseUri, out peerNode))
                {
                    peerNodeImpl = (PeerNodeImplementation)peerNode;

                    // ensure that the PeerNode is compatible
                    registration.CheckIfCompatible(peerNodeImpl, listenUri);
                    peerNodeImpl.refCount++;
                    return peerNodeImpl;
                }

                // create a new PeerNode, and add it to the dictionary
                peerNodeImpl = registration.CreatePeerNode();
                peerNodes[baseUri] = peerNodeImpl;
                peerNodeImpl.refCount = 1;
                return peerNodeImpl;
            }
        }
 public static PeerNodeImplementation Get(Uri listenUri, Registration registration)
 {
     if (listenUri == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("listenUri");
     }
     if (listenUri.Scheme != "net.p2p")
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("listenUri", System.ServiceModel.SR.GetString("InvalidUriScheme", new object[] { listenUri.Scheme, "net.p2p" }));
     }
     Uri key = new UriBuilder("net.p2p", listenUri.Host).Uri;
     lock (peerNodes)
     {
         PeerNodeImplementation peerNode = null;
         PeerNodeImplementation implementation2 = null;
         if (peerNodes.TryGetValue(key, out implementation2))
         {
             peerNode = implementation2;
             registration.CheckIfCompatible(peerNode, listenUri);
             peerNode.refCount++;
             return peerNode;
         }
         peerNode = registration.CreatePeerNode();
         peerNodes[key] = peerNode;
         peerNode.refCount = 1;
         return peerNode;
     }
 }