summaryrefslogtreecommitdiff
path: root/src/Network/Tox/ContactInfo.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-05-29 21:43:56 -0400
committerjoe <joe@jerkface.net>2018-05-29 21:43:56 -0400
commitdbb2e9fa0e61dbe288ae155a8141e3bc71d7e25e (patch)
tree2d1492b0e43ce111a44cfa237647ffbfcb0f50ce /src/Network/Tox/ContactInfo.hs
parentc7adc4afe5908753627d42386463604ce634de62 (diff)
setContactAddr : update ip address for tox friend.
Diffstat (limited to 'src/Network/Tox/ContactInfo.hs')
-rw-r--r--src/Network/Tox/ContactInfo.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Network/Tox/ContactInfo.hs b/src/Network/Tox/ContactInfo.hs
index 880740bf..d9d9a510 100644
--- a/src/Network/Tox/ContactInfo.hs
+++ b/src/Network/Tox/ContactInfo.hs
@@ -13,7 +13,6 @@ import Data.Maybe
13import qualified Data.Set as Set 13import qualified Data.Set as Set
14 ;import Data.Set (Set) 14 ;import Data.Set (Set)
15import Network.Tox.DHT.Transport as DHT 15import Network.Tox.DHT.Transport as DHT
16import Network.Tox.NodeId
17import Network.Tox.Onion.Transport as Onion 16import Network.Tox.Onion.Transport as Onion
18import System.IO 17import System.IO
19import Network.Socket 18import Network.Socket
@@ -32,6 +31,7 @@ data Account = Account
32 31
33data ContactEvent = OnionRouted { contact :: PublicKey, onionRouted :: OnionData } 32data ContactEvent = OnionRouted { contact :: PublicKey, onionRouted :: OnionData }
34 | PolicyChange { contact :: PublicKey, policyChange :: Policy } 33 | PolicyChange { contact :: PublicKey, policyChange :: Policy }
34 | AddrChange { contact :: PublicKey, addrChange :: SockAddr }
35 35
36data Contact = Contact 36data Contact = Contact
37 { contactKeyPacket :: Maybe (DHT.DHTPublicKey) 37 { contactKeyPacket :: Maybe (DHT.DHTPublicKey)
@@ -103,6 +103,9 @@ onionUpdate (Onion.OnionFriendRequest fr)
103policyUpdate :: Policy -> Maybe Contact -> Maybe Contact 103policyUpdate :: Policy -> Maybe Contact -> Maybe Contact
104policyUpdate policy = mergeContact nullContact { contactPolicy = Just policy } 104policyUpdate policy = mergeContact nullContact { contactPolicy = Just policy }
105 105
106addrUpdate :: SockAddr -> Maybe Contact -> Maybe Contact
107addrUpdate addr = mergeContact nullContact { contactLastSeenAddr = Just addr }
108
106updateAccount :: PublicKey -> Onion.OnionData -> Account -> STM () 109updateAccount :: PublicKey -> Onion.OnionData -> Account -> STM ()
107updateAccount remoteUserKey omsg acc = do 110updateAccount remoteUserKey omsg acc = do
108 modifyTVar' (contacts acc) $ HashMap.alter (onionUpdate omsg) (key2id remoteUserKey) 111 modifyTVar' (contacts acc) $ HashMap.alter (onionUpdate omsg) (key2id remoteUserKey)
@@ -113,6 +116,10 @@ setContactPolicy remoteUserKey policy acc = do
113 modifyTVar' (contacts acc) $ HashMap.alter (policyUpdate policy) (key2id remoteUserKey) 116 modifyTVar' (contacts acc) $ HashMap.alter (policyUpdate policy) (key2id remoteUserKey)
114 writeTChan (eventChan acc) $ PolicyChange remoteUserKey policy 117 writeTChan (eventChan acc) $ PolicyChange remoteUserKey policy
115 118
119setContactAddr :: PublicKey -> SockAddr -> Account -> STM ()
120setContactAddr remoteUserKey addr acc = do
121 modifyTVar' (contacts acc) $ HashMap.alter (addrUpdate addr) (key2id remoteUserKey)
122 writeTChan (eventChan acc) $ AddrChange remoteUserKey addr
116 123
117dnsPresentation :: ContactInfo -> STM String 124dnsPresentation :: ContactInfo -> STM String
118dnsPresentation (ContactInfo accsvar) = do 125dnsPresentation (ContactInfo accsvar) = do