Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove BoundPeerUtility #3933

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/node/Libplanet.Node.Executable/appsettings-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@
"BlocksyncSeedPeer": {
"type": "string",
"description": "The endpoint of the node to block sync.",
"pattern": "^$|^[0-9a-fA-F]{130}|[0-9a-fA-F]{66},\\s*(?:(?:[a-zA-Z0-9\\-\\.]+)|(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})):\\d{1,5}$"
"pattern": "^$|^(?:[0-9a-fA-F]{130}|[0-9a-fA-F]{66}),(?:(?:[a-zA-Z0-9\\-\\.]+)|(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})),\\d{1,5}$"
}
}
},
Expand All @@ -1209,7 +1209,7 @@
"ConsensusSeedPeer": {
"type": "string",
"description": "The endpoint of the node to consensus.",
"pattern": "^$|^[0-9a-fA-F]{130}|[0-9a-fA-F]{66},\\s*(?:(?:[a-zA-Z0-9\\-\\.]+)|(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})):\\d{1,5}$"
"pattern": "^$|^(?:[0-9a-fA-F]{130}|[0-9a-fA-F]{66}),(?:(?:[a-zA-Z0-9\\-\\.]+)|(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})),\\d{1,5}$"
}
}
}
Expand Down
33 changes: 0 additions & 33 deletions sdk/node/Libplanet.Node/BoundPeerUtility.cs

This file was deleted.

15 changes: 13 additions & 2 deletions sdk/node/Libplanet.Node/DataAnnotations/BoundPeerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ namespace Libplanet.Node.DataAnnotations;
public sealed class BoundPeerAttribute : RegularExpressionAttribute
{
public BoundPeerAttribute()
: base(
@$"^$|^{PublicKeyAttribute.OriginPattern},\s*{DnsEndPointAttribute.OriginPattern}$")
: base(GetPattern())
{
}

private static string GetPattern()
{
var items = new string[]
{
PublicKeyAttribute.OriginPattern,
DnsEndPointAttribute.HostPattern,
DnsEndPointAttribute.PortPattern,
};
var pattern = string.Join(",", items);
return @$"^$|^{pattern}$";
}
}

[AttributeUsage(AttributeTargets.Property)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ namespace Libplanet.Node.DataAnnotations;
[AttributeUsage(AttributeTargets.Property)]
public sealed class DnsEndPointAttribute : RegularExpressionAttribute
{
public const string OriginPattern
= @"(?:(?:[a-zA-Z0-9\-\.]+)|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})):\d{1,5}";
public const string HostPattern
= @"(?:(?:[a-zA-Z0-9\-\.]+)|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))";

public const string PortPattern = @"\d{1,5}";
public static readonly string OriginPattern
= $"{HostPattern}:{PortPattern}";

public DnsEndPointAttribute()
: base($"^{OriginPattern}$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Libplanet.Node.DataAnnotations;
[AttributeUsage(AttributeTargets.Property)]
public sealed class PublicKeyAttribute : RegularExpressionAttribute
{
public const string OriginPattern = "[0-9a-fA-F]{130}|[0-9a-fA-F]{66}";
public const string OriginPattern = "(?:[0-9a-fA-F]{130}|[0-9a-fA-F]{66})";

public PublicKeyAttribute()
: base($"^{OriginPattern}$")
Expand Down
9 changes: 4 additions & 5 deletions sdk/node/Libplanet.Node/Services/SwarmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
PrivateKey = ByteUtil.Hex(seedPrivateKey.ByteArray),
EndPoint = EndPointUtility.ToString(EndPointUtility.Next()),
});
_options.BlocksyncSeedPeer = BoundPeerUtility.ToString(_blocksyncSeed.BoundPeer);
_options.BlocksyncSeedPeer = _blocksyncSeed.BoundPeer.PeerString;
await _blocksyncSeed.StartAsync(cancellationToken);
}

Expand All @@ -63,8 +63,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
PrivateKey = ByteUtil.Hex(seedPrivateKey.ByteArray),
EndPoint = EndPointUtility.ToString(EndPointUtility.Next()),
});
validatorOptions.ConsensusSeedPeer
= BoundPeerUtility.ToString(_consensusSeed.BoundPeer);
validatorOptions.ConsensusSeedPeer = _consensusSeed.BoundPeer.PeerString;
await _consensusSeed.StartAsync(cancellationToken);
}

Expand All @@ -74,7 +73,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
var swarmTransport = await CreateTransport(
privateKey: privateKey,
endPoint: swarmEndPoint);
var blocksyncSeedPeer = BoundPeerUtility.Parse(nodeOptions.BlocksyncSeedPeer);
var blocksyncSeedPeer = BoundPeer.ParsePeer(nodeOptions.BlocksyncSeedPeer);
var swarmOptions = new Net.Options.SwarmOptions
{
StaticPeers = [blocksyncSeedPeer],
Expand Down Expand Up @@ -185,7 +184,7 @@ private static async Task<NetMQTransport> CreateTransport(
private static ConsensusReactorOption CreateConsensusReactorOption(
PrivateKey privateKey, ValidatorOptions options)
{
var consensusSeedPeer = BoundPeerUtility.Parse(options.ConsensusSeedPeer);
var consensusSeedPeer = BoundPeer.ParsePeer(options.ConsensusSeedPeer);
var consensusEndPoint = (DnsEndPoint)EndPointUtility.Parse(options.EndPoint);
return new ConsensusReactorOption
{
Expand Down
Loading