summaryrefslogtreecommitdiff
path: root/src/Network/Tox.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-20 21:30:47 -0400
committerjoe <joe@jerkface.net>2018-06-20 21:30:47 -0400
commit7a16f326fbe7429792b155c4a963bad1f50dcbda (patch)
treebc134b0d5989a66205b30df5dc78879dfe2011e6 /src/Network/Tox.hs
parent06229147ebfa72349baec5a2b55081341ff61908 (diff)
Parameterized Account to hold arbitrary information.
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r--src/Network/Tox.hs22
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
251data Tox = Tox 251data 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
269netCrypto :: Tox -> SecretKey -> PublicKey{-UserKey -} -> IO [NetCryptoSession] 269netCrypto :: Tox extra -> SecretKey -> PublicKey{-UserKey -} -> IO [NetCryptoSession]
270netCrypto tox myseckey theirpubkey = netCryptoWithBackoff 1000000 tox myseckey theirpubkey 270netCrypto 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
273netCryptoWithBackoff :: Int -> Tox -> SecretKey -> PublicKey -> IO [NetCryptoSession] 273netCryptoWithBackoff :: Int -> Tox extra -> SecretKey -> PublicKey -> IO [NetCryptoSession]
274netCryptoWithBackoff millisecs tox myseckey theirpubkey = do 274netCryptoWithBackoff 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.
361getContactInfo :: Tox -> IO DHT.DHTPublicKey 361getContactInfo :: Tox extra -> IO DHT.DHTPublicKey
362getContactInfo Tox{toxCryptoKeys,toxRouting} = join $ atomically $ do 362getContactInfo 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)
420newTox keydb addr mbSessionsState suppliedDHTKey = do 420newTox 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
509onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) 509onionTimeout :: Tox extra -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int)
510onionTimeout Tox { toxOnionRoutes = or } (DHT.TransactionId n8 _) od = lookupTimeout or n8 od 510onionTimeout Tox { toxOnionRoutes = or } (DHT.TransactionId n8 _) od = lookupTimeout or n8 od
511 511
512routing4nodeInfo :: DHT.Routing -> IO NodeInfo 512routing4nodeInfo :: DHT.Routing -> IO NodeInfo
513routing4nodeInfo (DHT.routing4 -> tv) = R.thisNode <$> readTVarIO tv 513routing4nodeInfo (DHT.routing4 -> tv) = R.thisNode <$> readTVarIO tv
514 514
515dnssdAnnounce :: Tox -> IO () 515dnssdAnnounce :: Tox extra -> IO ()
516dnssdAnnounce (toxRouting -> r) = do 516dnssdAnnounce (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
520dnssdDiscover :: Tox -> NodeInfo -> IO () 520dnssdDiscover :: Tox extra -> NodeInfo -> IO ()
521dnssdDiscover (toxDHT -> client) ni = void $ DHT.ping client ni 521dnssdDiscover (toxDHT -> client) ni = void $ DHT.ping client ni
522 522
523forkTox :: Tox -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ()) 523forkTox :: Tox extra -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ())
524forkTox tox = do 524forkTox tox = do
525 _ <- forkListener "toxHandshakes" (toxHandshakes tox) 525 _ <- forkListener "toxHandshakes" (toxHandshakes tox)
526 _ <- forkListener "toxToRoute" (toxToRoute tox) 526 _ <- forkListener "toxToRoute" (toxToRoute tox)