Skip to content
Permalink
Browse files

Add Microsoft.DotNet.Analyzers.Compatibility

  • Loading branch information...
longfin committed Jun 3, 2019
1 parent aa95093 commit 5e2e64bc090f2461e661be93ae3c636b70ece850
@@ -16,6 +16,10 @@
<PackageReference Include="Menees.Analyzers.2017" Version="2.0.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
@@ -43,7 +43,11 @@ public class TurnClient : IStunContext, IDisposable
_relayedClients = new List<TcpClient>();

_control = new TcpClient();

// TODO Should investigate about PC001 on TcpClient.Connect().
#pragma warning disable PC001 // API not supported on all platforms
_control.Connect(_host, _port);
#pragma warning restore PC001

_connectionAttempts =
new AsyncProducerConsumerQueue<ConnectionAttempt>();
@@ -70,6 +70,10 @@ https://docs.libplanet.io/</Description>
<PackageReference Include="Menees.Analyzers.2017" Version="2.0.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NetMQ" Version="4.0.0.207-pre" />
<PackageReference Include="Nito.AsyncEx" Version="5.0.0" />
<PackageReference Include="Serilog" Version="2.8.0" />
@@ -29,7 +29,11 @@ public async Task StartAsync(IPAddress address, int port)
public async Task StartAsync(IPEndPoint endPoint)
{
_targetClient = new TcpClient();

// TODO Should investigate about PC001 on TcpClient.Connect().
#pragma warning disable PC001 // API not supported on all platforms
_targetClient.Connect(endPoint);
#pragma warning restore PC001
NetworkStream target = _targetClient.GetStream();
await Task.WhenAll(
Proxy(_source, target),
@@ -18,6 +18,14 @@ namespace Libplanet.Store
{
public class LiteDBStore : IStore, IDisposable
{
private const string TxIdPrefix = "tx/";

private const string IndexColPrefix = "index_";

private const string StateRefIdPrefix = "stateref/";

private const string NonceIdPrefix = "nonce/";

private readonly LiteDatabase _db;

public LiteDBStore(string path)
@@ -60,8 +68,8 @@ public LiteDBStore(string path)
public IEnumerable<string> ListNamespaces()
{
return _db.GetCollectionNames()
.Where(name => name.StartsWith("indices_"))
.Select(name => name.Split('_')[1]);
.Where(name => name.StartsWith(IndexColPrefix))
.Select(name => name.Substring(IndexColPrefix.Length));
}

/// <inheritdoc/>
@@ -132,7 +140,7 @@ public IEnumerable<TxId> IterateStagedTransactionIds()
public IEnumerable<TxId> IterateTransactionIds()
{
return _db.FileStorage
.Find("tx/")
.Find(TxIdPrefix)
.Select(file => new TxId(ByteUtil.ParseHex(file.Filename)));
}

@@ -298,7 +306,7 @@ public AddressStateMap GetBlockStates(HashDigest<SHA256> blockHash)
Block<T> lookupUntil)
where T : IAction, new()
{
var fileId = $"stateref/{@namespace}/{address.ToHex()}";
var fileId = $"{StateRefIdPrefix}{@namespace}/{address.ToHex()}";
LiteFileInfo file = _db.FileStorage.FindById(fileId);

if (file is null)
@@ -347,12 +355,13 @@ public AddressStateMap GetBlockStates(HashDigest<SHA256> blockHash)

foreach (Address address in addresses)
{
var fileId = $"stateref/{@namespace}/{address.ToHex()}";
string addrHex = address.ToHex();
var fileId = $"{StateRefIdPrefix}{@namespace}/{addrHex}";
if (!_db.FileStorage.Exists(fileId))
{
_db.FileStorage.Upload(
fileId,
address.ToHex(),
addrHex,
new MemoryStream());
}

@@ -375,29 +384,29 @@ public AddressStateMap GetBlockStates(HashDigest<SHA256> blockHash)

/// <inheritdoc/>
public void ForkStateReferences<T>(
string sourceNamespace,
string destinationNamespace,
string srcNamespace,
string destNamespace,
Block<T> branchPoint,
IImmutableSet<Address> addressesToStrip)
where T : IAction, new()
{
long branchPointIndex = branchPoint.Index;
List<LiteFileInfo> files =
_db.FileStorage
.Find($"stateref/{sourceNamespace}")
.Find($"{StateRefIdPrefix}{srcNamespace}")
.ToList();

if (!files.Any() && addressesToStrip.Any())
{
throw new NamespaceNotFoundException(
sourceNamespace,
srcNamespace,
"The source namespace to be forked does not exist.");
}

foreach (LiteFileInfo srcFile in files)
{
string destId =
$"stateref/{destinationNamespace}/{srcFile.Filename}";
$"{StateRefIdPrefix}{destNamespace}/{srcFile.Filename}";
_db.FileStorage.Upload(
destId,
srcFile.Filename,
@@ -435,7 +444,7 @@ public AddressStateMap GetBlockStates(HashDigest<SHA256> blockHash)
/// <inheritdoc/>
public long GetTxNonce(string @namespace, Address address)
{
var fileId = $"nonce/{@namespace}/{address.ToHex()}";
var fileId = $"{NonceIdPrefix}{@namespace}/{address.ToHex()}";
LiteFileInfo file = _db.FileStorage.FindById(fileId);

if (file is null)
@@ -479,7 +488,7 @@ public void IncreaseTxNonce<T>(string @namespace, Block<T> block)

foreach (Address signer in signers)
{
var fileId = $"nonce/{@namespace}/{signer.ToHex()}";
var fileId = $"{NonceIdPrefix}{@namespace}/{signer.ToHex()}";
long nextNonce = GetTxNonce(@namespace, signer) + 1;

if (!_db.FileStorage.Exists(fileId))
@@ -521,7 +530,7 @@ public void IncreaseTxNonce<T>(string @namespace, Block<T> block)
long branchPointIndex = branchPoint.Index;
List<LiteFileInfo> files =
_db.FileStorage
.Find($"nonce/{sourceNamespace}")
.Find($"{NonceIdPrefix}{sourceNamespace}")
.ToList();

if (!files.Any() && addressesToStrip.Any())
@@ -534,7 +543,7 @@ public void IncreaseTxNonce<T>(string @namespace, Block<T> block)
foreach (LiteFileInfo srcFile in files)
{
string destId =
$"nonce/{destinationNamespace}/{srcFile.Filename}";
$"{NonceIdPrefix}{destinationNamespace}/{srcFile.Filename}";
_db.FileStorage.Upload(
destId,
srcFile.Filename,
@@ -575,7 +584,7 @@ public void IncreaseTxNonce<T>(string @namespace, Block<T> block)
/// <inheritdoc/>
public long CountTransactions()
{
return _db.FileStorage.Find("tx/").Count();
return _db.FileStorage.Find(TxIdPrefix).Count();
}

/// <inheritdoc/>
@@ -617,7 +626,7 @@ IEnumerable transactions

private LiteCollection<HashDoc> IndexCollection(string @namespace)
{
return _db.GetCollection<HashDoc>($"indices_{@namespace}");
return _db.GetCollection<HashDoc>($"{IndexColPrefix}{@namespace}");
}

private class HashDoc

0 comments on commit 5e2e64b

Please sign in to comment.
You can’t perform that action at this time.