From ee20bc944ca2c8d6512cfbd5b50dafa94ef12ddb Mon Sep 17 00:00:00 2001 From: Charis Date: Tue, 16 Jul 2019 12:49:12 +0800 Subject: [PATCH 1/4] add internal to DB and WriteBatch --- neo/IO/Data/LevelDB/DB.cs | 16 ++++++++-------- neo/IO/Data/LevelDB/WriteBatch.cs | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/neo/IO/Data/LevelDB/DB.cs b/neo/IO/Data/LevelDB/DB.cs index 559a109594..5f4a9f359a 100644 --- a/neo/IO/Data/LevelDB/DB.cs +++ b/neo/IO/Data/LevelDB/DB.cs @@ -16,7 +16,7 @@ private DB(IntPtr handle) this.handle = handle; } - public void Dispose() + public virtual void Dispose() { if (handle != IntPtr.Zero) { @@ -25,14 +25,14 @@ public void Dispose() } } - public void Delete(WriteOptions options, Slice key) + public virtual void Delete(WriteOptions options, Slice key) { IntPtr error; Native.leveldb_delete(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, out error); NativeHelper.CheckError(error); } - public Slice Get(ReadOptions options, Slice key) + public virtual Slice Get(ReadOptions options, Slice key) { UIntPtr length; IntPtr error; @@ -50,12 +50,12 @@ public Slice Get(ReadOptions options, Slice key) } } - public Snapshot GetSnapshot() + public virtual Snapshot GetSnapshot() { return new Snapshot(handle); } - public Iterator NewIterator(ReadOptions options) + public virtual Iterator NewIterator(ReadOptions options) { return new Iterator(Native.leveldb_create_iterator(handle, options.handle)); } @@ -73,14 +73,14 @@ public static DB Open(string name, Options options) return new DB(handle); } - public void Put(WriteOptions options, Slice key, Slice value) + public virtual void Put(WriteOptions options, Slice key, Slice value) { IntPtr error; Native.leveldb_put(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, value.buffer, (UIntPtr)value.buffer.Length, out error); NativeHelper.CheckError(error); } - public bool TryGet(ReadOptions options, Slice key, out Slice value) + public virtual bool TryGet(ReadOptions options, Slice key, out Slice value) { UIntPtr length; IntPtr error; @@ -101,7 +101,7 @@ public bool TryGet(ReadOptions options, Slice key, out Slice value) return true; } - public void Write(WriteOptions options, WriteBatch write_batch) + public virtual void Write(WriteOptions options, WriteBatch write_batch) { // There's a bug in .Net Core. // When calling DB.Write(), it will throw LevelDBException sometimes. diff --git a/neo/IO/Data/LevelDB/WriteBatch.cs b/neo/IO/Data/LevelDB/WriteBatch.cs index eaa3e08bd6..29d04643a1 100644 --- a/neo/IO/Data/LevelDB/WriteBatch.cs +++ b/neo/IO/Data/LevelDB/WriteBatch.cs @@ -11,17 +11,17 @@ public class WriteBatch Native.leveldb_writebatch_destroy(handle); } - public void Clear() + public virtual void Clear() { Native.leveldb_writebatch_clear(handle); } - public void Delete(Slice key) + public virtual void Delete(Slice key) { Native.leveldb_writebatch_delete(handle, key.buffer, (UIntPtr)key.buffer.Length); } - public void Put(Slice key, Slice value) + public virtual void Put(Slice key, Slice value) { Native.leveldb_writebatch_put(handle, key.buffer, (UIntPtr)key.buffer.Length, value.buffer, (UIntPtr)value.buffer.Length); } From b76b04daa18414b4fa9d7ea2ce09234db7a8e328 Mon Sep 17 00:00:00 2001 From: luchuan Date: Sat, 12 Oct 2019 16:07:45 +0800 Subject: [PATCH 2/4] reset db.cs writebatch.cs --- neo/IO/Data/LevelDB/DB.cs | 16 ++++++++-------- neo/IO/Data/LevelDB/WriteBatch.cs | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/neo/IO/Data/LevelDB/DB.cs b/neo/IO/Data/LevelDB/DB.cs index b446f0eb56..04e8f50e8f 100644 --- a/neo/IO/Data/LevelDB/DB.cs +++ b/neo/IO/Data/LevelDB/DB.cs @@ -16,7 +16,7 @@ private DB(IntPtr handle) this.handle = handle; } - public virtual void Dispose() + public void Dispose() { if (handle != IntPtr.Zero) { @@ -25,14 +25,14 @@ public virtual void Dispose() } } - public virtual void Delete(WriteOptions options, Slice key) + public void Delete(WriteOptions options, Slice key) { IntPtr error; Native.leveldb_delete(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, out error); NativeHelper.CheckError(error); } - public virtual Slice Get(ReadOptions options, Slice key) + public Slice Get(ReadOptions options, Slice key) { UIntPtr length; IntPtr error; @@ -50,12 +50,12 @@ public virtual Slice Get(ReadOptions options, Slice key) } } - public virtual Snapshot GetSnapshot() + public Snapshot GetSnapshot() { return new Snapshot(handle); } - public virtual Iterator NewIterator(ReadOptions options) + public Iterator NewIterator(ReadOptions options) { return new Iterator(Native.leveldb_create_iterator(handle, options.handle)); } @@ -73,14 +73,14 @@ public static DB Open(string name, Options options) return new DB(handle); } - public virtual void Put(WriteOptions options, Slice key, Slice value) + public void Put(WriteOptions options, Slice key, Slice value) { IntPtr error; Native.leveldb_put(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, value.buffer, (UIntPtr)value.buffer.Length, out error); NativeHelper.CheckError(error); } - public virtual bool TryGet(ReadOptions options, Slice key, out Slice value) + public bool TryGet(ReadOptions options, Slice key, out Slice value) { UIntPtr length; IntPtr error; @@ -101,7 +101,7 @@ public virtual bool TryGet(ReadOptions options, Slice key, out Slice value) return true; } - public virtual void Write(WriteOptions options, WriteBatch write_batch) + public void Write(WriteOptions options, WriteBatch write_batch) { // There's a bug in .Net Core. // When calling DB.Write(), it will throw LevelDBException sometimes. diff --git a/neo/IO/Data/LevelDB/WriteBatch.cs b/neo/IO/Data/LevelDB/WriteBatch.cs index 03dcab1f3d..b3a9782108 100644 --- a/neo/IO/Data/LevelDB/WriteBatch.cs +++ b/neo/IO/Data/LevelDB/WriteBatch.cs @@ -11,17 +11,17 @@ public class WriteBatch Native.leveldb_writebatch_destroy(handle); } - public virtual void Clear() + public void Clear() { Native.leveldb_writebatch_clear(handle); } - public virtual void Delete(Slice key) + public void Delete(Slice key) { Native.leveldb_writebatch_delete(handle, key.buffer, (UIntPtr)key.buffer.Length); } - public virtual void Put(Slice key, Slice value) + public void Put(Slice key, Slice value) { Native.leveldb_writebatch_put(handle, key.buffer, (UIntPtr)key.buffer.Length, value.buffer, (UIntPtr)value.buffer.Length); } From 9b380a76df428dc003141c2c391864ab8f8cbf67 Mon Sep 17 00:00:00 2001 From: luchuan Date: Fri, 18 Oct 2019 11:13:19 +0800 Subject: [PATCH 3/4] filter unconnected peers --- neo/Network/P2P/Peer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/Network/P2P/Peer.cs b/neo/Network/P2P/Peer.cs index 0cbd6cbaff..0665567fc8 100644 --- a/neo/Network/P2P/Peer.cs +++ b/neo/Network/P2P/Peer.cs @@ -66,7 +66,7 @@ protected void AddPeers(IEnumerable peers) { if (UnconnectedPeers.Count < UnconnectedMax) { - peers = peers.Where(p => p.Port != ListenerTcpPort || !localAddresses.Contains(p.Address)); + peers = peers.Where(p => (p.Port != ListenerTcpPort || !localAddresses.Contains(p.Address)) && !ConnectedPeers.Values.Contains(p)); ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Union(peers)); } } From 17d9e9d9c88532d963dee762c61548d09c425724 Mon Sep 17 00:00:00 2001 From: luchuan Date: Fri, 18 Oct 2019 13:24:06 +0800 Subject: [PATCH 4/4] add MaxCountFromSeedList variable --- neo/Network/P2P/LocalNode.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/Network/P2P/LocalNode.cs b/neo/Network/P2P/LocalNode.cs index 79ad7fb096..0efd8a3287 100644 --- a/neo/Network/P2P/LocalNode.cs +++ b/neo/Network/P2P/LocalNode.cs @@ -20,6 +20,7 @@ internal class RelayDirectly { public IInventory Inventory; } internal class SendDirectly { public IInventory Inventory; } public const uint ProtocolVersion = 0; + private const int MaxCountFromSeedList = 5; private static readonly object lockObj = new object(); private readonly NeoSystem system; @@ -123,7 +124,7 @@ public IEnumerable GetUnconnectedPeers() protected override void NeedMorePeers(int count) { - count = Math.Max(count, 5); + count = Math.Max(count, MaxCountFromSeedList); if (ConnectedPeers.Count > 0) { BroadcastMessage(MessageCommand.GetAddr);