diff options
author | joe <joe@jerkface.net> | 2018-06-20 21:30:47 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-20 21:30:47 -0400 |
commit | 7a16f326fbe7429792b155c4a963bad1f50dcbda (patch) | |
tree | bc134b0d5989a66205b30df5dc78879dfe2011e6 /src/Network/Tox.hs | |
parent | 06229147ebfa72349baec5a2b55081341ff61908 (diff) |
Parameterized Account to hold arbitrary information.
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r-- | src/Network/Tox.hs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 20302343..a13a4f10 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -248,7 +248,7 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do | |||
248 | in client | 248 | in client |
249 | return $ either mkclient mkclient tblvar handlers | 249 | return $ either mkclient mkclient tblvar handlers |
250 | 250 | ||
251 | data Tox = Tox | 251 | data Tox extra = Tox |
252 | { toxDHT :: DHT.Client | 252 | { toxDHT :: DHT.Client |
253 | , toxOnion :: Onion.Client RouteId | 253 | , toxOnion :: Onion.Client RouteId |
254 | , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData) | 254 | , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData) |
@@ -260,17 +260,17 @@ data Tox = Tox | |||
260 | , toxTokens :: TVar SessionTokens | 260 | , toxTokens :: TVar SessionTokens |
261 | , toxAnnouncedKeys :: TVar Onion.AnnouncedKeys | 261 | , toxAnnouncedKeys :: TVar Onion.AnnouncedKeys |
262 | , toxOnionRoutes :: OnionRouter | 262 | , toxOnionRoutes :: OnionRouter |
263 | , toxContactInfo :: ContactInfo | 263 | , toxContactInfo :: ContactInfo extra |
264 | , toxAnnounceToLan :: IO () | 264 | , toxAnnounceToLan :: IO () |
265 | , toxMgr :: Manager ToxProgress Key | 265 | , toxMgr :: Manager ToxProgress Key |
266 | } | 266 | } |
267 | 267 | ||
268 | -- | initiate a netcrypto session, blocking | 268 | -- | initiate a netcrypto session, blocking |
269 | netCrypto :: Tox -> SecretKey -> PublicKey{-UserKey -} -> IO [NetCryptoSession] | 269 | netCrypto :: Tox extra -> SecretKey -> PublicKey{-UserKey -} -> IO [NetCryptoSession] |
270 | netCrypto tox myseckey theirpubkey = netCryptoWithBackoff 1000000 tox myseckey theirpubkey | 270 | netCrypto tox myseckey theirpubkey = netCryptoWithBackoff 1000000 tox myseckey theirpubkey |
271 | 271 | ||
272 | -- | helper for 'netCrypto', initiate a netcrypto session, retry after specified millisecs | 272 | -- | helper for 'netCrypto', initiate a netcrypto session, retry after specified millisecs |
273 | netCryptoWithBackoff :: Int -> Tox -> SecretKey -> PublicKey -> IO [NetCryptoSession] | 273 | netCryptoWithBackoff :: Int -> Tox extra -> SecretKey -> PublicKey -> IO [NetCryptoSession] |
274 | netCryptoWithBackoff millisecs tox myseckey theirpubkey = do | 274 | netCryptoWithBackoff millisecs tox myseckey theirpubkey = do |
275 | let mykeyAsId = key2id (toPublic myseckey) | 275 | let mykeyAsId = key2id (toPublic myseckey) |
276 | -- TODO: check status of connection here: | 276 | -- TODO: check status of connection here: |
@@ -358,7 +358,7 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do | |||
358 | return [] | 358 | return [] |
359 | 359 | ||
360 | -- | Create a DHTPublicKey packet to send to a remote contact. | 360 | -- | Create a DHTPublicKey packet to send to a remote contact. |
361 | getContactInfo :: Tox -> IO DHT.DHTPublicKey | 361 | getContactInfo :: Tox extra -> IO DHT.DHTPublicKey |
362 | getContactInfo Tox{toxCryptoKeys,toxRouting} = join $ atomically $ do | 362 | getContactInfo Tox{toxCryptoKeys,toxRouting} = join $ atomically $ do |
363 | r4 <- readTVar $ DHT.routing4 toxRouting | 363 | r4 <- readTVar $ DHT.routing4 toxRouting |
364 | r6 <- readTVar $ DHT.routing6 toxRouting | 364 | r6 <- readTVar $ DHT.routing6 toxRouting |
@@ -416,7 +416,7 @@ newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rende | |||
416 | -> SockAddr -- ^ Bind-address to listen on. | 416 | -> SockAddr -- ^ Bind-address to listen on. |
417 | -> Maybe NetCryptoSessions -- ^ State of all one-on-one Tox links. | 417 | -> Maybe NetCryptoSessions -- ^ State of all one-on-one Tox links. |
418 | -> Maybe SecretKey -- ^ Optional DHT secret key to use. | 418 | -> Maybe SecretKey -- ^ Optional DHT secret key to use. |
419 | -> IO Tox | 419 | -> IO (Tox extra) |
420 | newTox keydb addr mbSessionsState suppliedDHTKey = do | 420 | newTox keydb addr mbSessionsState suppliedDHTKey = do |
421 | (udp,sock) <- {- addVerbosity <$> -} udpTransport' addr | 421 | (udp,sock) <- {- addVerbosity <$> -} udpTransport' addr |
422 | (crypto0,sessionsState0) <- case mbSessionsState of | 422 | (crypto0,sessionsState0) <- case mbSessionsState of |
@@ -506,21 +506,21 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
506 | , toxMgr = mgr | 506 | , toxMgr = mgr |
507 | } | 507 | } |
508 | 508 | ||
509 | onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) | 509 | onionTimeout :: Tox extra -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) |
510 | onionTimeout Tox { toxOnionRoutes = or } (DHT.TransactionId n8 _) od = lookupTimeout or n8 od | 510 | onionTimeout Tox { toxOnionRoutes = or } (DHT.TransactionId n8 _) od = lookupTimeout or n8 od |
511 | 511 | ||
512 | routing4nodeInfo :: DHT.Routing -> IO NodeInfo | 512 | routing4nodeInfo :: DHT.Routing -> IO NodeInfo |
513 | routing4nodeInfo (DHT.routing4 -> tv) = R.thisNode <$> readTVarIO tv | 513 | routing4nodeInfo (DHT.routing4 -> tv) = R.thisNode <$> readTVarIO tv |
514 | 514 | ||
515 | dnssdAnnounce :: Tox -> IO () | 515 | dnssdAnnounce :: Tox extra -> IO () |
516 | dnssdAnnounce (toxRouting -> r) = do | 516 | dnssdAnnounce (toxRouting -> r) = do |
517 | ni <- routing4nodeInfo r | 517 | ni <- routing4nodeInfo r |
518 | announceToxService (nodePort ni) (nodeId ni) | 518 | announceToxService (nodePort ni) (nodeId ni) |
519 | 519 | ||
520 | dnssdDiscover :: Tox -> NodeInfo -> IO () | 520 | dnssdDiscover :: Tox extra -> NodeInfo -> IO () |
521 | dnssdDiscover (toxDHT -> client) ni = void $ DHT.ping client ni | 521 | dnssdDiscover (toxDHT -> client) ni = void $ DHT.ping client ni |
522 | 522 | ||
523 | forkTox :: Tox -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ()) | 523 | forkTox :: Tox extra -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ()) |
524 | forkTox tox = do | 524 | forkTox tox = do |
525 | _ <- forkListener "toxHandshakes" (toxHandshakes tox) | 525 | _ <- forkListener "toxHandshakes" (toxHandshakes tox) |
526 | _ <- forkListener "toxToRoute" (toxToRoute tox) | 526 | _ <- forkListener "toxToRoute" (toxToRoute tox) |