From d9159028e812f2855558ba183d3c11040d98e408 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Fri, 7 Sep 2018 23:27:49 -0400 Subject: Added some minor helper utiltities to PSQ and Network.Tox.Session. --- src/Network/Tox/Session.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/Network/Tox/Session.hs') diff --git a/src/Network/Tox/Session.hs b/src/Network/Tox/Session.hs index e8be4d01..525338b2 100644 --- a/src/Network/Tox/Session.hs +++ b/src/Network/Tox/Session.hs @@ -4,6 +4,8 @@ module Network.Tox.Session ( SessionParams(..) , SessionKey , Session(..) + , sTheirUserKey + , sClose , handshakeH ) where @@ -11,7 +13,7 @@ import Control.Concurrent.STM import Control.Monad import Data.Functor.Identity import Data.Word -import Network.Socket +import Network.Socket (SockAddr) import Crypto.Tox import Data.PacketBuffer (PacketInboundEvent (..)) @@ -21,7 +23,7 @@ import Network.Lossless import Network.QueryResponse import Network.SessionTransports import Network.Tox.Crypto.Transport -import Network.Tox.DHT.Transport (Cookie,key2id) +import Network.Tox.DHT.Transport (Cookie (..), key2id, longTermKey) import Network.Tox.Handshake -- | Alias for 'SecretKey' to document that it is used as the temporary Tox @@ -79,6 +81,18 @@ data Session = Session , sSessionID :: Int } +-- | Helper to obtain the remote ToxID key from the locally-issued cookie +-- associated with the session. +sTheirUserKey :: Session -> PublicKey +sTheirUserKey s = longTermKey $ runIdentity cookie + where + Cookie _ cookie = handshakeCookie (sReceivedHandshake s) + +-- | Helper to close the 'Transport' associated with a session. +sClose :: Session -> IO () +sClose s = closeTransport (sTransport s) + + -- | Call this whenever a new handshake arrives so that a session is -- negotiated. It always returns Nothing which makes it convenient to use with -- 'Network.QueryResponse.addHandler'. -- cgit v1.2.3