/* * 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 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; }
/* * 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(); }
/* * 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 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(); }
/* * 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(); }
/* * 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(); }