/// <summary> /// 关闭连接 /// </summary> /// <param name="encryptedConnection">待断开的封装连接类</param> public void CloseConnection(IEncryptedConnection encryptedConnection) { IConnection connection = connectionDictionary[encryptedConnection]; SingleDownload singleDownload = connection.Download; connectionDictionary.Remove(encryptedConnection); singleDownload.Disconnect(); choker.CloseConnection(connection); }
/// <summary> /// 写入数据 /// </summary> /// <param name="singleSocket">待写入的单套接字</param> public void FlushConnection(ISingleSocket singleSocket) { IEncryptedConnection encryptedConnection = connections[singleSocket]; if (encryptedConnection.Completed) { connecter.FlushConnection(encryptedConnection); } }
/// <summary> /// 建立连接 /// </summary> /// <param name="encryptedConnection">待建立的封装连接类</param> public void MakeConnection(IEncryptedConnection encryptedConnection) { Connection connection = new Connection(encryptedConnection, this); connectionDictionary[encryptedConnection] = connection; connection.Upload = MakeUpload(connection); connection.Download = downloader.MakeDownload(connection); choker.MakeConnection(connection); }
public void GetMessage(IEncryptedConnection encryptedConnection, byte[] message) { log.Add(new object[] { "get ", encryptedConnection, message }); Console.WriteLine("Connecter Get Message:{0}", this.closeNext); if (this.closeNext) { Console.WriteLine("Connecter close Encrypted Connection"); encryptedConnection.Close(); } }
public void Test2() { DummyConnecter c = new DummyConnecter(); DummyRawServer rs = new DummyRawServer(); IEncrypter e = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40); DummySingleSocket c1 = new DummySingleSocket(); e.MakeExternalConnection(c1); c1.Pop(); byte[] bytes = new byte[48]; bytes[0] = 19; Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19); int i; for (i = 0; i < 8; i++) { bytes[20 + i] = 0; } for (i = 0; i < 20; i++) { bytes[28 + i] = 1; } e.DataCameIn(c1, bytes); bytes = new byte[20]; for (i = 0; i < 20; i++) { bytes[i] = (byte)'b'; } e.DataCameIn(c1, bytes); c1.Pop(); IEncryptedConnection ch = (EncryptedConnection)((object[])c.log[0])[1]; c.log.Clear(); Encoding.Default.GetBytes(ch.IP); ch.SendMessage(new byte[] { (byte)'a', (byte)'b', (byte)'c' }); c1.Pop(); bytes = new byte[] { 0, 0, 0, 3, (byte)'d', (byte)'e', (byte)'f' }; e.DataCameIn(c1, bytes); c1.Pop(); }
public void Test11() { DummyConnecter c = new DummyConnecter(); DummyRawServer rs = new DummyRawServer(); IEncrypter e = new Encrypter(c, rs, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 500, DummySchedule, 30, new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 40); DummySingleSocket c1 = new DummySingleSocket(); e.MakeExternalConnection(c1); Assert.AreEqual(0, c.log.Count); Assert.AreEqual(0, rs.connects.Count); Assert.AreEqual(false, c1.Closed); byte[] bytes = new byte[68]; bytes[0] = 19; Buffer.BlockCopy(Encoding.Default.GetBytes(protocolName), 0, bytes, 1, 19); int i; for (i = 0; i < 8; i++) { bytes[20 + i] = 0; } for (i = 0; i < 20; i++) { bytes[28 + i] = 1; bytes[48 + i] = 2; } e.DataCameIn(c1, bytes); Assert.AreEqual(1, c.log.Count); IEncryptedConnection ch = (EncryptedConnection)((object[])c.log[0])[1]; c.log.Clear(); Assert.AreEqual(false, c1.Closed); ch.Close(); Assert.AreEqual(true, c1.Closed); }
public void MakeConnection(IEncryptedConnection encryptedConnection) { log.Add(new object[] { "make ", encryptedConnection }); }
public void FlushConnection(IEncryptedConnection encryptedConnection) { log.Add(new object[] { "flush ", encryptedConnection }); }
public void CloseConnection(IEncryptedConnection encryptedConnection) { log.Add(new object[] { "lose ", encryptedConnection }); }
/// <summary> /// 处理从节点上获取的网络信息 /// </summary> /// <param name="encryptedConnection">获取网络信息的封装连接类</param> /// <param name="message">获取的网络信息字节流</param> public void GetMessage(IEncryptedConnection encryptedConnection, byte[] message) { throw new NotImplementedException(); //MessageDecoder.Parse(message, encryptedConnection, connectionDictionary[encryptedConnection], this); }
/// <summary> /// 清除缓冲区中的数据,并将其写入到相应节点上 /// </summary> /// <param name="encryptedConnection">待写入的封装连接类</param> public void FlushConnection(IEncryptedConnection encryptedConnection) { connectionDictionary[encryptedConnection].Upload.Flush(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="next">下一个分析字节流类</param> /// <param name="encrypter">封装连接器类</param> /// <param name="encryptedConnection">封装连接类</param> public ReadHandshake(ReadFunction next, IEncrypter encrypter, IEncryptedConnection encryptedConnection) : this(68, next, encrypter, encryptedConnection) { }
/// <summary> /// 构造函数 /// </summary> /// <param name="length">分析的长度</param> /// <param name="next">下一个分析字节流类</param> /// <param name="encrypter">封装连接器类</param> /// <param name="encryptedConnection">封装连接类</param> private ReadHandshake(int length, ReadFunction next, IEncrypter encrypter, IEncryptedConnection encryptedConnection) : base(length, next, encrypter) { this.encryptedConnection = encryptedConnection; }
/// <summary> /// 构造函数 /// </summary> /// <param name="length">分析的长度</param> /// <param name="encrypter">封装连接器类</param> /// <param name="encryptedConnection">封装连接类</param> public ReadMessage(int length, IEncrypter encrypter, IEncryptedConnection encryptedConnection) : base(length, null, encrypter) { }
/// <summary> /// 构造函数 /// </summary> /// <param name="length">分析的长度</param> /// <param name="next">下一个分析字节流类</param> /// <param name="encrypter">封装连接器类</param> /// <param name="encryptedConnection">封装连接类</param> public ReadMessage(int length, ReadLength next, IEncrypter encrypter, IEncryptedConnection encryptedConnection) : base(length, next, encrypter) { }
/// <summary> /// 构造函数 /// </summary> /// <param name="encryptedConnection">封装连接类</param> /// <param name="connecter">连接管理类</param> public Connection(IEncryptedConnection encryptedConnection, IConnecter connecter) { this.encryptedConnection = encryptedConnection; this.connecter = connecter; this.getAnything = false; }