The control of flow of a HOST process is
HOST:
reading from FIFO or IMP
if a message from IMP then // message: (type,src,dst,status,msg)
if type=HOST2HOST then // a new message arrived
show (src,msg) to stderr // The style of format is left to you.
elif type=IMP2HOST // IMP replies
show (msg) to stderr
endif
endif
if a command from FIFO then // A command is a pair of integers:(host, msg).
if host = 0 then // host wants to check if IMP alive
send to IMP (HOST2IMP, 0,0,0, msg)
else // host sends a msg to another host
send to IMP (HOST2HOST, host, my_host_id, NEW, msg)
endif
endif
The control of flow of an IMP process is
IMP
reading from HOST or ring
if a message from HOST then // message: (type,dst,src,status,msg)
if type = HOST2IMP then // host asks: Are you there?
send to HOST (IMP2HOST,0,0,0,msg) // IMP replies: Your command, sir?
elif type = HOST2HOST then // host want to send a new message
if got_msg // buffer is already filled with
do nothing // the previous message.
else // buffer is empty. so store it.
store this message to buffer
got_msg := true
endif
endif
endif
if a message from ring then // message: (type,src,dst,status,msg)
if type = TOKEN then // Aha, it is my turn
if got_msg then // Yes, I have something to send
// if the stored message is (HOST2HOST, dst, src, status, msg)
dstIMP := lookupIMP( dst ) // translate from host id to imp id
srcIMP := lookupIMP( src )
sending to ring (IMP2IMP,dstIMP,srcIMP,status,msg)
else // host has nothing to send
send to ring (TOKEN, 0,0,0,0)
endif
elif type = IMP2IMP then
if dst = myIMP then // a message for me
dstHOST := lookupHOST( dst ) // translate from imp id to host id
srcHOST := lookupHOST( src )
sending to HOST (HOST2HOST, dstHOST, srcHOST, status, msg)
sending to ring (IMP2IMP, dst, src, ACK, msg) //only status changed
show something to stderr
elif src = myIMP then // an ack for me
got_msg := false // clean the buffer
send to ring (TOKEN, 0,0,0,0) // regenerate a TOKEN
show something to stderr
else
bypass it, that is, send (type, dst, src, status, msg) to ring
endif
endif
endif