Skip to content

Commit

Permalink
ensure relay channel is set before signaling connection
Browse files Browse the repository at this point in the history
fixes "no channel found" error by properly initializing relay connection
state and request channel before signaling success via connectionMVar
  • Loading branch information
prolic committed Jan 29, 2025
1 parent cb03883 commit ccbe311
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Nostr/RelayConnection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,19 @@ connectWithRetry r maxRetries requestChan = do
nostrClient :: RelayConnectionEff es => TMVar Bool -> RelayURI -> TChan Request -> (forall a. Eff es a -> IO a) -> WS.ClientApp ()
nostrClient connectionMVar r requestChan runE conn = runE $ do
logDebug $ "Connected to " <> r
void $ atomically $ putTMVar connectionMVar True

modify @RelayPoolState $ \st ->
st { activeConnections = Map.adjust (\d -> d { connectionState = Connected }) r (activeConnections st) }
st { activeConnections = Map.adjust
(\d -> d { connectionState = Connected
, requestChannel = requestChan
})
r
(activeConnections st)
}
notifyRelayStatus

void $ atomically $ putTMVar connectionMVar True

updateQueue <- newTQueueIO
receiveThread <- async $ receiveLoop updateQueue
sendThread <- async $ sendLoop
Expand Down
14 changes: 12 additions & 2 deletions src/Nostr/Subscription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Nostr.Event (validateEvent)
import Nostr.GiftWrap (GiftWrap, handleGiftWrapEvent)
import Nostr.Keys (PubKeyXO, byteStringToHex, keyPairToPubKeyXO)
import Nostr.RelayConnection
import Nostr.Types ( Event(..), EventId(..), Filter, Kind(..), Relay(..)
import Nostr.Types ( Event(..), EventId(..), Filter(..), Kind(..), Relay(..)
, RelayURI, SubscriptionId, Tag(..), getUri )
import Nostr.Types qualified as NT
import Nostr.Util
Expand Down Expand Up @@ -411,12 +411,22 @@ createDMRelayFilters xo followedPubKeys =
-- | Create inbox relay subscription filters
createInboxRelayFilters :: PubKeyXO -> [PubKeyXO] -> [Filter]
createInboxRelayFilters xo followedPubKeys =
{-
[ NT.followListFilter (xo : followedPubKeys)
, NT.metadataFilter (xo : followedPubKeys)
, NT.shortTextNoteFilter (xo : followedPubKeys)
, NT.preferredDMRelaysFilter (xo : followedPubKeys)
]

-}
[ Filter
{ ids = Nothing
, authors = Just (xo : followedPubKeys)
, kinds = Just [FollowList, Metadata, ShortTextNote, EventDeletion, Repost, PreferredDMRelays]
, since = Nothing
, NT.until = Nothing
, limit = Just 1000
, fTags = Nothing
} ]

-- | Generate a random subscription ID
generateRandomSubscriptionId :: SubscriptionEff es => Eff es SubscriptionId
Expand Down

0 comments on commit ccbe311

Please sign in to comment.