Skip to content

Commit

Permalink
Fix a nostr subscription registration bug (#201)
Browse files Browse the repository at this point in the history
* check the dictionary _eoseCalledOnSubscriptionClients before adding a subscription class

* log if the subscription is already monitored

* return the result of the method adding the subscription

* log at the caller
  • Loading branch information
dangershony authored Dec 19, 2024
1 parent 7690592 commit dc64ff0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Angor/Shared/Services/INostrCommunicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface INostrCommunicationFactory
void CloseClientConnection();
int GetNumberOfRelaysConnected();
bool EoseEventReceivedOnAllRelays(string subscription);
void MonitoringEoseReceivedOnSubscription(string subscription);
bool MonitoringEoseReceivedOnSubscription(string subscription);
void ClearEoseReceivedOnSubscriptionMonitoring(string subscription);
bool OkEventReceivedOnAllRelays(string eventId);
void MonitoringOkReceivedOnSubscription(string eventId);
Expand Down
4 changes: 2 additions & 2 deletions src/Angor/Shared/Services/NostrCommunicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public bool EoseEventReceivedOnAllRelays(string subscription)
return response;
}

public void MonitoringEoseReceivedOnSubscription(string subscription)
public bool MonitoringEoseReceivedOnSubscription(string subscription)
{
_logger.LogInformation($"Started monitoring subscription {subscription}");
_eoseCalledOnSubscriptionClients.Add(subscription, new List<string>());
return _eoseCalledOnSubscriptionClients.TryAdd(subscription, new List<string>());
}

public void ClearEoseReceivedOnSubscriptionMonitoring(string subscription)
Expand Down
10 changes: 7 additions & 3 deletions src/Angor/Shared/Services/RelaySubscriptionsHandling.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using Blockcore.EventBus;
using Microsoft.Extensions.Logging;
using Nostr.Client.Requests;
using Nostr.Client.Responses;
Expand Down Expand Up @@ -65,9 +66,12 @@ public void HandleOkMessages(NostrOkResponse okResponse)

public bool TryAddEoseAction(string subscriptionName, Action action)
{
_communicationFactory.MonitoringEoseReceivedOnSubscription(subscriptionName);

return userEoseActions.TryAdd(subscriptionName,action);
var add = _communicationFactory.MonitoringEoseReceivedOnSubscription(subscriptionName);

if (!add)
_logger.LogWarning($"Subscription {subscriptionName} is already being monitored");

return userEoseActions.TryAdd(subscriptionName,action);
}

public void HandleEoseMessages(NostrEoseResponse _)
Expand Down

0 comments on commit dc64ff0

Please sign in to comment.