protocol web6 initstate 0 is -- version with reply filtering for dealing with symbolic links -- clinton/begin/arafat are aliases, router memorize which (client,server) is called fun getSetS (client: host, server : host, tcph : tcp, ss : (int*host*host) hash_table, ps :int) : int = if (tcpSYN(tcph)) then ( -- assign to the client the server ps+1 if (ps >= 1) then ( -- println ("SYN 0"); insert (ss, hashKey(tcpSrc(tcph)), (0, client, server)); 0 ) else ( -- println ("SYN 1"); insert (ss, hashKey(tcpSrc(tcph)), (ps+1, client, server)); ps+1 ) ) else try (#1 find (ss, hashKey(tcpSrc(tcph)))) handle NoEntry => (ps) fun getServerPhy (tcph : tcp, client: host, ss : (int*host*host) hash_table) : (int*host) = try let val res : (int*host*host) = find (ss, hashKey(tcpDst(tcph))) in if ((#2 res) = client) then (#1 res, #3 res) else ( -- bad table value, reset it println ("reset hash_table"); -- insert (ss, hashKey(tcpSrc(tcph)), (-1, client, 131.254.60.81)); insert (ss, hashKey(tcpSrc(tcph)), (-1, client, GATEWAY)); -- (-1, 131.254.60.81) (-1, GATEWAY) ) end handle NoEntry => (-1, GATEWAY) stream network(ps : int, ss : (int*host*host) hash_table, p : ip * tcp * blob) initstate mkTable(256) is -- answers if (tcpSrc(#2 p) = 80) then ( -- do we filter the connection ? let val con : (int*host) = getServerPhy((#2 p), ipDst(#1 p), ss) in if ((#1 con) = -1) then ( OnRemote(network, p); (ps,ss) ) else ( -- replace the physical server by the logical one OnRemote(network, (ipSrcSet(#1 p, #2 con), #2 p, #3 p)); (ps,ss)) end ) else ( -- incoming requests if (tcpDst(#2 p) = 80) then ( let val con : int = getSetS (ipSrc(#1 p), ipDst(#1 p), (#2 p), ss, ps) in if (con = 0 ) then ( -- replace the logical server by clinton -- println("clinton"); -- OnRemote(network, (ipDstSet(#1 p, 192.168.2.3), #2 p, #3 p)); OnRemote(network, (ipDstSet(#1 p, SERVER1), #2 p, #3 p)); (con,ss) ) else ( -- replace the logical server by begin -- println("begin"); -- OnRemote(network, (ipDstSet(#1 p, 131.254.60.109), #2 p, #3 p)); OnRemote(network, (ipDstSet(#1 p, SERVER2), #2 p, #3 p)); (con,ss) ) end ) -- non web messages else ( OnRemote(network, p); (ps,ss) ) )