summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Session.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/Session.hs')
-rw-r--r--src/Network/Tox/Session.hs18
1 files changed, 16 insertions, 2 deletions
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
4 ( SessionParams(..) 4 ( SessionParams(..)
5 , SessionKey 5 , SessionKey
6 , Session(..) 6 , Session(..)
7 , sTheirUserKey
8 , sClose
7 , handshakeH 9 , handshakeH
8 ) where 10 ) where
9 11
@@ -11,7 +13,7 @@ import Control.Concurrent.STM
11import Control.Monad 13import Control.Monad
12import Data.Functor.Identity 14import Data.Functor.Identity
13import Data.Word 15import Data.Word
14import Network.Socket 16import Network.Socket (SockAddr)
15 17
16import Crypto.Tox 18import Crypto.Tox
17import Data.PacketBuffer (PacketInboundEvent (..)) 19import Data.PacketBuffer (PacketInboundEvent (..))
@@ -21,7 +23,7 @@ import Network.Lossless
21import Network.QueryResponse 23import Network.QueryResponse
22import Network.SessionTransports 24import Network.SessionTransports
23import Network.Tox.Crypto.Transport 25import Network.Tox.Crypto.Transport
24import Network.Tox.DHT.Transport (Cookie,key2id) 26import Network.Tox.DHT.Transport (Cookie (..), key2id, longTermKey)
25import Network.Tox.Handshake 27import Network.Tox.Handshake
26 28
27-- | Alias for 'SecretKey' to document that it is used as the temporary Tox 29-- | Alias for 'SecretKey' to document that it is used as the temporary Tox
@@ -79,6 +81,18 @@ data Session = Session
79 , sSessionID :: Int 81 , sSessionID :: Int
80 } 82 }
81 83
84-- | Helper to obtain the remote ToxID key from the locally-issued cookie
85-- associated with the session.
86sTheirUserKey :: Session -> PublicKey
87sTheirUserKey s = longTermKey $ runIdentity cookie
88 where
89 Cookie _ cookie = handshakeCookie (sReceivedHandshake s)
90
91-- | Helper to close the 'Transport' associated with a session.
92sClose :: Session -> IO ()
93sClose s = closeTransport (sTransport s)
94
95
82-- | Call this whenever a new handshake arrives so that a session is 96-- | Call this whenever a new handshake arrives so that a session is
83-- negotiated. It always returns Nothing which makes it convenient to use with 97-- negotiated. It always returns Nothing which makes it convenient to use with
84-- 'Network.QueryResponse.addHandler'. 98-- 'Network.QueryResponse.addHandler'.