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

fixed warnings #47

Merged
merged 3 commits into from
May 21, 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
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dotnet_style_null_propagation = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_object_initializer = true:warning
dotnet_style_collection_initializer = true:suggestion

[*.xml]
indent_style = space
Expand Down Expand Up @@ -144,7 +145,7 @@ dotnet_diagnostic.CA1001.severity = suggestion
dotnet_diagnostic.CA1028.severity = suggestion

# CA1062: Validate arguments of public methods
dotnet_diagnostic.CA1062.severity = suggestion
dotnet_diagnostic.CA1062.severity = silent

# CA1308: Normalize strings to uppercase
dotnet_diagnostic.CA1308.severity = silent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ protected override ValueTask OnPeerAttachedAsync()
/// <returns></returns>
protected override async ValueTask OnPeerHandshakedAsync()
{
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>();
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>()!;

VersionMessage peerVersion = handshakeStatus.PeerVersion!;
logger.LogDebug("Peer {PeerId} handshake completed. Peer version: {PeerVersion}", PeerContext.PeerId, peerVersion);

await SendMessageAsync(minVersion: KnownVersion.V70012, new SendHeadersMessage()).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public SynchronizationProcessor(ILogger<SynchronizationProcessor> logger,

public void OnPeriodicWorkException(IPeriodicWork failedWork, Exception ex, ref IPeriodicWorkExceptionHandler.Feedback feedback)
{
ArgumentNullException.ThrowIfNull(failedWork, nameof(failedWork));
ArgumentNullException.ThrowIfNull(ex, nameof(ex));
ArgumentNullException.ThrowIfNull(feedback, nameof(feedback));

logger.LogError(ex, "Error in {FailedWork}", failedWork);

string? disconnectionReason = failedWork switch
{
IPeriodicWork work when work == _headerSyncLoop => "Peer header syncing loop had failures.",
Expand Down Expand Up @@ -116,7 +122,7 @@ protected override ValueTask OnPeerAttachedAsync()
/// <returns></returns>
protected override async ValueTask OnPeerHandshakedAsync()
{
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>();
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>()!;

VersionMessage peerVersion = handshakeStatus.PeerVersion!;

Expand Down Expand Up @@ -195,7 +201,7 @@ got back an empty response. */
HashStop = UInt256.Zero
};

await SendMessageAsync(newGetHeaderRequest).ConfigureAwait(false);
await SendMessageAsync(newGetHeaderRequest, cancellationToken).ConfigureAwait(false);
}

CheckSyncStallingLocked(bestBlockHeader);
Expand Down
2 changes: 2 additions & 0 deletions src/MithrilShards.Core/Network/PeerContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public PeerContextFactory(ILogger<PeerContextFactory<TPeerContext>> logger,

public virtual IPeerContext CreateIncomingPeerContext(string peerId, EndPoint localEndPoint, EndPoint remoteEndPoint, INetworkMessageWriter messageWriter)
{
_logger.LogTrace("Creating incoming peer context for {PeerId} from {RemoteEndPoint}", peerId, remoteEndPoint);
return Create(PeerConnectionDirection.Inbound, peerId, localEndPoint, remoteEndPoint, messageWriter);
}

public virtual IPeerContext CreateOutgoingPeerContext(string peerId, EndPoint localEndPoint, OutgoingConnectionEndPoint outgoingConnectionEndPoint, INetworkMessageWriter messageWriter)
{
_logger.LogTrace("Creating outgoing peer context for {PeerId} to {RemoteEndPoint}", peerId, outgoingConnectionEndPoint.EndPoint);
IPeerContext peerContext = Create(PeerConnectionDirection.Outbound, peerId, localEndPoint, outgoingConnectionEndPoint.EndPoint, messageWriter);
peerContext.Features.Set(outgoingConnectionEndPoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ public NetworkMessageProcessorFactory(ILogger<INetworkMessageProcessorFactory> l
/// <param name="peerContext">The peer context.</param>
public async Task StartProcessorsAsync(IPeerContext peerContext)
{
if (peerContext is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(peerContext));
}
ArgumentNullException.ThrowIfNull(peerContext, nameof(peerContext));

IEnumerable<INetworkMessageProcessor> processors = _serviceProvider.GetService<IEnumerable<INetworkMessageProcessor>>()!;
foreach (INetworkMessageProcessor processor in processors)
{
// skip processors that aren't enabled
if (!processor.Enabled) continue;

if (_logger.IsEnabled(LogLevel.Trace))
{
_logger.LogTrace("Attaching processor {ProcessorType} to peer {PeerId}", processor.GetType().Name, peerContext.PeerId);
}

peerContext.AttachNetworkMessageProcessor(processor);
await processor.AttachAsync(peerContext).ConfigureAwait(false);
}
Expand All @@ -48,6 +50,12 @@ public async Task StartProcessorsAsync(IPeerContext peerContext)

public async ValueTask ProcessMessageAsync(INetworkMessage message, IPeerContext peerContext, CancellationToken cancellation)
{
await peerContext.Features.Get<PeerNetworkMessageProcessorContainer>().ProcessMessageAsync(message, cancellation).ConfigureAwait(false);
ArgumentNullException.ThrowIfNull(message, nameof(message));
ArgumentNullException.ThrowIfNull(peerContext, nameof(peerContext));

var container = peerContext.Features.Get<PeerNetworkMessageProcessorContainer>()
?? throw new InvalidOperationException("PeerNetworkMessageProcessorContainer not found in peer context.");

await container.ProcessMessageAsync(message, cancellation).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override IPeerContext CreateOutgoingPeerContext(string peerId, EndPoint l
/// Since this information may be important to us, we decide to have an explicit property in our <see cref="ExamplePeerContext"/> so we can
/// access that information easily in our code.
/// Note that we set that information in our <see cref="Client.ExampleRequiredConnection"/> connector.
string myExtraInformation = (string)peerContext.Features.Get<OutgoingConnectionEndPoint>().Items[nameof(ExampleEndPoint.MyExtraInformation)];
string myExtraInformation = (string)peerContext.Features.Get<OutgoingConnectionEndPoint>()!.Items[nameof(ExampleEndPoint.MyExtraInformation)];

peerContext.MyExtraInformation = myExtraInformation;

Expand Down
Loading