diff options
author | joe <joe@jerkface.net> | 2018-05-29 21:43:56 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-05-29 21:43:56 -0400 |
commit | dbb2e9fa0e61dbe288ae155a8141e3bc71d7e25e (patch) | |
tree | 2d1492b0e43ce111a44cfa237647ffbfcb0f50ce /src/Network/Tox/ContactInfo.hs | |
parent | c7adc4afe5908753627d42386463604ce634de62 (diff) |
setContactAddr : update ip address for tox friend.
Diffstat (limited to 'src/Network/Tox/ContactInfo.hs')
-rw-r--r-- | src/Network/Tox/ContactInfo.hs | 9 |
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 | |||
13 | import qualified Data.Set as Set | 13 | import qualified Data.Set as Set |
14 | ;import Data.Set (Set) | 14 | ;import Data.Set (Set) |
15 | import Network.Tox.DHT.Transport as DHT | 15 | import Network.Tox.DHT.Transport as DHT |
16 | import Network.Tox.NodeId | ||
17 | import Network.Tox.Onion.Transport as Onion | 16 | import Network.Tox.Onion.Transport as Onion |
18 | import System.IO | 17 | import System.IO |
19 | import Network.Socket | 18 | import Network.Socket |
@@ -32,6 +31,7 @@ data Account = Account | |||
32 | 31 | ||
33 | data ContactEvent = OnionRouted { contact :: PublicKey, onionRouted :: OnionData } | 32 | data 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 | ||
36 | data Contact = Contact | 36 | data Contact = Contact |
37 | { contactKeyPacket :: Maybe (DHT.DHTPublicKey) | 37 | { contactKeyPacket :: Maybe (DHT.DHTPublicKey) |
@@ -103,6 +103,9 @@ onionUpdate (Onion.OnionFriendRequest fr) | |||
103 | policyUpdate :: Policy -> Maybe Contact -> Maybe Contact | 103 | policyUpdate :: Policy -> Maybe Contact -> Maybe Contact |
104 | policyUpdate policy = mergeContact nullContact { contactPolicy = Just policy } | 104 | policyUpdate policy = mergeContact nullContact { contactPolicy = Just policy } |
105 | 105 | ||
106 | addrUpdate :: SockAddr -> Maybe Contact -> Maybe Contact | ||
107 | addrUpdate addr = mergeContact nullContact { contactLastSeenAddr = Just addr } | ||
108 | |||
106 | updateAccount :: PublicKey -> Onion.OnionData -> Account -> STM () | 109 | updateAccount :: PublicKey -> Onion.OnionData -> Account -> STM () |
107 | updateAccount remoteUserKey omsg acc = do | 110 | updateAccount 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 | ||
119 | setContactAddr :: PublicKey -> SockAddr -> Account -> STM () | ||
120 | setContactAddr remoteUserKey addr acc = do | ||
121 | modifyTVar' (contacts acc) $ HashMap.alter (addrUpdate addr) (key2id remoteUserKey) | ||
122 | writeTChan (eventChan acc) $ AddrChange remoteUserKey addr | ||
116 | 123 | ||
117 | dnsPresentation :: ContactInfo -> STM String | 124 | dnsPresentation :: ContactInfo -> STM String |
118 | dnsPresentation (ContactInfo accsvar) = do | 125 | dnsPresentation (ContactInfo accsvar) = do |