private string getMyUserId(ObjectPrx objectPrx)
        {
            HostInformation hostInformation = HostInformation.extractHostInformation(objectPrx.ice_getConnection().ToString());
            string          prefix          = hostInformation != null?hostInformation.getLocalHostAndPort() : "direct_connect_user";

            return(prefix + "|" + uuid);
        }
Example #2
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            HostInformation that = (HostInformation)o;

            if (localHost != null ? !localHost.Equals(that.localHost) : that.localHost != null)
            {
                return(false);
            }
            if (localPort != null ? !localPort.Equals(that.localPort) : that.localPort != null)
            {
                return(false);
            }
            if (remoteHost != null ? !remoteHost.Equals(that.remoteHost) : that.remoteHost != null)
            {
                return(false);
            }
            return(!(remotePort != null ? !remotePort.Equals(that.remotePort) : that.remotePort != null));
        }
        /**
         * Creates a direct connection to the given peer identifier, which, in the case of direct connect, is simply the
         * peer's hostname or IP address.
         */
        public TerkUserPrx connectToPeer(string peerIdentifier)
        {
            log("connectToPeer called");
            peerIdentifier = peerIdentifier.Replace("localhost", "127.0.0.1");

            HostAndPort hostAndPort = createHostAndPort(peerIdentifier);

            if (peerHostAndPortToProxyMap.ContainsKey(hostAndPort))
            {
                throw new DuplicateConnectionException("Already connected to peer [" + hostAndPort + "]");
            }

            log("Not connected... creating new connection");
            TerkUserPrx peerProxy;
            ObjectPrx   objectPrx;

            try
            {
                objectPrx = getPeerProxy(hostAndPort, new Identity(MAIN_SERVANT_PROXY_IDENTITY_NAME, ""));
                if (objectPrx != null)
                {
                    peerProxy = TerkUserPrxHelper.uncheckedCast(objectPrx);

                    peerHostAndPortToProxyMap.Add(hostAndPort, peerProxy);

                    //start pinger
                    pinger = startPinger(new PeerPingerState(hostAndPort, objectPrx, this));
                    peerHostAndPortToPingerMap.Add(hostAndPort, pinger);
                }

                else
                {
                    throw new PeerConnectionFailedException("getPeerProxy() returned null peer proxy for peer [" + hostAndPort + "]");
                }
            }
            catch (Exception e)
            {
                throw new PeerConnectionFailedException("Failed to create connection to peer [" + hostAndPort + "]: " + e);
            }
            HostInformation hostInformation = HostInformation.extractHostInformation(objectPrx.ice_getConnection().ToString());
            string          endpointKey     = objectAdapterName + "." + ENDPOINT_PROPERTY_KEY;
            string          endpointValue   = communicator.getProperties().getProperty(PROTOCOL_PROPERTY_KEY) + " -h " + hostInformation.getLocalHost() + " -p " + hostInformation.getLocalPort();

            communicator.getProperties().setProperty(endpointKey, endpointValue);

            peerProxy.ice_getConnection().setAdapter(addObjectAdapter(getObjectAdapterName()));

            servants = this.servantFactory.createServants(this);

            // notify the peer of the connection
            notifyPeerOfConnection(peerProxy);

            return(peerProxy);
        }