-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A purely functional TCP implementation -- -- A purely functional TCP implementation -- -- Peng Li's TCP stack based on the formal HOL4 TCP specification at -- http://www.cl.cam.ac.uk/~pes20/Netsem/, code base on the -- unified events and threads project -- http://www.seas.upenn.edu/~lipeng/homepage/unify.html. @package tcp @version 0.0.2 module Network.TCP.LTS.InMisc module Network.TCP.Type.Base type Port = Word16 newtype IPAddr IPAddr :: Word32 -> IPAddr newtype TCPAddr TCPAddr :: (IPAddr, Port) -> TCPAddr newtype SocketID SocketID :: (Port, TCPAddr) -> SocketID get_ip :: TCPAddr -> IPAddr get_port :: TCPAddr -> Port get_remote_addr :: SocketID -> TCPAddr get_local_port :: SocketID -> Port class Eq a => Seq32 a seq_val :: Seq32 a => a -> Word32 seq_lt :: Seq32 a => a -> a -> Bool seq_leq :: Seq32 a => a -> a -> Bool seq_gt :: Seq32 a => a -> a -> Bool seq_geq :: Seq32 a => a -> a -> Bool seq_plus :: (Seq32 a, Integral n) => a -> n -> a seq_minus :: (Seq32 a, Integral n) => a -> n -> a seq_diff :: (Seq32 a, Integral n) => a -> a -> n newtype SeqLocal SeqLocal :: Word32 -> SeqLocal newtype SeqForeign SeqForeign :: Word32 -> SeqForeign newtype Timestamp Timestamp :: Word32 -> Timestamp type Time = Int64 seconds_to_time :: Float -> Time data Buffer Buffer :: {-# UNPACK #-} !ForeignPtr CChar -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Buffer buf_ptr :: Buffer -> {-# UNPACK #-} !ForeignPtr CChar buf_size :: Buffer -> {-# UNPACK #-} !Int buf_offset :: Buffer -> {-# UNPACK #-} !Int buf_len :: Buffer -> {-# UNPACK #-} !Int buffer_ok :: Buffer -> Bool new_buffer :: Int -> IO Buffer buffer_empty :: Buffer buffer_to_string :: Buffer -> IO String string_to_buffer :: String -> IO Buffer buffer_split :: Int -> Buffer -> (Buffer, Buffer) buffer_merge :: Buffer -> Buffer -> [Buffer] data BufferChain BufferChain :: ![Buffer] -> {-# UNPACK #-} !Int -> BufferChain bufc_list :: BufferChain -> ![Buffer] bufc_length :: BufferChain -> {-# UNPACK #-} !Int bufferchain_head :: BufferChain -> Buffer bufferchain_tail :: BufferChain -> BufferChain bufferchain_take :: Int -> BufferChain -> BufferChain bufferchain_drop :: Int -> BufferChain -> BufferChain bufferchain_split_at :: Int -> BufferChain -> (BufferChain, BufferChain) bufferchain_collapse :: BufferChain -> IO Buffer bufferchain_ok :: BufferChain -> Bool instance Eq Timestamp instance Show Timestamp instance Seq32 Timestamp instance Eq SeqForeign instance Show SeqForeign instance Seq32 SeqForeign instance Eq SeqLocal instance Show SeqLocal instance Seq32 SeqLocal instance Eq SocketID instance Ord SocketID instance Show SocketID instance Eq TCPAddr instance Ord TCPAddr instance Eq IPAddr instance Ord IPAddr instance Show BufferChain instance Show Buffer instance Ord Timestamp instance Ord SeqForeign instance Ord SeqLocal instance Seq32 Word32 instance Show TCPAddr instance Show IPAddr module Network.TCP.Type.Datagram data TCPSegment TCPSegment :: !TCPAddr -> !TCPAddr -> !SeqLocal -> !SeqForeign -> !Bool -> !Bool -> !Bool -> !Bool -> !Bool -> !Bool -> !Int -> !Int -> !BufferChain -> !Maybe Int -> !Maybe Int -> !Maybe (Timestamp, Timestamp) -> TCPSegment tcp_src :: TCPSegment -> !TCPAddr tcp_dst :: TCPSegment -> !TCPAddr tcp_seq :: TCPSegment -> !SeqLocal tcp_ack :: TCPSegment -> !SeqForeign tcp_URG :: TCPSegment -> !Bool tcp_ACK :: TCPSegment -> !Bool tcp_PSH :: TCPSegment -> !Bool tcp_RST :: TCPSegment -> !Bool tcp_SYN :: TCPSegment -> !Bool tcp_FIN :: TCPSegment -> !Bool tcp_win :: TCPSegment -> !Int tcp_urp :: TCPSegment -> !Int tcp_data :: TCPSegment -> !BufferChain tcp_ws :: TCPSegment -> !Maybe Int tcp_mss :: TCPSegment -> !Maybe Int tcp_ts :: TCPSegment -> !Maybe (Timestamp, Timestamp) data UDPDatagram UDPDatagram :: TCPAddr -> TCPAddr -> [Char] -> UDPDatagram udp_src :: UDPDatagram -> TCPAddr udp_dst :: UDPDatagram -> TCPAddr udp_data :: UDPDatagram -> [Char] data Protocol PROTO_TCP :: Protocol PROTO_UDP :: Protocol data ICMPType ICMP_UNREACH :: Int -> ICMPType ICMP_SOURCE_QUENCE :: Int -> ICMPType ICMP_REDIRECT :: Int -> ICMPType ICMP_TIME_EXCEEDED :: Int -> ICMPType ICMP_PARAMPROB :: Int -> ICMPType data ICMPDatagram ICMPDatagram :: IPAddr -> IPAddr -> Maybe TCPAddr -> Maybe TCPAddr -> Protocol -> Maybe SeqLocal -> ICMPType -> ICMPDatagram icmp_send :: ICMPDatagram -> IPAddr icmp_recv :: ICMPDatagram -> IPAddr icmp_src :: ICMPDatagram -> Maybe TCPAddr icmp_dst :: ICMPDatagram -> Maybe TCPAddr icmp_proto :: ICMPDatagram -> Protocol icmp_seq :: ICMPDatagram -> Maybe SeqLocal icmp_t :: ICMPDatagram -> ICMPType data IPMessage TCPMessage :: !TCPSegment -> IPMessage ICMPMessage :: !ICMPDatagram -> IPMessage UDPMessage :: !UDPDatagram -> IPMessage instance Show IPMessage instance Show ICMPDatagram instance Eq ICMPDatagram instance Show ICMPType instance Eq ICMPType instance Show Protocol instance Eq Protocol instance Show UDPDatagram instance Eq UDPDatagram instance Show TCPSegment module Network.TCP.Type.Timer data Timed a Timed :: a -> Time -> Timed a timed_val :: Timed a -> a timed_exp :: Timed a -> Time timed_expires :: Time -> Timed a -> Bool timer_expires :: Time -> Time -> Bool maybe_timed_expires :: Time -> Maybe (Timed a) -> Bool maybe_timer_expires :: Time -> Maybe Time -> Bool type TimeWindow a = Maybe (Timed a) timewindow_open :: Time -> TimeWindow a -> Bool timewindow_val :: Time -> TimeWindow a -> Maybe a instance Show a => Show (Timed a) instance Eq a => Eq (Timed a) module Network.TCP.Aux.Param backlog_fudge :: Int -> Int module Network.TCP.Type.Syscall data SocketID data TCPAddr data Buffer Buffer :: {-# UNPACK #-} !ForeignPtr CChar -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Buffer buf_ptr :: Buffer -> {-# UNPACK #-} !ForeignPtr CChar buf_size :: Buffer -> {-# UNPACK #-} !Int buf_offset :: Buffer -> {-# UNPACK #-} !Int buf_len :: Buffer -> {-# UNPACK #-} !Int data SockReq SockConnect :: !IPAddr -> !TCPAddr -> SockReq SockListen :: !Port -> SockReq SockAccept :: !SocketID -> SockReq SockSend :: !SocketID -> !Buffer -> SockReq SockRecv :: !SocketID -> SockReq SockClose :: !SocketID -> SockReq data SockRsp SockOK :: SockRsp SockError :: !String -> SockRsp SockNew :: !SocketID -> SockRsp SockData :: !Buffer -> SockRsp module Network.TCP.Type.Socket data TCPState CLOSED :: TCPState LISTEN :: TCPState SYN_SENT :: TCPState SYN_RECEIVED :: TCPState ESTABLISHED :: TCPState CLOSE_WAIT :: TCPState FIN_WAIT_1 :: TCPState FIN_WAIT_2 :: TCPState CLOSING :: TCPState LAST_ACK :: TCPState TIME_WAIT :: TCPState data TCPReassSegment TCPReassSegment :: !SeqForeign -> !Bool -> !BufferChain -> TCPReassSegment trs_seq :: TCPReassSegment -> !SeqForeign trs_FIN :: TCPReassSegment -> !Bool trs_data :: TCPReassSegment -> !BufferChain data RexmtMode RexmtSyn :: RexmtMode Rexmt :: RexmtMode Persist :: RexmtMode data Rttinf Rttinf :: !Int -> !Bool -> !Time -> !Time -> !Time -> !Time -> !Int -> !Bool -> Rttinf t_rttupdated :: Rttinf -> !Int tf_srtt_valid :: Rttinf -> !Bool t_srtt :: Rttinf -> !Time t_rttvar :: Rttinf -> !Time t_rttmin :: Rttinf -> !Time t_lastrtt :: Rttinf -> !Time t_lastshift :: Rttinf -> !Int t_wassyn :: Rttinf -> !Bool data IOBC NO_OOBDATA :: IOBC OOBDATA :: Buffer -> IOBC HAD_OOBDATA :: IOBC data SocketListen SocketListen :: ![SocketID] -> ![SocketID] -> !Int -> SocketListen lis_q0 :: SocketListen -> ![SocketID] lis_q :: SocketListen -> ![SocketID] lis_qlimit :: SocketListen -> !Int data TCBTiming TCBTiming :: !Maybe Time -> !Maybe Time -> !Maybe Time -> !Maybe Time -> !Time -> !TimeWindow Timestamp -> !TimeWindow () -> TCBTiming tt_keep :: TCBTiming -> !Maybe Time tt_conn_est :: TCBTiming -> !Maybe Time tt_fin_wait_2 :: TCBTiming -> !Maybe Time tt_2msl :: TCBTiming -> !Maybe Time t_idletime :: TCBTiming -> !Time ts_recent :: TCBTiming -> !TimeWindow Timestamp t_badrxtwin :: TCBTiming -> !TimeWindow () data TCBSending TCBSending :: !BufferChain -> !SeqLocal -> !Int -> !SeqForeign -> !SeqLocal -> !Int -> !SeqLocal -> !SeqLocal -> !Int -> !Rttinf -> !Maybe (Timestamp, SeqLocal) -> !Maybe (Timed (RexmtMode, Int)) -> TCBSending sndq :: TCBSending -> !BufferChain snd_una :: TCBSending -> !SeqLocal snd_wnd :: TCBSending -> !Int snd_wl1 :: TCBSending -> !SeqForeign snd_wl2 :: TCBSending -> !SeqLocal snd_cwnd :: TCBSending -> !Int snd_nxt :: TCBSending -> !SeqLocal snd_max :: TCBSending -> !SeqLocal t_dupacks :: TCBSending -> !Int t_rttinf :: TCBSending -> !Rttinf t_rttseg :: TCBSending -> !Maybe (Timestamp, SeqLocal) tt_rexmt :: TCBSending -> !Maybe (Timed (RexmtMode, Int)) data TCBReceiving TCBReceiving :: !SeqForeign -> !Bool -> !Bool -> !Bool -> !SeqForeign -> !Int -> !SeqForeign -> !BufferChain -> ![TCPReassSegment] -> TCBReceiving last_ack_sent :: TCBReceiving -> !SeqForeign tf_rxwin0sent :: TCBReceiving -> !Bool tf_shouldacknow :: TCBReceiving -> !Bool tt_delack :: TCBReceiving -> !Bool rcv_adv :: TCBReceiving -> !SeqForeign rcv_wnd :: TCBReceiving -> !Int rcv_nxt :: TCBReceiving -> !SeqForeign rcvq :: TCBReceiving -> !BufferChain t_segq :: TCBReceiving -> ![TCPReassSegment] data TCBMisc TCBMisc :: !Int -> !Int -> !Int -> !SeqLocal -> !Bool -> !Bool -> !Bool -> !SocketID -> !SocketID -> !TCPAddr -> !TCPAddr -> !Int -> !Maybe Int -> !Bool -> !Bool -> !Bool -> !Maybe Int -> !Int -> !Int -> !SeqLocal -> !SeqForeign -> !Maybe Int -> !Maybe Int -> !IOBC -> !SeqForeign -> !Bool -> TCBMisc snd_ssthresh :: TCBMisc -> !Int snd_cwnd_prev :: TCBMisc -> !Int snd_ssthresh_prev :: TCBMisc -> !Int snd_recover :: TCBMisc -> !SeqLocal cantsndmore :: TCBMisc -> !Bool cantrcvmore :: TCBMisc -> !Bool bsd_cantconnect :: TCBMisc -> !Bool self_id :: TCBMisc -> !SocketID parent_id :: TCBMisc -> !SocketID local_addr :: TCBMisc -> !TCPAddr remote_addr :: TCBMisc -> !TCPAddr t_maxseg :: TCBMisc -> !Int t_advmss :: TCBMisc -> !Maybe Int tf_doing_ws :: TCBMisc -> !Bool tf_doing_tstmp :: TCBMisc -> !Bool tf_req_tstmp :: TCBMisc -> !Bool request_r_scale :: TCBMisc -> !Maybe Int snd_scale :: TCBMisc -> !Int rcv_scale :: TCBMisc -> !Int iss :: TCBMisc -> !SeqLocal irs :: TCBMisc -> !SeqForeign sndurp :: TCBMisc -> !Maybe Int rcvurp :: TCBMisc -> !Maybe Int iobc :: TCBMisc -> !IOBC rcv_up :: TCBMisc -> !SeqForeign tf_needfin :: TCBMisc -> !Bool data TCPSocket threadt TCPSocket :: !TCPState -> !TCBTiming -> !TCBSending -> !TCBReceiving -> !TCBMisc -> !SocketListen -> ![(SockReq, SockRsp -> threadt)] -> TCPSocket threadt st :: TCPSocket threadt -> !TCPState cb_time :: TCPSocket threadt -> !TCBTiming cb_snd :: TCPSocket threadt -> !TCBSending cb_rcv :: TCPSocket threadt -> !TCBReceiving cb :: TCPSocket threadt -> !TCBMisc sock_listen :: TCPSocket threadt -> !SocketListen waiting_list :: TCPSocket threadt -> ![(SockReq, SockRsp -> threadt)] data Host threadt Host :: !Map SocketID (TCPSocket threadt) -> ![IPMessage] -> ![threadt] -> !Timestamp -> !Time -> !(Time, Time) -> ![Port] -> Host threadt sock_map :: Host threadt -> !Map SocketID (TCPSocket threadt) output_queue :: Host threadt -> ![IPMessage] ready_list :: Host threadt -> ![threadt] ticks :: Host threadt -> !Timestamp clock :: Host threadt -> !Time next_timers :: Host threadt -> !(Time, Time) local_ports :: Host threadt -> ![Port] instance Show TCBMisc instance Show TCBReceiving instance Show TCBSending instance Show TCBTiming instance Show SocketListen instance Eq SocketListen instance Show IOBC instance Show Rttinf instance Show RexmtMode instance Eq RexmtMode instance Show TCPReassSegment instance Show TCPState instance Eq TCPState instance Show (TCPSocket t) module Network.TCP.Aux.Misc debug :: Monad m => String -> m a bound_ports :: Map SocketID (TCPSocket threadt) -> [Port] accept_incoming_q0 :: SocketListen -> Bool do_tcp_options :: Time -> Bool -> (TimeWindow Timestamp) -> Timestamp -> Maybe (Timestamp, Timestamp) calculate_bsd_rcv_wnd :: TCPSocket t -> Int mode_of :: Maybe (Timed (RexmtMode, Int)) -> Maybe RexmtMode shift_of :: Maybe (Timed (RexmtMode, Int)) -> Int computed_rto :: [Int] -> Int -> Rttinf -> Time update_rtt :: Time -> Rttinf -> Rttinf next_smaller :: [Int] -> Int -> Int tcp_reass :: SeqForeign -> [TCPReassSegment] -> (BufferChain, SeqForeign, Bool, [TCPReassSegment]) tcp_reass_prune :: SeqForeign -> [TCPReassSegment] -> [TCPReassSegment] empty_sid :: SocketID module Network.TCP.Aux.HostMonad newtype HMonad t a HMonad :: (Host t -> (a, Host t)) -> HMonad t a bindHMonad :: HMonad t a -> (a -> HMonad t b) -> HMonad t b get_host :: HMonad t (Host t) has_sock :: SocketID -> HMonad t Bool delete_sock :: SocketID -> HMonad t () insert_sock :: SocketID -> TCPSocket t -> HMonad t () runHMonad_ :: (HMonad t a) -> (Host t) -> (Host t, a) runHMonad :: (HMonad t a) -> (Host t) -> (Host t) instance Monad (HMonad t) module Network.TCP.Aux.SockMonad data HState t HState :: !Host t -> !TCPSocket t -> HState t hs_host :: HState t -> !Host t hs_sock :: HState t -> !TCPSocket t newtype SMonad t a SMonad :: (HState t -> (a, HState t)) -> SMonad t a bindSMonad :: SMonad t a -> (a -> SMonad t b) -> SMonad t b get_host_ :: SMonad t (Host t) runSMonad :: SocketID -> (SMonad t a) -> HMonad t a instance Monad (SMonad t) module Network.TCP.Aux.Output make_syn_segment :: Time -> TCPSocket t -> Timestamp -> TCPSegment tcp_close :: SocketID -> HMonad t () tcp_drop_and_close :: SocketID -> HMonad t () alloc_local_port :: HMonad t (Maybe Port) module Network.TCP.LTS.Out tcp_output_all :: SMonad t () tcp_output :: Bool -> SMonad t () tcp_close :: SocketID -> HMonad t () tcp_drop_and_close :: SocketID -> HMonad t () module Network.TCP.LTS.Time tcp_update_timers :: HMonad t () module Network.TCP.LTS.User tcp_process_user_request :: (SockReq, SockRsp -> t) -> HMonad t (Maybe t) tcp_wakeup :: SMonad threadt () module Network.TCP.LTS.InData module Network.TCP.LTS.InPassive module Network.TCP.LTS.InActive module Network.TCP.LTS.In tcp_deliver_in_packet :: TCPSegment -> HMonad threadt () module Network.TCP.Pure data Host threadt data IPMessage type Time = Int64 tcp_init_host :: Time -> [Port] -> Host t tcp_user_req :: (SockReq, SockRsp -> t) -> Host t -> (Host t, Maybe t) tcp_user_rsp :: Host t -> (Host t, [t]) tcp_packet_in :: IPMessage -> Host t -> Host t tcp_packet_out :: Host t -> (Host t, [IPMessage]) tcp_timer :: Time -> Host t -> Host t tcp_timer_check :: Time -> Host t -> IO (Host t)