/* * find or create a connection to the given node */ public virtual OtpCookedConnection connection(System.String node) { OtpPeer peer = null; OtpCookedConnection conn = null; lock (connections) { // first just try looking up the name as-is conn = (OtpCookedConnection)connections[node]; if (conn == null) { // in case node had no '@' add localhost info and try again peer = new OtpPeer(node); conn = (OtpCookedConnection)connections[peer.node()]; if (conn == null) { try { conn = new OtpCookedConnection(this, peer); addConnection(conn); } catch (System.Exception e) { /*false = outgoing */ connAttempt(peer.node(), false, e); } } } return(conn); } }
/* * Intiate and open a connection to a remote node. * * @exception C#.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; this.queue = new GenericQueue(); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Start)); t.IsBackground = true; t.Name = "connection2 " + self.node() + " -> " + other.node(); t.Start(); }
/* * Intiate and open a connection to a remote node. * * @exception C#.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; this.queue = new GenericQueue(); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Start)); t.IsBackground = true; t.Name = "connection2 "+self.node()+" -> "+other.node(); t.Start(); }
/* * Intiate and open a connection to a remote node. * * @exception C#.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; this.links = new Links(25); this.monitors = new System.Collections.Hashtable(49, (float)0.95); thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start)); thread.IsBackground = true; thread.Name = "cooked connection2 " + self.node() + "->" + other.node(); thread.Start(); }
/* * Intiate and open a connection to a remote node. * * @exception C#.io.IOException if it was not possible to connect to the peer. * @exception OtpAuthException if handshake resulted in an authentication error. */ protected internal AbstractConnection(OtpLocalNode self, OtpPeer other, string cookie) { this.peer = other; this.self = self; this.socket = null; this.auth_cookie = cookie; //this.IsBackground = true; // now get a connection between the two... int 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 System.IO.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); this.name = peer.node(); this.connected = true; }
/* * Intiate and open a connection to a remote node. * * @exception C#.io.IOException if it was not possible to connect to the peer. * @exception OtpAuthException if handshake resulted in an authentication error. */ protected internal AbstractConnection(OtpLocalNode self, OtpPeer other) : this(self, other, self.cookie()) { }
protected internal virtual void recvName(OtpPeer peer) { System.String hisname = ""; try { byte[] tmpbuf = read2BytePackage(); OtpInputStream ibuf = new OtpInputStream(tmpbuf); byte[] tmpname; int len = (int) (tmpbuf.Length); peer.ntype = ibuf.read1(); if (peer.ntype != AbstractNode.NTYPE_R6) { throw new System.IO.IOException("Unknown remote node type"); } peer._distLow = (peer._distHigh = ibuf.read2BE()); if (peer._distLow < 5) { throw new System.IO.IOException("Unknown remote node type"); } peer.flags = ibuf.read4BE(); tmpname = new byte[len - 7]; ibuf.readN(tmpname); char[] tmpChar; tmpChar = new char[tmpname.Length]; tmpname.CopyTo(tmpChar, 0); hisname = new System.String(tmpChar); // 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.ntype = AbstractNode.NTYPE_R4_ERLANG; else peer.ntype = AbstractNode.NTYPE_R4_HIDDEN; if ((peer.flags & AbstractNode.dFlagExtendedReferences) == 0) { throw new System.IO.IOException("Handshake failed - peer cannot handle extended references"); } if (OtpSystem.useExtendedPidsPorts() && (peer.flags & AbstractNode.dFlagExtendedPidsPorts) == 0) if (true && (peer.flags & AbstractNode.dFlagExtendedPidsPorts) == 0) { throw new System.IO.IOException("Handshake failed - peer cannot handle extended pids and ports"); } } catch (Erlang.Exception) { throw new System.IO.IOException("Handshake failed - not enough data"); } int i = hisname.IndexOf((System.Char) '@', 0); peer._node = hisname; peer._alive = hisname.Substring(0, (i) - (0)); peer._host = hisname.Substring(i + 1, (hisname.Length) - (i + 1)); if (traceLevel >= OtpTrace.Type.handshakeThreshold) { OtpTrace.TraceEvent("<- " + "HANDSHAKE" + " ntype=" + peer.ntype + " dist=" + peer._distHigh + " remote=" + peer); } }
/* * 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 C#.io.IOException if it was not possible to connect to the peer. * @exception OtpAuthException if handshake resulted in an authentication error */ protected internal AbstractConnection(OtpLocalNode self, System.Net.Sockets.TcpClient s) { this.self = self; this.peer = new OtpPeer(); this.socket = s; this.auth_cookie = self.cookie(); this.socket.NoDelay = true; // Use keepalive timer this.socket.Client.SetSocketOption( System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.KeepAlive, true); // Close socket gracefully this.socket.Client.SetSocketOption( System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.DontLinger, true); //this.socket.ReceiveTimeout = 5000; if (traceLevel >= OtpTrace.Type.handshakeThreshold) { OtpTrace.TraceEvent("<- ACCEPT FROM " + System.Net.IPAddress.Parse(s.Client.RemoteEndPoint.ToString()).ToString() + ":" + (s.Client.RemoteEndPoint as System.Net.IPEndPoint).Port.ToString()); } // get his info recvName(this.peer); // now find highest common dist value if ((peer._proto != self._proto) || (self._distHigh < peer._distLow) || (self._distLow > peer._distHigh)) { close(); throw new System.IO.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(); this.name = peer.node(); }
private AbstractConnection(OtpLocalNode self, OtpPeer peer, System.Net.Sockets.TcpClient s, string cookie) { this.peer = peer; this.self = self; this.socket = s; this.auth_cookie = cookie ?? self._cookie; this.sentBytes = 0; this.receivedBytes = 0; this.maxPayloadLength = defaultMaxPayloadLength; }
/* * 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 C#.net.UnknownHostException if the remote host could * not be found. * * @exception C#.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 virtual OtpConnection connect(OtpPeer other) { return(new OtpConnection(this, other)); }
/* * Intiate and open a connection to a remote node. * * @exception C#.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, string cookie) : base(self, other, cookie) { this.self = self; this.links = new Links(25); this.monitors = new System.Collections.Hashtable(49, (float)0.95); thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start)); thread.IsBackground = true; thread.Name = "cooked connection2 "+self.node()+"->"+other.node(); thread.Start(); }
/* * find or create a connection to the given node */ public virtual OtpCookedConnection connection(System.String node, string cookie) { OtpPeer peer = null; OtpCookedConnection conn = null; lock(connections) { // first just try looking up the name as-is conn = (OtpCookedConnection) connections[node]; if (conn == null) { // in case node had no '@' add localhost info and try again peer = new OtpPeer(node, _useShortName); conn = (OtpCookedConnection) connections[peer.node()]; if (conn == null) { try { conn = new OtpCookedConnection(this, peer, cookie); addConnection(conn); } catch (System.Exception e) { /*false = outgoing */ connAttempt(peer.node(), false, e); } } } return conn; } }
/* * Intiate and open a connection to a remote node. * * @exception C#.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) : this(self, other, self.cookie()) { }
/* * 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 C#.io.IOException if it was not possible to connect to the peer. * @exception OtpAuthException if handshake resulted in an authentication error */ protected internal AbstractConnection(OtpLocalNode self, System.Net.Sockets.TcpClient s) { this.self = self; this.peer = new OtpPeer(); this.socket = s; this.socket.NoDelay = true; this.traceLevel = defaultLevel; if (traceLevel >= handshakeThreshold) { System.Console.Out.WriteLine("<- ACCEPT FROM ?"); /* System.Net.Sockets.Socket sock = s.Client; //UPGRADE_TODO: Expression C#.net.Socket.getInetAddress could not be converted.; //UPGRADE_TODO: Expression C#.net.Socket.getPort could not be converted.; System.Console.Out.WriteLine("<- ACCEPT FROM " + IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString())+ ":" + ((IPEndPoint)s.RemoteEndPoint).Port.ToString()); */ } // get his info recvName(this.peer); // now find highest common dist value if ((peer._proto != self._proto) || (self._distHigh < peer._distLow) || (self._distLow > peer._distHigh)) { close(); throw new System.IO.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(); this.name = peer.node(); }
/* * 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 C#.net.UnknownHostException if the remote host could * not be found. * * @exception C#.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 virtual OtpConnection connect(OtpPeer other) { return new OtpConnection(this, other); }
/* * Intiate and open a connection to a remote node. * * @exception C#.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; this.links = new Links(25); thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start)); thread.IsBackground = true; thread.Name = "cooked connection2 "+self.node()+"->"+other.node(); thread.Start(); }