From 19364a287f7083fc60beed2d6eae3dd71d27e737 Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 18 Jun 2018 06:14:11 -0400 Subject: tox: Automatically share dhtkey with roster contacts. --- src/Network/Tox.hs | 1 + src/Network/Tox/ContactInfo.hs | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'src/Network') diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 5a4c02ea..52dba0f5 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs @@ -351,6 +351,7 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do hPutStrLn stderr "Unable to establish session..." return [] +-- | Create a DHTPublicKey packet to send to a remote contact. getContactInfo :: Tox -> IO DHT.DHTPublicKey getContactInfo Tox{toxCryptoKeys,toxRouting} = join $ atomically $ do r4 <- readTVar $ DHT.routing4 toxRouting diff --git a/src/Network/Tox/ContactInfo.hs b/src/Network/Tox/ContactInfo.hs index 47c07237..9f29d587 100644 --- a/src/Network/Tox/ContactInfo.hs +++ b/src/Network/Tox/ContactInfo.hs @@ -34,6 +34,8 @@ data Account = Account data ContactEvent = OnionRouted { contact :: PublicKey, onionRouted :: OnionData } | PolicyChange { contact :: PublicKey, policyChange :: Policy } | AddrChange { contact :: PublicKey, addrChange :: SockAddr } + | SessionEstablished { contact :: PublicKey } + | SessionTerminated { contact :: PublicKey } data Contact = Contact { contactKeyPacket :: TVar (Maybe (POSIXTime,DHT.DHTPublicKey)) @@ -105,6 +107,13 @@ setContactAddr now remoteUserKey addr acc = do updateAccount' remoteUserKey acc $ addrUpdate now addr writeTChan (eventChan acc) $ AddrChange remoteUserKey addr +setEstablished :: POSIXTime -> PublicKey -> Account -> STM () +setEstablished now remoteUserKey acc = + writeTChan (eventChan acc) $ SessionEstablished remoteUserKey + +setTerminated :: POSIXTime -> PublicKey -> Account -> STM () +setTerminated now remoteUserKey acc = + writeTChan (eventChan acc) $ SessionTerminated remoteUserKey addContactInfo :: ContactInfo -> SecretKey -> STM () -- cgit v1.2.3