summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-08-13 13:06:23 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-08-27 12:01:16 +0200
commit0ef84b829ef2b27ce73dc84ad549d6099b28c377 (patch)
tree28d1b101c4172c455b71855fabafa5d8b22e5f1b /src
parent740c55ac1989ba5093af9350a63820a818ff0202 (diff)
Network: remove socket from peer's DatagramAddress
Diffstat (limited to 'src')
-rw-r--r--src/Discovery.hs2
-rw-r--r--src/Network.hs27
2 files changed, 14 insertions, 15 deletions
diff --git a/src/Discovery.hs b/src/Discovery.hs
index f419eab..a05fdac 100644
--- a/src/Discovery.hs
+++ b/src/Discovery.hs
@@ -107,7 +107,7 @@ instance Service DiscoveryService where
let insertHelper new old | dpPriority new > dpPriority old = new
| otherwise = old
mbaddr <- case words (T.unpack addr) of
- [ipaddr, port] | DatagramAddress _ paddr <- peerAddress peer -> do
+ [ipaddr, port] | DatagramAddress paddr <- peerAddress peer -> do
saddr <- liftIO $ head <$> getAddrInfo (Just $ defaultHints { addrSocketType = Datagram }) (Just ipaddr) (Just port)
return $ if paddr == addrAddress saddr
then Just addr
diff --git a/src/Network.hs b/src/Network.hs
index 787bff9..28a8ce5 100644
--- a/src/Network.hs
+++ b/src/Network.hs
@@ -125,11 +125,11 @@ setPeerChannel Peer {..} ch = do
instance Eq Peer where
(==) = (==) `on` peerIdentityVar
-data PeerAddress = DatagramAddress Socket SockAddr
+data PeerAddress = DatagramAddress SockAddr
| PeerIceSession IceSession
instance Show PeerAddress where
- show (DatagramAddress _ saddr) = unwords $ case IP.fromSockAddr saddr of
+ show (DatagramAddress saddr) = unwords $ case IP.fromSockAddr saddr of
Just (IP.IPv6 ipv6, port)
| (0, 0, 0xffff, ipv4) <- IP.fromIPv6w ipv6
-> [show (IP.toIPv4w ipv4), show port]
@@ -139,15 +139,15 @@ instance Show PeerAddress where
show (PeerIceSession ice) = show ice
instance Eq PeerAddress where
- DatagramAddress _ addr == DatagramAddress _ addr' = addr == addr'
- PeerIceSession ice == PeerIceSession ice' = ice == ice'
- _ == _ = False
+ DatagramAddress addr == DatagramAddress addr' = addr == addr'
+ PeerIceSession ice == PeerIceSession ice' = ice == ice'
+ _ == _ = False
instance Ord PeerAddress where
- compare (DatagramAddress _ addr) (DatagramAddress _ addr') = compare addr addr'
- compare (DatagramAddress _ _ ) _ = LT
- compare _ (DatagramAddress _ _ ) = GT
- compare (PeerIceSession ice ) (PeerIceSession ice') = compare ice ice'
+ compare (DatagramAddress addr) (DatagramAddress addr') = compare addr addr'
+ compare (DatagramAddress _ ) _ = LT
+ compare _ (DatagramAddress _ ) = GT
+ compare (PeerIceSession ice ) (PeerIceSession ice') = compare ice ice'
data PeerIdentity = PeerIdentityUnknown (TVar [UnifiedIdentity -> ExceptT String IO ()])
@@ -255,13 +255,13 @@ startServer opt serverOrigHead logd' serverServices = do
forkServerThread server $ forever $ do
(msg, saddr) <- S.recvFrom sock 4096
- writeFlowIO serverRawPath (DatagramAddress sock saddr, msg)
+ writeFlowIO serverRawPath (DatagramAddress saddr, msg)
forkServerThread server $ forever $ do
(paddr, msg) <- readFlowIO serverRawPath
case paddr of
- DatagramAddress _ addr -> void $ S.sendTo sock msg addr
- PeerIceSession ice -> iceSend ice msg
+ DatagramAddress addr -> void $ S.sendTo sock msg addr
+ PeerIceSession ice -> iceSend ice msg
forkServerThread server $ forever $ do
conn <- readFlowIO serverNewConnection
@@ -625,8 +625,7 @@ mkPeer peerServer_ peerAddress = do
serverPeer :: Server -> SockAddr -> IO Peer
serverPeer server paddr = do
- sock <- readMVar $ serverSocket server
- serverPeer' server (DatagramAddress sock paddr)
+ serverPeer' server (DatagramAddress paddr)
serverPeerIce :: Server -> IceSession -> IO Peer
serverPeerIce server@Server {..} ice = do