” CSE 130-02编程 辅导、C/C++程序语言调试、 写作c++编程Assignment 03CSE 130-02: Principles of Computer System Design, Spring 2021Due: Thursday, June 3 at 11:59PMGoalsThe goals for Assignment 3 are to create an HTTP reverse proxy with cache. That means thatyour program will act as an HTTP server but will actually forward received requests to therequested objects origin server in Case the object is not cached locally, and then forward theresponse from the origin server to the original client. In order to avoid sending requests toservers and thus reduce response time and traffic on the network, the proxy cache (or proxyserver) will keep copies of objects returned from previous GET requests in a local cache inmemory. If a future GET request is made for a cached object, the proxy will return the cachedcopy as long as the cached Copy is recent enough. Thus your program will act both as serverand a client.We will provide you with a working HTTP server executable that you can use to test your proxyserver, and we recommend you use this instead of your Assignment 1 HTTP serverimplementation (the provided executable implements more features). Your main goal is toimplement the reverse proxy. That said, your reverse proxy server will have to handle the sametypes of requests that you have seen before (GET, HEAD and PUT), and must supportpersistent connections.As usual, you must have a design document along with your README.md in your git repository.Your code must build an executable named httpsproxy using make.Programming assignment: HTTP reverse proxyDesign documentBefore writing code for this assignment, as with every other assignment, you must write up adesign document. Your design document must be called DESIGN.pdf, and must be in PDFformat (you can easily convert other document formats, including plain text, to PDF).Your design document should describe the design of your code in enough detail that aknowledgeable programmer could duplicate your work. This includes descriptions of the datastructures you use, non-trivial algorithms and formulas, and a description of each function withits purpose, inputs, outputs, and assumptions it makes about inputs or outputs.Write your design document Before you start writing code. Itll make writing code a loteasier. It will help you think about what you need to do for this assignment, and it can help youidentify possible problems with your planned implementation before you have invested hours init. Also, if you want help with your code, the first thing were going to ask for is your designdocument. Were happy to help you with the design, but we cant debug code without a designany more than you can.Since a lot of the system in Assignment 3 is similar to Assignments 1 and 2, we expect youregoing to copy a good part of your design from your previous designs. This is fine, as long asits your previous assignment youre copying from. This will let you focus on the new stuff inAssignment 3.Start early on the design. This program can be built independently of previous assignments, butif you didnt get the previous assignments to work, you will probably need help. Please see thecourse staff ASAP for help in that case.TESTING AND ASSIGNMENT QUESTIONIn the design document, you will also describe the testing you did on your program and answerany short questions below. The testing can be unit testing (testing of individual functions orsmaller pieces of the program) or whole-system testing, which involves running your code inparticular scenarios.For Assignment 3, please answer the following questions:● Using a large file (e.g. 100 MiB adjust according to your computers capacity) and theprovided HTTP server:○ Start the server with only one thread in the same directory as the large file (sothat it can provide it to requests);○ Start your proxy with no cache and request the file ten times. How long does ittake?○ Now stop your proxy and start again, this time with cache enabled for that file.Request the same file ten times. How long does it take?● Aside from caching, What other uses can you consider for a reverse proxy?Program functionalityYou may not use standard libraries for HTTP; you have to implement this yourself. You may usestandard networking (and file system) system calls, but not any FILE * calls except for printingto the screen (e.g., error messages). Note that string functions like sprintf() and sscanf()arent FILE * calls.Your code must be in C and be compiled with no errors or warnings using the following flags:-Wall -Wextra -Wpedantic -WshadowOnce again your program will take a port number as a parameter, but this time it will be followedby another port number to identify the address of the HTTP server. Unlike Assignment 2, yourreverse proxy does not need to be multithreaded. Those two parameters can beaccompanied by three optional parameters that configure the cache: c, a non-negative integerspecifying the capacity of the cache (the number of items that can be stored); m, anon-negative integer specifying the maximum file size to be stored in the cache; u, a flagoption that enables Least Recently Used (LRU) replacement policy the default replacementpolicy will be First In First Out (FIFO).. The default values for c and m will be 3 and 65536,respectively. The following examples are then valid:● ./ httpsproxy 9090 8080 -c 4 -u○ Starts httpsproxy on port 9090○ Communicates with a server running on port 8080○ Cache can hold four files○ Each file in cache can have at most 65536 bytes○ The replacement policy is LRU● ./ httpsproxy 8181 1234○ Starts httpsproxy on port 8181○ Communicates with a server running on port 1234○ Cache can hold three files○ Each file in cache can have at most 65536 bytes○ The replacement policy defaults to FIFO (no u option is given)● ./ httpsproxy -m 100 7373 2525○ Starts httpsproxy on port 7373○ Communicates with a server running on port 2525○ Cache can hold three files○ Each file in cache can have at most 100 bytes○ The replacement policy defaults to FIFO (no u option is given)● ./ httpsproxy 8383 -c 1 -u 3434 -m 100000000○ Starts httpsproxy on port 8383○ Communicates with a server running on port 3434○ Cache can hold one file○ Each file in cache can have at most 100000000 bytes○ The replacement policy is LRU● ./ httpsproxy 7654 -m 512 -c 4 1234○ Starts httpsproxy on Port 7654○ Communicates with a server running on port 1234○ Cache can hold four files○ Each file in cache can have at most 512 bytes○ The replacement policy defaults to FIFO (no u option is given)ProxyingYou are implementing a reverse proxy, which means that the client is not aware that it iscommunicating through a proxy. That means your proxy will receive requests from the client inthe same way that your previous server received them. The proxy will forward requests to theserver when the requested object is not cached locally, then receive the correspondingresponses from the server and forward them to the client. When the proxy receives a GETrequest for a resource that is cached, it should verify that the cached copy is not obsolete bysending a HEAD request to the server and checking the Last-Modified header line, whose valueis a date/time for when the requested object was last modified. The provided HTTP serveralready implements this header so you can use it directly. An example of the Last-Modifiedheader is given below.Last-Modified: Wed, 21 Oct 2015 07:28:00 GMTYour reverse proxy should compare the last modified date with the age of the stored object. Ifthe stored object is the same age or is newer, the proxy can respond directly to the clientwithout forwarding to the server (it will still have to check if the file is not obsolete, however see Caching). Otherwise the proxy should forward the request to the server as usual.CachingYour proxy has a number of parameters defining how the cache will work. The first parameter,specified by the option s, defines how many items the cache can hold. That is just the numberof files that can exist in the cache at once. If another file were to be added to the cache once itreaches the maximum number of files, then the new file should replace one of the existing filesin the cache, according to a replacement policy.The second parameter, specified by the option m, defines the maximum size of a file to becached. That is the size in bytes, as present in the Content-Length header line of a response toa GET request. Your proxy Should only add to its cache files that are equal in size or smallerthan this value. What if the file is larger? In that case the file will not be stored in the cache.The third parameter is the replacement policy. The default policy is First In First Out (FIFO),meaning that if a file has to be replaced, the file that was the oldest to be added to the cacheshould be replaced. If the flag u is provided when starting the proxy, the policy will be insteadLeast Recently Used (LRU), meaning that the file to be replaced is the one that has spent themost time in the cache without being requested.As an example of how these two replacement policies differ, consider three consecutivesrequests for files A, B, and A again, with caching of both files. If a fourth request for file Carrives, and the cache can only hold two files, FIFO will result in A leaving the cache, because itwas added first, while LRU will result in B leaving the cache, because A was requested morerecently.Cached files should be held in memory, without creating any files in disk.Testing your codeYou should test your code on your own system. You can run the server and the proxy onlocalhost using a port number above 1024 (e.g., 8888). Come up with requests you canmake of your server, and try them using curl(1). curl takes a URL and will make requestsfor those. By default these requests are of the GET type. Some useful options:● -T file: makes curl send a PUT request, sending the contents of file. file doesnot need to match the resource name in the URL;● -I: makes curl send a HEAD request;● -v: runs curl in verbose mode. By default curl will only print the body of the receivedresponse (or the full response if it sent a HEAD request). In verbose mode curl will alsoprint the request and the response headers, identified by a if curl is sending it and a if curl is receiving it;● -o file curl saves the output to file;curl can also send multiple requests if it has multiple URLs as parameters. As with theprevious assignment, connections are persistent and any connection may contain multiplerequests. Note that youll need to Run your server in one terminal, and make requests usingcurl in a separate terminal. You can see examples of curl commands in the Hints section. Formore on curl check httpss://everything.curl.dev/ https/requestsRemember that in this assignment you are working on a proxy that will communicatewith a server, so your curl requests should be directed towards the proxy. That is, if theserver is running on port 8080 and the proxy is on port 9090, you would use the command● curl https://localhost:9090/01234abcde01234to request file 01234abcde01234 through the proxy.You might also consider cloning a new copy of your repository (from GitLab) to a clean directoryto see if it builds properly, and runs as you expect. Thats an easy way to tell if your repositoryhas all of the right files in it. You can then delete the newly-cloned copy of the directory on yourlocal machine once youre done with it.READMEAs for previous assignments, your repository must include (README.md). The README.md fileshould be short, and contain any instructions necessary for running your code. You should alsolist limitations or issues in README.md, telling a user if there are any known issues with yourcode.Submitting your assignmentAll of your files for Assignment 1 must be in the asgn1 directory in your git. When you pushyour repository to GitLab@UCSC, make sure to include the following:● There are no bad files in the asgn3 (i.e., object files).● Your assignment builds in asgn3 using make to produce httpsproxy.● All required files (source files, DESIGN.pdf, README.md) are present in asgn3. Notethat you do not have to write a client program nor a server, only the proxy.After pushing your submission to GitLab, submit your commit id to this Google Form: httpss://forms.gle/QSh7EnfxuN48Xzbv5Hints● Start early on the design. This program can be built independently of previousassignments, but if you didnt get the previous assignments to work, you will probablyneed help. Please see the course staff ASAP for help in that case.● Reuse your code from assignments 1 and 2. (No need to cite this)● We have updated the Skeleton code for this assignment. It now has one function tocreate a socket as a client. You can use it, or you can just copy the new function to thecode base you have already built.● Aggressively check for and report errors via a response. Transfers may be aborted onerrors. However, the server doesnt exit on an error; it deals with the error appropriately(sending the corresponding error code for the client if possible) and ends the connectionin that thread, leaving the thread free to handle another connection.● Use getopt(3) to parse options from the command line. Read the man pages and seeexamples on how its used. Ask the course staff if you have difficulty using it afterreading this material.● Your commit must contain the following files:○ README.md○ DESIGN.pdf○ Makefile○ source file(s) for the serverIt may not contain any .o files or other compiled files. It may not contain data files thatyou create for testing Either. You may, if you wish, include the source files for yourDESIGN.pdf in your repo, but you dont have to. After running make, your directory mustcontain httpsproxy. Your source files must be .c files (and the corresponding headers,if needed).● You can use the strptime(3) function to parse the content of the Last-Modified headerline. To use it in your code, define __USE_XOPEN and then include time.h, in this order.That will look like this in your code:#define __USE_XOPEN#include time.h● If you need help, use online documentation such as man pages and documentation onMakefiles. If you still need help, ask the course staff.GradingAs with all of the assignments in this class, we will be grading you on all of the material you turnin, with the approximate distribution of points as follows: design document and answer toassignment question (30%); coding practices (10%); functionality (60%).Your code must compile to be Graded. A submission that cannot compile may receive amaximum grade of as low as 5%. https://www.6daixie.com/contents/13/6208.html
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。