diff options
author | joe <joe@jerkface.net> | 2018-05-22 01:40:28 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-05-22 01:40:28 -0400 |
commit | b56fb7874cda7799b2535dee81a32dcedb09c676 (patch) | |
tree | f74e9c71e2f69cb8d97ed4d4ffad5a884d755425 /Presence | |
parent | 1661192a9c84ceaad6d372bd80820a7066fa1e10 (diff) |
Configurable bind-addresses for xmpp.
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/Presence.hs | 9 | ||||
-rw-r--r-- | Presence/XMPPServer.hs | 25 |
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 | ||
142 | presenceHooks :: PresenceState -> Int -> Maybe PortNumber -> XMPPServerParameters | 142 | presenceHooks :: PresenceState -> Int -> Maybe SockAddr -- ^ client-to-server bind address |
143 | presenceHooks state verbosity mport = XMPPServerParameters | 143 | -> Maybe SockAddr -- ^ server-to-server bind address |
144 | -> XMPPServerParameters | ||
145 | presenceHooks 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 | |||
39 | import ControlMaybe | 39 | import ControlMaybe |
40 | import LockedChan | 40 | import LockedChan |
41 | import PeerResolve | 41 | import PeerResolve |
42 | import qualified Connection | ||
43 | import Util | ||
44 | import Network.Address (getBindAddress, sockAddrPort) | ||
42 | import Blaze.ByteString.Builder (Builder) | 45 | import Blaze.ByteString.Builder (Builder) |
43 | 46 | ||
44 | import Debug.Trace | 47 | import Debug.Trace |
@@ -88,11 +91,9 @@ import Data.Void (Void) | |||
88 | import System.Endian (toBE32) | 91 | import System.Endian (toBE32) |
89 | import Control.Applicative | 92 | import Control.Applicative |
90 | import System.IO | 93 | import System.IO |
91 | import qualified Connection | ||
92 | import Util | ||
93 | 94 | ||
94 | peerport :: PortNumber | 95 | -- peerport :: PortNumber |
95 | peerport = 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 | ||
1390 | peerKey :: SocketLike sock => sock -> IO (ConnectionKey,SockAddr) | 1392 | peerKey :: SocketLike sock => Maybe SockAddr -> sock -> IO (ConnectionKey,SockAddr) |
1391 | peerKey sock = do | 1393 | peerKey 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 | ||
1400 | clientKey :: SocketLike sock => sock -> IO (ConnectionKey,SockAddr) | 1403 | clientKey :: 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) |