讲解:SE 3314B、Java、Python,c/c++Matlab| Statistics、

Abdelkader Ouda page 1 Winter 2020WESTERN UNIVERSITY - CANADAFACULTY OF ENGINEERINGDEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERINGSE 3314B – NETWORK NETWORKS APPLICATIONSAssignment 2: A Peer NodeDue Date: March 9, 2020This assignment is to be done individually. Cheating is prohibited in this assignment, that is not to showyour code to any other student, do not look at any other students code, and do not put your code in anypublic domain. However, getting help is easy and available, just ask the instructor or the TAs. At the sametime, you are encouraged to discuss your problems (if any) with other students in general terms but theactual program design and code must be your own.Please note that the consequences of cheating are much, much worse than getting a low mark for thatparticular item of work. The very best case is that you get a zero for the whole thing. Keep in mind thatturning in your own work would have at least gotten you a few marks, better than a zero.1. ObjectivesThe majority of socket programs, including GetImage/imageDB of assignment 1, follows the client-serverparadigm, where a server waits on a well-known port for clients connections. In this assignment, youll explorepeer-to-peer programming. You will be re-using most of the functions you built in assignment1 to create anew program for the peer. If you didnt manage to get these functions to work in assignment1, no problemyou still have the chance to make your new code works in this assignment. A peer is basically both a serverand a client. It accepts connections from other peers and also connects to one or more peers.2. IntroductionThe peer program takes three optional arguments on the command line:> node peer [-p : -n -v ]The -p option tells the peer program which peer to connect to initially. If this option is not provided, thepeer starts as a server listening on a random, ephemeral port. The -n option allows the user to set a peersmaximum peering relationships is equal to 2. The -v option workssimilarly to the same option for GetImage in assignment1.To bootstrap the peer-to-peer (p2p) network, we first start a peer by itself. Every time a peer runs, it printsits IP address and port number it is listening on. When a peer is run with the IPaddress:port of another peeras its command line argument, the new peer tries to join the provided peer in the p2p network by creating asocket and connecting to the peer.Abdelkader Ouda page 2 Winter 2020A peer that receives a join request will accept the peer if and only if its peer table is not full. Whether ajoin request is accepted or not, the peer sends back to the requesting peer the IPaddress:port of a peer that issaved in its peer table (if the table is not empty). This will help the newly joined peer find more peers to join.Take a step back and look at the big picture, see how code implemented in two different programs inassignment1 are now residing in the same program and how this program is serving the role of both a clientand a server. In this assignment, a custom Peer-to-Peer Transport Protocol (cPTP) for peer communicationwill be built and used. The subsequent sections describe the structure and mechanism of this protocol.The main goal of this assignment is to gain an early experience with protocol design as you are designinga simple peer-to-peer join protocol, with redirection.3. Task 1: Server SideYour first task is to implement the server side of the peer program. If peer is run without any option onthe command line, reuse your imageDB server code to announce for its IPaddress and port number and beready to accept other peers join requests.If a new peer is trying to connect to this peer and this peers peering table isnot full, handleClientJoining(sock) should accept the connection and then send back a message packet (seeFigure 1) with field set to 1, (1 means Welcome). The new peer is thenstored in the peer table. On the other hand, if the peer table is full, handleClientJoining(sock) is invoked againto receive the request but it sends back a redirect message packet -direct). All times it fills in the fields of the message: V must be set to 3314 (only in this assignment). Theholds the number of peers attached to the cPTP message packet.The figure below shows the cPTP message packet structure.00 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1V = 3314 Message TypeSenderNumber of peersReserved Peer port numberPeer IPv4 addressFigure 1: The cPTP message packet formatThis structure stores the cPTP message type isone byte, it is Welcome Re- . The sender ID is 4 bytes, thebytes, holds the number of peers included in the message pacassignment we allow each peer a maximum of 2 partners). Followed by 2 reserved bytes, not used in this4 bytes. Although each peer may have up to 2 partners, we store the IPaddress and port number of only onejoined peer.4. Task 2: Client SideOnly ifNumber ofpeers is notzeroAbdelkader Ouda page 3 Winter 2020If a peer is run with the -p option, the user must provide a known peer IP address and port number toconnect to, with the port number separated from the peer IP address by a colon. Keep in mind that, a peerjoining a p2p network simply connects to another peer, without sending any messages, so using a differentversion number with t代做SE 3314B留学生作业、代做Java编程语言作业、代写Python,c/c++课程作业 调试Matlab程序|代he -v command line option will not affect the join process.Note that Node.js would have assigned a random, ephemeral source port to the connected socket. Findout the assigned ephemeral source port number and store it along with the IPv4 address of the current host.Note also that, the program will be managing for activities on both the socket connected to the known peerand the socket on which youre listening for connection from other peers.The peer program checks for activity on each connected peers socket. If theres an incoming packet, itreceives the message and examine it packet. It first checks the version number of the received packet. If it isnot , the message will be ignored. Assuming the version number checks out, the receipt of a packetcarrying another peer causes the third peers address and port number to be printed out. If the received packetis of type 2, it printed out that the join has been declined (redirected) and exits the program. The user canthen manually try to connect to the third peer returned in the redirect packet by running the peer programagain.Youre not required to handle peer leaving the p2p network: once a peer departs, its partner peer is notrequired to clean up its peer table and be ready to accept another peer. You can assume that a peer is only torndown when the whole p2p network is being torn down. It is required, however, that when a peer leaves, itspartner does not crash.5. Sample execution runBelow is a running scenario as an example to show the execution of the program and to summarize therequirements of this assignment. After finish building the program peer, save it in four different workingfolders, p1, p2, p3, and p4. Open four command line windows, one for each of these created folders.1. On the first window, run peer program without any command line argument:p1> node peerIt should print to screen (with a different port number, depicted in bold here), not that the folder nameinformation, the program should recognize it automatically:This peer address is 127.0.0.1: 43945 located at p12. On the second window, run peer with the following command line argument (replacing the portnumber with the one printed out on the first item above:p2> node peer -p 127.0.0.1:43945It should print to screen (with different port numbers and time stamp):Connected to peer p1:43945 at timestamp: 457This peer address is 127.0.0.1:56535 located at p2Abdelkader Ouda page 4 Winter 2020Received ack from p1:43945Meanwhile, on the first window, you should see the following additional line printed to screen:This peer address is 127.0.0.1: 43945 located at p1Connected from peer 127.0.0.1:565353. On the third window, run peer with the following command line argument (replacing the portnumber with the one from the first item above)p3> node peer -p 127.0.0.1:43945It should print to screen (with different port numbers and time stamp):Connected to peer p1:43945 at timestamp: 492This peer address is 127.0.0.1:48141 located at p3Received ack from p1:43945 which is peered with: 127.0.0.1:56535Meanwhile, on the first window, you should see the following additional line printed to screen:This peer address is 127.0.0.1: 43945 located at p1Connected from peer 127.0.0.1:56535Connected from peer 127.0.0.1:481414. On the fourth window, run peer with the following command line argument (replacing the portnumber with the one from the first item above)P4> node peer -p 127.0.0.1:43945It should print to screen (with different port numbers and time stamp):Connected to peer p1:43945 at timestamp: 712This peer address is 127.0.0.1:40231 located at p4Received ack from p1:43945 which is peered with: 127.0.0.1:56535Abdelkader Ouda page 5 Winter 2020Join redirected, try to connect to the peer above.Meanwhile, on the first window, you should see the following additional line printed to screen:This peer address is 127.0.0.1: 43945 located at p1Connected from peer 127.0.0.1:56535Connected from peer 127.0.0.1:48141Peer table full: 127.0.0.1:40231 redirected5. Staying on the fourth window, run peer again with the following command line argument (replacingthe port number with the one from the fourth step item above)P4> node peer -p 127.0.0.1:56535It should print to screen (with different port numbers):Connected to peer p2:56535 at timestamp: 1090This peer address is 127.0.0.1:50095 located at p4Received ack from p2:56535 which is peered with: 127.0.0.1:43945Meanwhile, on the second window on p2, you should see the following additional line printed to screen:Connected to peer 127.0.0.1:43945 at timestamp: 457This peer address is 127.0.0.1:56535 located at p2Received ack from 127.0.0.1:43945Connected from peer 127.0.0.1:50095That ends our sample execution/test scenario and you can quit all four peers.The above is a very simple test case to check that your peers are communicating with each other. Youshould further test your p2p network with other test cases of your own. Recall that a peer is not required toaccept another peer if its partner departs.Hand InSubmit the final version of your source code (Fully commented and formatted) through OWL by the duedate mentioned above. This should include one compressed achieve file (zip file) having all JS files for the peerprogram including the package.json file and name it yourUWOID-SE3314b-assignment2.zip.转自:http://www.6daixie.com/contents/3/4931.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 222,252评论 6 516
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,886评论 3 399
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 168,814评论 0 361
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,869评论 1 299
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,888评论 6 398
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,475评论 1 312
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 41,010评论 3 422
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,924评论 0 277
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,469评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,552评论 3 342
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,680评论 1 353
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,362评论 5 351
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 42,037评论 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,519评论 0 25
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,621评论 1 274
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 49,099评论 3 378
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,691评论 2 361

推荐阅读更多精彩内容