diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-07-23 17:38:08 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-07-26 22:37:02 +0200 |
commit | 941ba9a209fa03b1c059b2b02a8e4cf4a270030e (patch) | |
tree | 6f506d14e953bd0bf74e78a0f41b004fe026e797 /src/Network.hs | |
parent | d8f165b62914cb61cad2f6c37eb7a2b3a57c9990 (diff) |
Network: notify services when peer identity updates
Diffstat (limited to 'src/Network.hs')
-rw-r--r-- | src/Network.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Network.hs b/src/Network.hs index 6fae8c5..da786c6 100644 --- a/src/Network.hs +++ b/src/Network.hs @@ -722,11 +722,7 @@ finalizedChannel peer self = do -- Notify services about new peer readTVar (peerIdentityVar peer) >>= \case - PeerIdentityFull _ -> - writeTQueue (serverIOActions $ peerServer peer) $ do - forM_ (serverServices $ peerServer peer) $ \case - service@(SomeService _ attrs) -> - runPeerServiceOn (Just (service, attrs)) peer serviceNewPeer + PeerIdentityFull _ -> notifyServicesOfPeer peer _ -> return () -- Outstanding service packets @@ -754,7 +750,8 @@ handleIdentityAnnounce self peer ref = liftIO $ atomically $ do PeerIdentityFull pid | idData pid `precedes` wrappedLoad ref - -> validateAndUpdate (idUpdates pid) $ \_ -> return () + -> validateAndUpdate (idUpdates pid) $ \_ -> do + notifyServicesOfPeer peer _ -> return () @@ -766,9 +763,16 @@ handleIdentityUpdate peer ref = liftIO $ atomically $ do -> do writeTVar (peerIdentityVar peer) $ PeerIdentityFull pid' writeTChan (serverChanPeer $ peerServer peer) peer + when (idData pid /= idData pid') $ notifyServicesOfPeer peer | otherwise -> return () +notifyServicesOfPeer :: Peer -> STM () +notifyServicesOfPeer peer@Peer { peerServer_ = Server {..} } = do + writeTQueue serverIOActions $ do + forM_ serverServices $ \service@(SomeService _ attrs) -> + runPeerServiceOn (Just (service, attrs)) peer serviceNewPeer + mkPeer :: Server -> PeerAddress -> IO Peer mkPeer server paddr = do |