diff options
Diffstat (limited to 'src/Network/Tox/Session.hs')
-rw-r--r-- | src/Network/Tox/Session.hs | 18 |
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 | |||
11 | import Control.Monad | 13 | import Control.Monad |
12 | import Data.Functor.Identity | 14 | import Data.Functor.Identity |
13 | import Data.Word | 15 | import Data.Word |
14 | import Network.Socket | 16 | import Network.Socket (SockAddr) |
15 | 17 | ||
16 | import Crypto.Tox | 18 | import Crypto.Tox |
17 | import Data.PacketBuffer (PacketInboundEvent (..)) | 19 | import Data.PacketBuffer (PacketInboundEvent (..)) |
@@ -21,7 +23,7 @@ import Network.Lossless | |||
21 | import Network.QueryResponse | 23 | import Network.QueryResponse |
22 | import Network.SessionTransports | 24 | import Network.SessionTransports |
23 | import Network.Tox.Crypto.Transport | 25 | import Network.Tox.Crypto.Transport |
24 | import Network.Tox.DHT.Transport (Cookie,key2id) | 26 | import Network.Tox.DHT.Transport (Cookie (..), key2id, longTermKey) |
25 | import Network.Tox.Handshake | 27 | import 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. | ||
86 | sTheirUserKey :: Session -> PublicKey | ||
87 | sTheirUserKey s = longTermKey $ runIdentity cookie | ||
88 | where | ||
89 | Cookie _ cookie = handshakeCookie (sReceivedHandshake s) | ||
90 | |||
91 | -- | Helper to close the 'Transport' associated with a session. | ||
92 | sClose :: Session -> IO () | ||
93 | sClose 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'. |