Auto generate hashable instance for SockAddr
This commit is contained in:
parent
8bf3031a87
commit
f5cc7b31b8
1 changed files with 8 additions and 8 deletions
16
src/Lib.hs
16
src/Lib.hs
|
@ -1,8 +1,10 @@
|
||||||
{-# LANGUAGE BangPatterns #-}
|
{-# LANGUAGE BangPatterns #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# LANGUAGE NoImplicitPrelude #-}
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
{-# LANGUAGE StandaloneDeriving #-}
|
||||||
{-# LANGUAGE TypeSynonymInstances #-}
|
{-# LANGUAGE TypeSynonymInstances #-}
|
||||||
|
|
||||||
module Lib
|
module Lib
|
||||||
|
@ -34,11 +36,10 @@ import qualified Network.WebSockets.Stream as WS
|
||||||
import Network.Connection (settingDisableCertificateValidation)
|
import Network.Connection (settingDisableCertificateValidation)
|
||||||
|
|
||||||
|
|
||||||
instance Hashable N.SockAddr where
|
deriving instance Generic PortNumber
|
||||||
hashWithSalt salt (N.SockAddrInet port host) = hashWithSalt salt ((fromIntegral port :: Int) + hash host)
|
deriving instance Hashable PortNumber
|
||||||
hashWithSalt salt (N.SockAddrInet6 port flow host scopeID) = hashWithSalt salt ((fromIntegral port :: Int) + hash host + hash flow + hash scopeID)
|
deriving instance Generic N.SockAddr
|
||||||
hashWithSalt salt (N.SockAddrUnix addr) = hashWithSalt salt addr
|
deriving instance Hashable N.SockAddr
|
||||||
hashWithSalt salt (N.SockAddrCan addr) = hashWithSalt salt addr
|
|
||||||
|
|
||||||
data Proto = UDP | TCP deriving (Show, Read)
|
data Proto = UDP | TCP deriving (Show, Read)
|
||||||
|
|
||||||
|
@ -91,8 +92,7 @@ runUDPServer (host, port) app = do
|
||||||
putStrLn "CLOSE tunnel"
|
putStrLn "CLOSE tunnel"
|
||||||
|
|
||||||
where
|
where
|
||||||
addNewClient :: IORef (H.HashMap N.SockAddr UdpAppData) -> N.Socket -> N.SockAddr -> ByteString
|
addNewClient :: IORef (H.HashMap N.SockAddr UdpAppData) -> N.Socket -> N.SockAddr -> ByteString -> IO UdpAppData
|
||||||
-> IO UdpAppData
|
|
||||||
addNewClient clientsCtx socket addr payload = do
|
addNewClient clientsCtx socket addr payload = do
|
||||||
sem <- newMVar payload
|
sem <- newMVar payload
|
||||||
let appData = UdpAppData { appAddr = addr
|
let appData = UdpAppData { appAddr = addr
|
||||||
|
|
Loading…
Reference in a new issue