private void sendBuf(ErlTuple ctrl, ErlOutputStream payload = null) { if (!m_Connected) { throw new ErlException(StringConsts.ERL_CONN_NOT_CONNECTED_ERROR); } var header = new ErlOutputStream(writeVersion: false, capacity: HEADER_LEN); // preamble: 4 byte length + "PASS_THROUGH" tag + version header.Write4BE(0); // reserve space for length header.Write1(PASS_THROUGH); header.Write1((byte)ErlExternalTag.Version); // header info header.WriteTuple(ctrl); // version for payload //header.Write1((byte)ErlExternalTag.Version); // Note that it's already written in the payload if (payload == null) { header.Poke4BE(0, (int)(header.Length - 4)); DoSend(header); } else { header.Poke4BE(0, (int)(header.Length + payload.Length - 4)); DoSend(header, payload); } }
private void sendChallenge(int dist, ErlAbstractNode.NodeCompatibility flags, int challenge) { ErlAtom str = m_Home.NodeName; var obuf = new ErlOutputStream(writeVersion: false, writePktSize: false, capacity: 11 + str.Length); obuf.Write2BE((short)str.Length + 11); // 11 bytes + nodename obuf.Write1((byte)ErlAbstractNode.NodeType.Ntype_R6); obuf.Write2BE((short)dist); obuf.Write4BE((int)flags); obuf.Write4BE(challenge); obuf.Write(Encoding.ASCII.GetBytes(str.Value)); obuf.WriteTo(m_TcpClient.GetStream()); m_Home.OnTrace(ErlTraceLevel.Handshake, Direction.Outbound, () => "sendChallenge(flags({0:X2})={1}, dist={2}, challenge={3}, local={4}".Args( (int)flags, flags, dist, challenge, m_Home.AliveName)); }
private void sendChallengeReply(int challenge, byte[] digest) { var obuf = new ErlOutputStream(writeVersion: false, writePktSize: false, capacity: 23); obuf.Write2BE(21); obuf.Write1(CHALLENGE_REPLY); obuf.Write4BE(challenge); obuf.Write(digest); obuf.WriteTo(m_TcpClient.GetStream()); m_Home.OnTrace(ErlTraceLevel.Handshake, Direction.Outbound, () => "sendChallengeReply(challenge={0}, digest={1}, local={2}".Args( challenge, hex(digest), m_Home.NodeName.Value)); }
private void sendName(int dist, ErlAbstractNode.NodeCompatibility flags) { string str = m_Home.NodeName.Value; var obuf = new ErlOutputStream(writeVersion: false, writePktSize: false, capacity: 7 + str.Length); obuf.Write2BE(str.Length + 7); // 7 bytes + nodename obuf.Write1((int)ErlAbstractNode.NodeType.Ntype_R6); obuf.Write2BE((short)dist); obuf.Write4BE((int)flags); obuf.Write(Encoding.ASCII.GetBytes(str)); obuf.WriteTo(m_Transport.GetStream()); m_Home.OnTrace(ErlTraceLevel.Handshake, Direction.Outbound, () => "sendName(flags({0:X2})={1}, dist={2}, local={3}".Args( (int)flags, flags, dist, m_Home.AliveName)); }
/// <summary> /// Send an auth error to peer because he sent a bad cookie /// The auth error uses his cookie (not revealing ours). /// This is just like send_reg otherwise /// </summary> private void cookieError(ErlLocalNode local, ErlAtom cookie) { var header = new ErlOutputStream(writeVersion: false, capacity: HEADER_LEN); // preamble: 4 byte length + "PASS_THROUGH" tag + version header.Write4BE(0); // reserve space for length header.Write1(PASS_THROUGH); header.Write1((byte)ErlExternalTag.Version); header.WriteTupleHead(4); header.WriteLong((long)ErlMsg.Tag.RegSend); header.WritePid(local.CreatePid()); // disposable pid header.WriteAtom(cookie); // important: his cookie, not mine... header.WriteAtom("auth"); // version for payload written later by the payload stream //header.Write1((byte)ErlExternalTag.Version); // the payload // the no_auth message (copied from Erlang) Don't change this (Erlang will crash) // {$gen_cast, {print, "~n** Unauthorized cookie ~w **~n", [foo@aule]}} var msg = ErlObject.Parse( "{'$gen_cast', {print, \"\n** Unauthorized cookie ~w **\n\", [" + local.NodeName.Value + "]}}"); var payload = new ErlOutputStream(msg, writeVersion: true); // fix up length in preamble header.Poke4BE(0, (int)(header.Length + payload.Length - 4)); try { DoSend(header, payload); } catch (Exception e) { Close(); throw new ErlException(StringConsts.ERL_CONN_UNAUTH_COOKIE_ERROR.Args(cookie.Value), e); } }
private void sendName(int dist, ErlAbstractNode.NodeCompatibility flags) { string str = m_Home.NodeName.Value; var obuf = new ErlOutputStream(writeVersion: false, writePktSize: false, capacity: 7 + str.Length); obuf.Write2BE(str.Length + 7); // 7 bytes + nodename obuf.Write1((int)ErlAbstractNode.NodeType.Ntype_R6); obuf.Write2BE((short)dist); obuf.Write4BE((int)flags); obuf.Write(Encoding.ASCII.GetBytes(str)); obuf.WriteTo(m_Transport.GetStream()); m_Home.OnTrace(ErlTraceLevel.Handshake, Direction.Outbound, () => "sendName(flags({0:X2})={1}, dist={2}, local={3}".Args( (int)flags, flags, dist, m_Home.AliveName)); }
private void sendChallengeReply(int challenge, byte[] digest) { var obuf = new ErlOutputStream(writeVersion: false, writePktSize: false, capacity: 23); obuf.Write2BE(21); obuf.Write1(CHALLENGE_REPLY); obuf.Write4BE(challenge); obuf.Write(digest); obuf.WriteTo(m_Transport.GetStream()); m_Home.OnTrace(ErlTraceLevel.Handshake, Direction.Outbound, () => "sendChallengeReply(challenge={0}, digest={1}, local={2}".Args( challenge, hex(digest), m_Home.NodeName.Value)); }
private void sendBuf(ErlTuple ctrl, ErlOutputStream payload = null) { if (!m_Connected) throw new ErlException(StringConsts.ERL_CONN_NOT_CONNECTED_ERROR); var header = new ErlOutputStream(writeVersion: false, capacity: HEADER_LEN); // preamble: 4 byte length + "PASS_THROUGH" tag + version header.Write4BE(0); // reserve space for length header.Write1(PASS_THROUGH); header.Write1((byte)ErlExternalTag.Version); // header info header.WriteTuple(ctrl); // version for payload //header.Write1((byte)ErlExternalTag.Version); // Note that it's already written in the payload if (payload == null) { header.Poke4BE(0, (int)(header.Length - 4)); DoSend(header); } else { header.Poke4BE(0, (int)(header.Length + payload.Length - 4)); DoSend(header, payload); } }
/// <summary> /// Send an auth error to peer because he sent a bad cookie /// The auth error uses his cookie (not revealing ours). /// This is just like send_reg otherwise /// </summary> private void cookieError(ErlLocalNode local, ErlAtom cookie) { var header = new ErlOutputStream(writeVersion: false, capacity: HEADER_LEN); // preamble: 4 byte length + "PASS_THROUGH" tag + version header.Write4BE(0); // reserve space for length header.Write1(PASS_THROUGH); header.Write1((byte)ErlExternalTag.Version); header.WriteTupleHead(4); header.WriteLong((long)ErlMsg.Tag.RegSend); header.WritePid(local.CreatePid()); // disposable pid header.WriteAtom(cookie); // important: his cookie, not mine... header.WriteAtom("auth"); // version for payload written later by the payload stream //header.Write1((byte)ErlExternalTag.Version); // the payload // the no_auth message (copied from Erlang) Don't change this (Erlang will crash) // {$gen_cast, {print, "~n** Unauthorized cookie ~w **~n", [foo@aule]}} var msg = ErlObject.Parse( "{'$gen_cast', {print, \"\n** Unauthorized cookie ~w **\n\", [" + local.NodeName.Value + "]}}"); var payload = new ErlOutputStream(msg, writeVersion: true); // fix up length in preamble header.Poke4BE(0, (int)(header.Length + payload.Length - 4)); try { DoSend(header, payload); } catch (Exception e) { Close(); throw new ErlException(StringConsts.ERL_CONN_UNAUTH_COOKIE_ERROR.Args(cookie.Value), e); } }
private void sendChallenge(int dist, ErlAbstractNode.NodeCompatibility flags, int challenge) { ErlAtom str = m_Home.NodeName; var obuf = new ErlOutputStream(writeVersion: false, writePktSize: false, capacity: 11 + str.Length); obuf.Write2BE((short)str.Length + 11); // 11 bytes + nodename obuf.Write1((byte)ErlAbstractNode.NodeType.Ntype_R6); obuf.Write2BE((short)dist); obuf.Write4BE((int)flags); obuf.Write4BE(challenge); obuf.Write(Encoding.ASCII.GetBytes(str.Value)); obuf.WriteTo(m_TcpClient.GetStream()); m_Home.Trace(ErlTraceLevel.Handshake, Direction.Outbound, () => "sendChallenge(flags({0:X2})={1}, dist={2}, challenge={3}, local={4}".Args( (int)flags, flags, dist, challenge, m_Home.AliveName)); }