⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxy_lab.htm

📁 ICS 课程的Lab8
💻 HTM
📖 第 1 页 / 共 4 页
字号:
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=ZH-CN link=blue vlink=purple style='tab-interval:36.0pt;text-justify-trim:
punctuation'>

<div class=Section1>

<p class=MsoNormal align=center style='text-align:center;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:17.0pt;mso-font-kerning:
0pt'>Lab Assignment 8</span><span style='font-size:17.0pt;font-family:宋体;
mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman";
mso-bidi-font-family:宋体;mso-font-kerning:0pt'>:</span><span lang=EN-US
style='font-size:17.0pt;mso-font-kerning:0pt'>Logging Web Proxy<o:p></o:p></span></p>

<p class=MsoNormal align=center style='text-align:center;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:17.0pt;mso-font-kerning:
0pt'>Assigned: May 16, Due: May 31, 11:59PM<o:p></o:p></span></p>

<p class=MsoNormal align=center style='text-align:center;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:17.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=center style='text-align:center;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:11.0pt;mso-font-kerning:
0pt'>Please mail VLIW </span><span lang=EN-US style='font-size:11.0pt;
font-family:Courier;mso-bidi-font-family:Courier;mso-font-kerning:0pt'>on <span
class=SpellE>bbs</span> </span><span lang=EN-US style='font-size:11.0pt;
mso-font-kerning:0pt'>with any questions<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:11.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><b><span lang=EN-US style='font-size:14.5pt;
mso-font-kerning:0pt'>Introduction<o:p></o:p></span></b></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>A web proxy is a program which acts as a middleman between a web server
and browser. Instead of contacting the server directly to get a web page, the
browser contacts the proxy, which forwards the request on to the server. When
the server replies to the proxy, the proxy sends the reply on to the browser. <o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;text-indent:24.0pt;
mso-char-indent-count:2.0;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-size:12.0pt;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>Proxies are used for many purposes. Sometimes proxies are used in
firewalls, such that the proxy is the only way for a browser inside the
firewall to contact a server outside. The proxy may do translation on the page,
for instance, to make it viewable on a web-enabled cell phone. Proxies are used
as “<span class=SpellE>anonymizers</span>” – by stripping a request of all
identifying information, a proxy can make the browser anonymous to the server. Proxies
can even be used to cache web objects, by storing a copy of, say, an image when
a request for it is first made, and then serving that image in response to
future requests rather than going to the server. Squid (available at
http://squid.nlanr.net) is a free proxy cache.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>In this lab, you will write a simple web proxy that logs and filters
requests. In the first part of the lab, you will set up the proxy to accept
requests, check if the request should be blocked, forward the requests to the
server if not, and return the result back to the browser, keeping a log of such
requests in a disk file. In this part, you will learn how to write programs
that interact with each other over a network (socket programming), as<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span class=GramE><span lang=EN-US style='font-size:
12.0pt;mso-font-kerning:0pt'>well</span></span><span lang=EN-US
style='font-size:12.0pt;mso-font-kerning:0pt'> as some basic HTTP.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>In the second part of the lab, you will upgrade your proxy to deal with
multiple open connections at once. You may implement this in two ways: Your
proxy can spawn a separate thread to deal with each request, or it may
multiplex between the requests using the <span class=GramE>select(</span>2)
Unix system call. Either option will give you an introduction to dealing with
concurrency, a crucial systems concept. Using threads for this lab is recommended.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;text-indent:24.0pt;
mso-char-indent-count:2.0;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-size:12.0pt;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><b><span lang=EN-US style='font-size:12.0pt;
mso-font-kerning:0pt'>Logistics<o:p></o:p></span></b></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>Your code should only change <span class=SpellE>proxy.c</span> in this
lab. <o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><b><span lang=EN-US style='font-size:12.0pt;
mso-font-kerning:0pt'>Part I: Implementing a web proxy<o:p></o:p></span></b></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>The first step is implementing a basic logging proxy. When started, your
proxy should open a socket and listen for connections. When it gets a
connection (from a browser), it should accept the connection, read the request,
check if the address is blocked, and parse it to determine the server that the
request was meant for. It should then open a socket connection to that server,
send it the request, receive the reply, and forward the reply to the browser if
the request is not blocked.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;text-indent:24.0pt;
mso-char-indent-count:2.0;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-size:12.0pt;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>Notice that, since your proxy is a middleman between client and server, it
will have elements of both. It will act as a server to the web <span
class=GramE>browser,</span> and as a client to the web server. Thus you will
get experience with both client and server programming.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>To do this part, you will need to understand socket programming and basic
HTTP. See Resources section below for help on these topics.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><b><span lang=EN-US style='font-size:12.0pt;
mso-font-kerning:0pt'>Filtering<o:p></o:p></span></b></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>The blocked URLs are stored in <span class=SpellE>proxy.filter</span>. The
web proxy may read in the addresses at the initialization. When a request on a
blocked address comes from a web browser, the proxy should return <span
class=GramE>a <i>permission</i></span><i> denied </i>information to the browser
in the following format:<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;text-indent:24.0pt;
mso-char-indent-count:2.0;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-size:12.0pt;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal style='margin-left:10.5pt;mso-para-margin-left:1.0gd;
mso-layout-grid-align:none;text-autospace:none'><span lang=EN-US
style='font-family:"Courier New";mso-font-kerning:0pt'>&lt;<span class=GramE>html</span>&gt;&lt;head&gt;&lt;title&gt;Proxy
error&lt;/title&gt;&lt;/head&gt;<o:p></o:p></span></p>

<p class=MsoNormal style='margin-left:10.5pt;mso-para-margin-left:1.0gd;
mso-layout-grid-align:none;text-autospace:none'><span lang=EN-US
style='font-family:"Courier New";mso-font-kerning:0pt'>&lt;<span class=GramE>body&gt;</span>You
are not allowed to access this web page.&lt;/body&gt;&lt;/html&gt;<o:p></o:p></span></p>

<p class=MsoNormal style='margin-left:42.0pt;mso-para-margin-left:4.0gd;
mso-layout-grid-align:none;text-autospace:none'><span lang=EN-US
style='font-size:12.0pt;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><b><span lang=EN-US style='font-size:12.0pt;
mso-font-kerning:0pt'>Logging<o:p></o:p></span></b></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>Your proxy should also keep track of all requests in a log file named <span
class=SpellE>proxy.log</span>. Each line should be of the form:<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='margin-left:10.5pt;mso-para-margin-left:
1.0gd;text-align:left;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-size:12.0pt;font-family:"Courier New";mso-font-kerning:
0pt'>Date: <span class=SpellE>browserIP</span> URL size<o:p></o:p></span></p>

<p class=MsoNormal align=left style='margin-left:10.5pt;mso-para-margin-left:
1.0gd;text-align:left;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-size:12.0pt;font-family:"Courier New";mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span class=GramE><span lang=EN-US style='font-size:
12.0pt;mso-font-kerning:0pt'>where</span></span><span lang=EN-US
style='font-size:12.0pt;mso-font-kerning:0pt'> <span class=SpellE>browserIP</span>
is the IP address of the browser, URL is the URL asked for, size is the size in
bytes of the object that was returned. For instance:<o:p></o:p></span></p>

<p class=MsoNormal align=left style='margin-left:10.5pt;mso-para-margin-left:
1.0gd;text-align:left;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-family:"Courier New";mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='margin-left:10.5pt;mso-para-margin-left:
1.0gd;text-align:left;mso-layout-grid-align:none;text-autospace:none'><span
lang=EN-US style='font-family:"Courier New";mso-font-kerning:0pt'>Fri 13 Apr
2001 02:51:02 EST: 128.2.111.38 http://www.cs.cmu.edu/ 34314<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>Note that size is essentially the number of bytes received from the
server, from the time the connection is opened to the time it is closed. Only
requests that are met by a response from a server (or cached response) should
be logged. We have provided the function void format log <span class=GramE>entry(</span>)
to create a log entry in the required format.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><b><span lang=EN-US style='font-size:12.0pt;
mso-font-kerning:0pt'>Port Numbers<o:p></o:p></span></b></p>

<p class=MsoNormal align=left style='text-align:left;mso-layout-grid-align:
none;text-autospace:none'><span lang=EN-US style='font-size:12.0pt;mso-font-kerning:
0pt'>Since there will be many people working on the same machine, all of you
can not use the same port to run your proxies. You are allowed to select any
non-privileged port for your proxy, as long as it is not taken by other system
processes. Selecting a port in the upper thousands is suggested (i.e., 3070 or
8104).<o:p></o:p></span></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -