summaryrefslogtreecommitdiff
path: root/dht/examples/toxrelay.hs
blob: d6b0da173c0b0c65116f58b778713a58cabaa296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Network.Address (getBindAddress,sockAddrPort)
import Network.SocketLike
import Network.StreamServer
import Network.Tox.Onion.Transport hiding (encrypt,decrypt)
import Network.Tox.Relay
import Crypto.Tox

import DPut
import DebugTag

socketPort s = sockAddrPort <$> getSocketName s

main :: IO ()
main = do
    udp_addr <- getBindAddress "33445" True
    let sendOnion :: SockAddr -> OnionRequest N1 -> IO ()
        sendOnion _ _ = return ()
    setVerbose XNetCrypto
    crypto <- newCrypto
    (h,sendTCP) <- tcpRelay crypto udp_addr sendOnion
    boundPort <- socketPort $ listenSocket h
    putStrLn $ "Listening on port: " ++ show boundPort

    putStrLn $ "ENTER to quit..."
    s <- getLine

    quitListening h