From f5cc7b31b8f9d3d96073e909e8855ecbb7bbfbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Er=C3=A8be?= Date: Sun, 22 May 2016 19:27:13 +0200 Subject: [PATCH] Auto generate hashable instance for SockAddr --- src/Lib.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Lib.hs b/src/Lib.hs index f5b2abc..b0e8f16 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -1,8 +1,10 @@ {-# LANGUAGE BangPatterns #-} -{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeSynonymInstances #-} module Lib @@ -34,11 +36,10 @@ import qualified Network.WebSockets.Stream as WS import Network.Connection (settingDisableCertificateValidation) -instance Hashable N.SockAddr where - hashWithSalt salt (N.SockAddrInet port host) = hashWithSalt salt ((fromIntegral port :: Int) + hash host) - hashWithSalt salt (N.SockAddrInet6 port flow host scopeID) = hashWithSalt salt ((fromIntegral port :: Int) + hash host + hash flow + hash scopeID) - hashWithSalt salt (N.SockAddrUnix addr) = hashWithSalt salt addr - hashWithSalt salt (N.SockAddrCan addr) = hashWithSalt salt addr +deriving instance Generic PortNumber +deriving instance Hashable PortNumber +deriving instance Generic N.SockAddr +deriving instance Hashable N.SockAddr data Proto = UDP | TCP deriving (Show, Read) @@ -91,8 +92,7 @@ runUDPServer (host, port) app = do putStrLn "CLOSE tunnel" where - addNewClient :: IORef (H.HashMap N.SockAddr UdpAppData) -> N.Socket -> N.SockAddr -> ByteString - -> IO UdpAppData + addNewClient :: IORef (H.HashMap N.SockAddr UdpAppData) -> N.Socket -> N.SockAddr -> ByteString -> IO UdpAppData addNewClient clientsCtx socket addr payload = do sem <- newMVar payload let appData = UdpAppData { appAddr = addr