summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-05-22 01:40:28 -0400
committerjoe <joe@jerkface.net>2018-05-22 01:40:28 -0400
commitb56fb7874cda7799b2535dee81a32dcedb09c676 (patch)
treef74e9c71e2f69cb8d97ed4d4ffad5a884d755425 /Presence
parent1661192a9c84ceaad6d372bd80820a7066fa1e10 (diff)
Configurable bind-addresses for xmpp.
Diffstat (limited to 'Presence')
-rw-r--r--Presence/Presence.hs9
-rw-r--r--Presence/XMPPServer.hs25
2 files changed, 21 insertions, 13 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index 198012de..4aa24eb5 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -139,8 +139,10 @@ nameForClient state k = do
139 "." -> textHostName 139 "." -> textHostName
140 profile -> return profile 140 profile -> return profile
141 141
142presenceHooks :: PresenceState -> Int -> Maybe PortNumber -> XMPPServerParameters 142presenceHooks :: PresenceState -> Int -> Maybe SockAddr -- ^ client-to-server bind address
143presenceHooks state verbosity mport = XMPPServerParameters 143 -> Maybe SockAddr -- ^ server-to-server bind address
144 -> XMPPServerParameters
145presenceHooks state verbosity mclient mpeer = XMPPServerParameters
144 { xmppChooseResourceName = chooseResourceName state 146 { xmppChooseResourceName = chooseResourceName state
145 , xmppTellClientHisName = tellClientHisName state 147 , xmppTellClientHisName = tellClientHisName state
146 , xmppTellMyNameToClient = nameForClient state 148 , xmppTellMyNameToClient = nameForClient state
@@ -163,7 +165,8 @@ presenceHooks state verbosity mport = XMPPServerParameters
163 , xmppClientInformSubscription = clientInformSubscription state 165 , xmppClientInformSubscription = clientInformSubscription state
164 , xmppPeerInformSubscription = peerInformSubscription state 166 , xmppPeerInformSubscription = peerInformSubscription state
165 , xmppVerbosity = return verbosity 167 , xmppVerbosity = return verbosity
166 , xmppClientPort = fromMaybe 5222 mport 168 , xmppClientBind = mclient
169 , xmppPeerBind = mpeer
167 } 170 }
168 171
169 172
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index bc5e88da..bcd75ee2 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -39,6 +39,9 @@ import EventUtil
39import ControlMaybe 39import ControlMaybe
40import LockedChan 40import LockedChan
41import PeerResolve 41import PeerResolve
42import qualified Connection
43import Util
44import Network.Address (getBindAddress, sockAddrPort)
42import Blaze.ByteString.Builder (Builder) 45import Blaze.ByteString.Builder (Builder)
43 46
44import Debug.Trace 47import Debug.Trace
@@ -88,11 +91,9 @@ import Data.Void (Void)
88import System.Endian (toBE32) 91import System.Endian (toBE32)
89import Control.Applicative 92import Control.Applicative
90import System.IO 93import System.IO
91import qualified Connection
92import Util
93 94
94peerport :: PortNumber 95-- peerport :: PortNumber
95peerport = 5269 96-- peerport = 5269
96-- clientport :: PortNumber 97-- clientport :: PortNumber
97-- clientport = 5222 98-- clientport = 5222
98 99
@@ -217,7 +218,8 @@ data XMPPServerParameters =
217 , -- | Called when a remote peer informs us of our subscription status. 218 , -- | Called when a remote peer informs us of our subscription status.
218 xmppPeerInformSubscription :: IO () -> ConnectionKey -> Stanza -> IO () 219 xmppPeerInformSubscription :: IO () -> ConnectionKey -> Stanza -> IO ()
219 , xmppVerbosity :: IO Int 220 , xmppVerbosity :: IO Int
220 , xmppClientPort :: PortNumber -- 5222 221 , xmppClientBind :: Maybe SockAddr
222 , xmppPeerBind :: Maybe SockAddr
221 } 223 }
222 224
223 225
@@ -1387,14 +1389,15 @@ data PeerState
1387 | PeerConnected (TChan Stanza) 1389 | PeerConnected (TChan Stanza)
1388-} 1390-}
1389 1391
1390peerKey :: SocketLike sock => sock -> IO (ConnectionKey,SockAddr) 1392peerKey :: SocketLike sock => Maybe SockAddr -> sock -> IO (ConnectionKey,SockAddr)
1391peerKey sock = do 1393peerKey outgoingPeerPort sock = do
1392 addr <- getSocketName sock 1394 addr <- getSocketName sock
1393 peer <- 1395 peer <-
1394 sIsConnected sock >>= \c -> 1396 sIsConnected sock >>= \c ->
1395 if c then getPeerName sock -- addr is normally socketName 1397 if c then getPeerName sock -- addr is normally socketName
1396 else return addr -- Weird hack: addr is would-be peer name 1398 else return addr -- Weird hack: addr is would-be peer name
1397 laddr <- getSocketName sock 1399 laddr <- getSocketName sock
1400 let peerport = fromMaybe 5269 $ outgoingPeerPort >>= sockAddrPort
1398 return $ (PeerKey (peer `withPort` fromIntegral peerport),laddr) 1401 return $ (PeerKey (peer `withPort` fromIntegral peerport),laddr)
1399 1402
1400clientKey :: SocketLike sock => sock -> IO (ConnectionKey,SockAddr) 1403clientKey :: SocketLike sock => sock -> IO (ConnectionKey,SockAddr)
@@ -1833,7 +1836,7 @@ xmppServer xmpp = do
1833 let (r,gen') = System.Random.next gen 1836 let (r,gen') = System.Random.next gen
1834 return $ r `mod` 2000 -- maximum 2 seconds of fuzz 1837 return $ r `mod` 2000 -- maximum 2 seconds of fuzz
1835 liftIO . wlog $ "pingfuzz = " ++ show pingfuzz 1838 liftIO . wlog $ "pingfuzz = " ++ show pingfuzz
1836 let peer_params = (connectionDefaults peerKey) 1839 let peer_params = (connectionDefaults $ peerKey $ xmppPeerBind xmpp)
1837 { pingInterval = 15000 + pingfuzz 1840 { pingInterval = 15000 + pingfuzz
1838 , timeout = 2000 1841 , timeout = 2000
1839 , duplex = False } 1842 , duplex = False }
@@ -1846,9 +1849,11 @@ xmppServer xmpp = do
1846 myThreadId >>= flip labelThread ("XMPP.monitor") 1849 myThreadId >>= flip labelThread ("XMPP.monitor")
1847 monitor sv peer_params xmpp 1850 monitor sv peer_params xmpp
1848 hPutStrLn stderr $ "Starting peer listen" 1851 hPutStrLn stderr $ "Starting peer listen"
1849 control sv (Listen peerport peer_params) 1852 peer_bind <- maybe (getBindAddress "5269" True) return $ xmppPeerBind xmpp
1853 control sv (Listen peer_bind peer_params)
1850 hPutStrLn stderr $ "Starting client listen" 1854 hPutStrLn stderr $ "Starting client listen"
1851 control sv (Listen (xmppClientPort xmpp) client_params) 1855 client_bind <- maybe (getBindAddress "5222" True) return $ xmppClientBind xmpp
1856 control sv (Listen client_bind client_params)
1852 return XMPPServer { _xmpp_sv = sv, _xmpp_peer_params = peer_params } 1857 return XMPPServer { _xmpp_sv = sv, _xmpp_peer_params = peer_params }
1853 1858
1854#if MIN_VERSION_stm(2,4,0) 1859#if MIN_VERSION_stm(2,4,0)