public DhtEngine(DhtListener listener) { if (listener == null) throw new ArgumentNullException("listener"); messageLoop = new MessageLoop(this, listener); timeout = TimeSpan.FromSeconds(15); // 15 second message timeout by default tokenManager = new TokenManager(); }
public void CheckTokenGenerator() { TokenManager m = new TokenManager(); m.Timeout = TimeSpan.FromMilliseconds(75); // 1 second timeout for testing purposes Node n = new Node(NodeId.Create(),new IPEndPoint(IPAddress.Parse("127.0.0.1"), 25)); Node n2 = new Node(NodeId.Create(),new IPEndPoint(IPAddress.Parse("127.0.0.2"), 25)); BEncodedString s = m.GenerateToken(n); BEncodedString s2 = m.GenerateToken(n); Assert.AreEqual(s, s2, "#1"); Assert.IsTrue(m.VerifyToken(n, s),"#2"); Assert.IsFalse(m.VerifyToken(n2, s),"#3"); System.Threading.Thread.Sleep(100); Assert.IsTrue(m.VerifyToken(n, s), "#4"); System.Threading.Thread.Sleep(100); Assert.IsFalse(m.VerifyToken(n, s), "#5"); }
public void CheckTokenGenerator() { var m = new TokenManager(); m.Timeout = TimeSpan.FromMilliseconds(75); // 1 second timeout for testing purposes var n = new Node(NodeId.Create(), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 25)); var n2 = new Node(NodeId.Create(), new IPEndPoint(IPAddress.Parse("127.0.0.2"), 25)); var s = m.GenerateToken(n); var s2 = m.GenerateToken(n); Assert.Equal(s, s2); Assert.True(m.VerifyToken(n, s), "#2"); Assert.False(m.VerifyToken(n2, s), "#3"); Thread.Sleep(100); Assert.True(m.VerifyToken(n, s)); Thread.Sleep(100); Assert.False(m.VerifyToken(n, s)); }
public void Setup() { manager = new TokenManager(); node = new Node(NodeId.Create(), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 25)); token = manager.GenerateToken(node); }