diff options
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r-- | examples/dhtd.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index fed2976f..57ee8deb 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -673,20 +673,23 @@ clientSession s@Session{..} sock cnum h = do | |||
673 | -> cmd0 $ do | 673 | -> cmd0 $ do |
674 | sessions' <- atomically $ readTVar sessions :: IO [PerSession] | 674 | sessions' <- atomically $ readTVar sessions :: IO [PerSession] |
675 | let sessionsReport = mapM showPerSession sessions' | 675 | let sessionsReport = mapM showPerSession sessions' |
676 | headers = ["Key", "NextMsg", "Handled","Unhandled"] | 676 | headers = ["Key", "NextMsg", "Dropped","Handled","Unhandled"] |
677 | showPerSession (PerSession | 677 | showPerSession (PerSession |
678 | { perSessionMsgs = msgQ | 678 | { perSessionMsgs = msgQ |
679 | , perSessionPublicKey = pubKey | 679 | , perSessionPublicKey = pubKey |
680 | , perSessionAddr = sockAddr | 680 | , perSessionAddr = sockAddr |
681 | , perSessionNumVar = msgNumVar | 681 | , perSessionNumVar = msgNumVar |
682 | , perSessionDropCount = dropCntVar | ||
682 | }) = do | 683 | }) = do |
683 | num <- atomically (readTVar msgNumVar) | 684 | num <- atomically (readTVar msgNumVar) |
685 | dropped <- atomically (readTVar dropCntVar) | ||
684 | as <- atomically (packetQueueViewList msgQ) | 686 | as <- atomically (packetQueueViewList msgQ) |
685 | let (h,u) = partition (fst . snd) as | 687 | let (h,u) = partition (fst . snd) as |
686 | countHandled = length h | 688 | countHandled = length h |
687 | countUnhandled = length u | 689 | countUnhandled = length u |
688 | return [ show (Tox.key2id pubKey) -- "Key" | 690 | return [ show (Tox.key2id pubKey) -- "Key" |
689 | , show num -- "NextMsg" | 691 | , show num -- "NextMsg" |
692 | , show dropped -- "Dropped" | ||
690 | , show countHandled -- "Handled" | 693 | , show countHandled -- "Handled" |
691 | , show countUnhandled -- "Unhandled" | 694 | , show countUnhandled -- "Unhandled" |
692 | ] | 695 | ] |
@@ -1248,7 +1251,8 @@ announceToxJabberPeer echan laddr saddr pingflag tsrc tsnk | |||
1248 | data PerSession = PerSession { perSessionMsgs :: PacketQueue (Bool{-Handled?-},Tox.CryptoMessage) | 1251 | data PerSession = PerSession { perSessionMsgs :: PacketQueue (Bool{-Handled?-},Tox.CryptoMessage) |
1249 | , perSessionPublicKey :: PublicKey | 1252 | , perSessionPublicKey :: PublicKey |
1250 | , perSessionAddr :: SockAddr | 1253 | , perSessionAddr :: SockAddr |
1251 | , perSessionNumVar :: TVar Word32 | 1254 | , perSessionNumVar :: TVar Word32 |
1255 | , perSessionDropCount :: TVar Word32 | ||
1252 | } | 1256 | } |
1253 | 1257 | ||
1254 | main :: IO () | 1258 | main :: IO () |
@@ -1572,12 +1576,14 @@ main = runResourceT $ liftBaseWith $ \resT -> do | |||
1572 | -- allsessionsMap <- atomically $ readTVar (netCryptoSessions netCryptoSessionsState) | 1576 | -- allsessionsMap <- atomically $ readTVar (netCryptoSessions netCryptoSessionsState) |
1573 | let sockAddr = Tox.ncSockAddr netcrypto | 1577 | let sockAddr = Tox.ncSockAddr netcrypto |
1574 | pubKey = Tox.ncTheirPublicKey netcrypto | 1578 | pubKey = Tox.ncTheirPublicKey netcrypto |
1575 | msgQ <- atomically (Data.PacketQueue.new 10 0 :: STM (PacketQueue (Bool,Tox.CryptoMessage))) | 1579 | msgQ <- atomically (Data.PacketQueue.newOverwrite 10 0 :: STM (PacketQueue (Bool,Tox.CryptoMessage))) |
1576 | msgNumVar <- atomically (newTVar 0) | 1580 | msgNumVar <- atomically (newTVar 0) |
1581 | dropCntVar <- atomically (newTVar 0) | ||
1577 | let perSession = PerSession { perSessionMsgs = msgQ | 1582 | let perSession = PerSession { perSessionMsgs = msgQ |
1578 | , perSessionPublicKey = pubKey | 1583 | , perSessionPublicKey = pubKey |
1579 | , perSessionAddr = sockAddr | 1584 | , perSessionAddr = sockAddr |
1580 | , perSessionNumVar = msgNumVar | 1585 | , perSessionNumVar = msgNumVar |
1586 | , perSessionDropCount = dropCntVar | ||
1581 | } | 1587 | } |
1582 | atomically $ modifyTVar' sessions (perSession:) | 1588 | atomically $ modifyTVar' sessions (perSession:) |
1583 | tmchan <- atomically newTMChan | 1589 | tmchan <- atomically newTMChan |
@@ -1599,8 +1605,11 @@ main = runResourceT $ liftBaseWith $ \resT -> do | |||
1599 | handleIncoming mTyp session cm = do | 1605 | handleIncoming mTyp session cm = do |
1600 | atomically $ do | 1606 | atomically $ do |
1601 | num <- readTVar msgNumVar | 1607 | num <- readTVar msgNumVar |
1602 | enqueue msgQ num (False,cm) | 1608 | (wraps,offset) <- enqueue msgQ num (False,cm) |
1609 | capacity <- getCapacity msgQ | ||
1610 | let dropped = wraps * capacity + offset | ||
1603 | modifyTVar' msgNumVar (+1) | 1611 | modifyTVar' msgNumVar (+1) |
1612 | writeTVar dropCntVar dropped | ||
1604 | atomically $ writeTMChan tmchan cm -- (Tox.bufferData cd) | 1613 | atomically $ writeTMChan tmchan cm -- (Tox.bufferData cd) |
1605 | return Nothing | 1614 | return Nothing |
1606 | atomically $ writeTVar (Tox.ncUnrecognizedHook netcrypto) handleIncoming | 1615 | atomically $ writeTVar (Tox.ncUnrecognizedHook netcrypto) handleIncoming |