/// <summary>
 /// Initializes a new instance of the <see cref="ConnectionParameters"/> class.
 /// </summary>
 /// <param name="otpSelf">The otp self.</param>
 /// <param name="otpPeer">The otp peer.</param>
 /// <remarks></remarks>
 public ConnectionParameters(OtpSelf otpSelf, OtpPeer otpPeer)
 {
     AssertUtils.ArgumentNotNull(otpSelf, "OtpSelf must be non-null");
     AssertUtils.ArgumentNotNull(otpPeer, "OtpPeer must be non-null");
     this.otpSelf = otpSelf;
     this.otpPeer = otpPeer;
 }
        public void AfterPropertiesSet()
        {
            AssertUtils.IsTrue(this.selfNodeName != null || this.peerNodeName != null,
                               "'selfNodeName' or 'peerNodeName' is required");
            if (this.cookie == null)
            {
                this.otpSelf = new OtpSelf(this.selfNodeName);
            }
            else
            {
                this.otpSelf = new OtpSelf(this.selfNodeName, this.cookie);
            }

            this.otpPeer = new OtpPeer(this.peerNodeName);
        }
        public void TestRawApi()
        {
            var self = new OtpSelf("rabbit-monitor");

            var hostName = NODE_NAME;
            var peer = new OtpPeer(hostName);
            this.connection = self.connect(peer);

            var encoding = new UTF8Encoding();
            OtpErlangObject[] objectArray = { new OtpErlangBinary(encoding.GetBytes("/")) };

            this.connection.sendRPC("rabbit_amqqueue", "info_all", new OtpErlangList(objectArray));

            var received = this.connection.receiveRPC();
            Logger.Info(received);
            Logger.Info(received.GetType().ToString());
        }
Example #4
0
        /*
         * find or create a connection to the given node
         */
        public OtpCookedConnection getConnection(String node)
        {
            OtpPeer peer = null;
            OtpCookedConnection conn = null;

            lock (connections)
            {
                // first just try looking up the name as-is

                if (connections.ContainsKey(node))
                {
                    conn = connections[node];
                }
                else
                {
                    // in case node had no '@' add localhost info and try again
                    peer = new OtpPeer(node);

                    if (connections.ContainsKey(peer.Node))
                    {
                        conn = connections[peer.Node];
                    }
                    else
                    {
                        try
                        {
                            conn = new OtpCookedConnection(this, peer);
                            conn.setFlags(flags);
                            addConnection(conn);
                        }
                        catch (Exception e)
                        {
                            /* false = outgoing */
                            connAttempt(peer.Node, false, e);
                        }
                    }
                }
                return conn;
            }
        }
        /// <summary>
        /// Afters the properties set.
        /// </summary>
        /// <remarks></remarks>
        public void AfterPropertiesSet()
        {
            AssertUtils.IsTrue(this.selfNodeName != null || this.peerNodeName != null, "'selfNodeName' or 'peerNodeName' is required");

            var selfNodeNameToUse = this.selfNodeName;
            selfNodeNameToUse = string.IsNullOrEmpty(selfNodeNameToUse) ? string.Empty : selfNodeNameToUse;
            if (this.UniqueSelfNodeName)
            {
                selfNodeNameToUse = this.selfNodeName + "-" + Guid.NewGuid().ToString();
                this.logger.Debug("Creating OtpSelf with node name = [" + selfNodeNameToUse + "]");
            }

            try
            {
                if (StringUtils.HasText(this.cookie))
                {
                    this.otpSelf = new OtpSelf(selfNodeNameToUse.Trim(), this.cookie);
                }
                else
                {
                    this.otpSelf = new OtpSelf(selfNodeNameToUse.Trim());
                }
            }
            catch (IOException e)
            {
                throw new OtpIOException(e);
            }

            this.otpPeer = new OtpPeer(string.IsNullOrEmpty(this.peerNodeName) ? string.Empty : this.peerNodeName.Trim());
        }
Example #6
0
 /**
  * Open a connection to a remote node.
  * 
  * @param other
  *                the remote node to which you wish to connect.
  * 
  * @return a connection to the remote node.
  * 
  * @exception java.net.UnknownHostException
  *                    if the remote host could not be found.
  * 
  * @exception java.io.IOException
  *                    if it was not possible to connect to the remote node.
  * 
  * @exception OtpAuthException
  *                    if the connection was refused by the remote node.
  */
 public OtpConnection connect(OtpPeer other)
 {
     return new OtpConnection(this, other);
 }
 /// <summary>Creates the connection.</summary>
 /// <returns>The Erlang.NET.OtpConnection.</returns>
 public OtpConnection CreateConnection()
 {
     var self = new OtpSelf("rabbit-monitor-" + counter++);
     var peer = new OtpPeer(NODE_NAME);
     return self.connect(peer);
 }
 /*
  * Intiate and open a connection to a remote node.
  *
  * @exception java.io.IOException if it was not possible to connect to the
  * peer.
  *
  * @exception OtpAuthException if handshake resulted in an authentication
  * error.
  */
 // package scope
 internal OtpCookedConnection(OtpNode self, OtpPeer other)
     : base(self, other)
 {
     this.self = self;
     links = new Links(25);
     start();
 }
        /**
         * Intiate and open a connection to a remote node.
         *
         * @exception java.io.IOException if it was not possible to connect to the
         * peer.
         *
         * @exception OtpAuthException if handshake resulted in an authentication
         * error.
         */
        protected AbstractConnection(OtpLocalNode self, OtpPeer other)
            : base("receive", true)
        {
            peer = other;
            this.self = self;
            socket = null;
            int port;

            traceLevel = defaultLevel;

            // now get a connection between the two...
            port = OtpEpmd.lookupPort(peer);

            // now find highest common dist value
            if (peer.Proto != self.Proto || self.DistHigh < peer.DistLow || self.DistLow > peer.DistHigh)
            {
                throw new IOException("No common protocol found - cannot connect");
            }

            // highest common version: min(peer.distHigh, self.distHigh)
            peer.DistChoose = peer.DistHigh > self.DistHigh ? self.DistHigh : peer.DistHigh;

            doConnect(port);

            name = peer.Node;
            connected = true;
        }
        /**
         * Accept an incoming connection from a remote node. Used by {@link
         * OtpSelf#accept() OtpSelf.accept()} to create a connection based on data
         * received when handshaking with the peer node, when the remote node is the
         * connection intitiator.
         *
         * @exception java.io.IOException if it was not possible to connect to the
         * peer.
         *
         * @exception OtpAuthException if handshake resulted in an authentication
         * error
         */
        protected AbstractConnection(OtpLocalNode self, BufferedTcpClient s)
            : base("receive", true)
        {
            this.self = self;
            peer = new OtpPeer();
            socket = s;

            traceLevel = defaultLevel;

            if (traceLevel >= handshakeThreshold)
            {
                log.Debug("<- ACCEPT FROM " + s.Client.RemoteEndPoint);
            }

            // get his info
            recvName(peer);

            // now find highest common dist value
            if (peer.Proto != self.Proto || self.DistHigh < peer.DistLow || self.DistLow > peer.DistHigh)
            {
                close();
                throw new IOException("No common protocol found - cannot accept connection");
            }
            // highest common version: min(peer.distHigh, self.distHigh)
            peer.DistChoose = peer.DistHigh > self.DistHigh ? self.DistHigh : peer.DistHigh;

            doAccept();
            name = peer.Node;
        }
        protected void recvName(OtpPeer peer)
        {
            String hisname = "";

            try
            {
                byte[] tmpbuf = read2BytePackage();
                OtpInputStream ibuf = new OtpInputStream(tmpbuf, 0);
                byte[] tmpname;
                int len = tmpbuf.Length;
                peer.Type = ibuf.read1();
                if (peer.Type != AbstractNode.NTYPE_R6)
                {
                    throw new IOException("Unknown remote node type");
                }
                peer.DistLow = peer.DistHigh = ibuf.read2BE();
                if (peer.DistLow < 5)
                {
                    throw new IOException("Unknown remote node type");
                }
                peer.Flags = ibuf.read4BE();
                tmpname = new byte[len - 7];
                ibuf.readN(tmpname);
                hisname = OtpErlangString.newString(tmpname);
                // Set the old nodetype parameter to indicate hidden/normal status
                // When the old handshake is removed, the ntype should also be.
                if ((peer.Flags & AbstractNode.dFlagPublished) != 0)
                {
                    peer.Type = AbstractNode.NTYPE_R4_ERLANG;
                }
                else
                {
                    peer.Type = AbstractNode.NTYPE_R4_HIDDEN;
                }

                if ((peer.Flags & AbstractNode.dFlagExtendedReferences) == 0)
                {
                    throw new IOException("Handshake failed - peer cannot handle extended references");
                }

                if ((peer.Flags & AbstractNode.dFlagExtendedPidsPorts) == 0)
                {
                    throw new IOException("Handshake failed - peer cannot handle extended pids and ports");
                }
            }
            catch (OtpErlangDecodeException)
            {
                throw new IOException("Handshake failed - not enough data");
            }

            int i = hisname.IndexOf('@', 0);
            peer.Node = hisname;
            peer.Alive = hisname.Substring(0, i);
            peer.Host = hisname.Substring(i + 1, hisname.Length - (i + 1));

            if (traceLevel >= handshakeThreshold)
            {
                log.Debug("<- " + "HANDSHAKE" + " ntype=" + peer.Type
                             + " dist=" + peer.DistHigh + " remote=" + peer);
            }
        }
Example #12
0
 /*
  * Intiate and open a connection to a remote node.
  * 
  * @exception java.io.IOException if it was not possible to connect to the
  * peer.
  * 
  * @exception OtpAuthException if handshake resulted in an authentication
  * error.
  */
 // package scope
 internal OtpConnection(OtpSelf self, OtpPeer other)
     : base(self, other)
 {
     this.self = self;
     queue = new GenericQueue();
     start();
 }