In peer-to-peer networks such as gnutella, each host must search out other hosts. When a host finds another host, these hosts become neighbors. Often a.

Slides:



Advertisements
Similar presentations
The Internet 8th Edition Tutorial 3 Using Web-Based Services for Communication and Collaboration.
Advertisements

OSPF Header OSPF HEADER OSPF HEADER for this project Types we will use
Introduction to Computer Networks Spanning Tree 1.
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
1 The 7 layer OSI model Sending an . 2 The seven layers.
COEN 445 Communication Networks and Protocols Lab 4
MPI Program Structure Self Test with solution. Self Test 1.How would you modify "Hello World" so that only even-numbered processors print the greeting.
In peer-to-peer networks such as gnutella, each host must search out other hosts. When a host finds another host, these hosts become neighbors. Often a.
Transport Layer 3-1 Transport Layer r To learn about transport layer protocols in the Internet: m TCP: connection-oriented protocol m Reliability protocol.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
Lab2 TA Notes. Set up for Visual C++ New Workspace Win32 Console Application – This runs from a command line Chose Blank Project Add your.C file Build.
Error Checking continued. Network Layers in Action Each layer in the OSI Model will add header information that pertains to that specific protocol. On.
Ad Hoc Wireless Routing COS 461: Computer Networks
CMPT 471 Networking II Address Resolution IPv6 Neighbor Discovery 1© Janice Regan, 2012.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Mapping Internet Addresses to Physical Addresses (ARP)
Network Programming using NetLink Sockets C++ Library
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
Dsr – dynamics source routing. basics Two types of routing –On-demand / reactive Information is only collected when required, I.e., when a packet needs.
An efficient secure distributed anonymous routing protocol for mobile and wireless ad hoc networks Authors: A. Boukerche, K. El-Khatib, L. Xu, L. Korba.
LWIP TCP/IP Stack 김백규.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
1 Huffman Codes Drozdek Chapter Objectives You will be able to Construct an optimal variable bit length code for an alphabet with known probability.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
CS332, Ch. 26: TCP Victor Norman Calvin College 1.
Routing Protocols of On- Demand Dynamic Source Routing (DSR) Ad-Hoc On-Demand Distance Vector (AODV)
Computer Science I How to Configure Visual Studio.NET 2003 for C++ Colin Goble.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
The Routing Table Last Update Copyright Kenneth M. Chipps Ph.D.
Implementation of the Hangman Game in C++
Publishing Your Web Pages Ann Emmanuel SIUE Web Administrator
CMSC 341 B- Trees D. Frey with apologies to Tom Anastasio.
1 Chapter Six - Errors, Error Detection, and Error Control Chapter Six.
The Internet 8th Edition Tutorial 3 Using Web-Based Services for Communication and Collaboration.
SRL: A Bidirectional Abstraction for Unidirectional Ad Hoc Networks. Venugopalan Ramasubramanian Ranveer Chandra Daniel Mosse.
Understanding IPv6 Slide: 1 Lesson 12 IPv6 Mobility.
GPRS functionality overview in Horner OCS. GPRS functionality – Peer to Peer communication over GPRS – CSCAPE connectivity over GPRS – Data exchange using.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 4 – Logical Operators & Branching.
ICMPv6 Error Message Types Informational Message Types.
EIToolkit stub doc. main.cpp file int main(int argc, char* argv[]) { EIProperties::UseStandards(); // create the stub ExampleStub stub; stub.Start();
ECE 4110 – Internetwork Programming
1 Tips for the assignment. 2 Socket: a door between application process and end- end-transport protocol (UDP or TCP) TCP service: reliable transfer of.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
COMP2322 Lab 4 Socket Programming Toby Lam March 2, 2016.
CSC 360, Instructor: Kui Wu IPC. CSC 360, Instructor: Kui Wu Agenda 1.The need to communicate 2.Shared memory 3.Message passing.
Powerpoint Templates Page 1 Powerpoint Templates CS Networks Laboratory HANDLED BY, A.MAHESH PRIYA L/IT.
COMP2322 Lab 4 Socket Programming
Behrouz A. Forouzan TCP/IP Protocol Suite, 3rd Ed.
LINKED LISTS.
B/B+ Trees 4.7.
To do While (1) Receive hello Search for more neighbors?
Lists C++ Standard template library list
Layered Architectures
Lesson Objectives Aims Understand the following “standard algorithms”:
Chapter 6: Transport Layer (Part I)
Introduction of Transport Protocols
Sarah Diesburg Operating Systems COP 4610
Chapter 8 – Binary Search Tree
B- Trees D. Frey with apologies to Tom Anastasio
1. Open Visual Studio 2008.
CSS432 (Link Level Protocols) Reliable Transmission Textbook Ch 2.5
In peer-to-peer networks such as gnutella, each host must search out other hosts. When a host finds another host, these hosts become neighbors. Often a.
Andy Wang Operating Systems COP 4610 / CGS 5765
Delivery, Forwarding, and Routing of IP Packets
Then this information is wrong
I am A I have heard: no one A B Have heard list Have heard list.
Error Checking continued
Presentation transcript:

In peer-to-peer networks such as gnutella, each host must search out other hosts. When a host finds another host, these hosts become neighbors. Often a host will continue to search for peers until a sufficient number of hosts have been found. Lets assume that a host will continue to search for hosts until it has N neighbors. In this project, peer-to-peer neighborhoods are made and maintained. Each host maintains list of neighbors and sends hello packets to these neighbors every 10 seconds. If a host is on the neighbor list, and no hello packet is received from the host for 40 seconds, then this host is removed from the neighbor list. If a node does not have enough neighbors, then it selects an address (e.g., IP and port) at random and tries to become its neighbor.

Objectives Find N neighbors – A node is a neighbor if two-way communication is possible and verified Two-communication == bidirectional link Maintain N neighbors – If two-way communication is no longer verified, the node is no longer a neighbor

Detecting Bidirectional Links Node A has a bidirectional with node B if – Node A can hear node B – Node B can hear node A To determine if a link between node A and B is bidirectional – Node A sends a message to node B – Node B sends a message to node A saying that it can hear node A Now node A believes the link is bidirectional – Node A sends a message to node B saying that it can hear node B Now node B believes the link is bidirectional In general, to determine is links are bidirectional – Send hello messages where the message includes a list of all nodes that have been heard – Upon receiving a hello message, If you are listed as one of the nodes that has been recently heard, then the link is bidirectional Add the sender of the hello to the list of nodes that you can hear

AB I am A I have heard: no one Have heard list

AB I am A I have heard: no one Have heard list A

AB I am B I have heard: A Have heard list A

AB A I am B I have heard: A B and B hears me

AB Have heard list A I am A I have heard: B B and B hears me

AB Have heard list A and A hears me I am A I have heard: B, C, D B and B hears me

Neighbor States nothing one-way (receivable) bidirectional Received a hello and this node is not listed in the hello as a recently heard node Received a hello with this node listed as recently heard No hello received for a long time Received a hello with this node listed as recently heard No hello received for a long time Received a hello and this node is not listed as recently heard

Neighbor States nothing unidirectional Neighbors bidirectional Neighbors Received a hello and this node is not listed as recently heard Received a hello with this node listed as recently heard No hello received for a long time Received a hello with this node listed as recently heard No hello received for a long time Received a hello and this node is not listed as recently heard

Neighbor List Activity Diagram waiting Hello arrived from node B Node B is unidirectionalNeighbors Node B is bidirectionalNeighbors Node B is neither list This node is listed in the hello as a recently heard node Move B from unidirectionalNeighbors to bidirectionalNeighbors Move B from bidirectionalNeighbors to unidirectionalNeighbor This node is NOT listed in the hello as a recently heard node Put B into unidirectionalNeighbors Put B into bidirectionalNeig hbors This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node

Lists C++ Standard template library list Add the following to the top of cpp file #include using namespace std; E.g., list of ints – making a list of ints list myList; – Add an element to myList myList.push_back(1); myList.push_back(2); myList.push_back(1); – Iterate through the list and print each element for( list ::iterator it=myList.begin(); it!=myList.end(); ++it) printf(“entry=%d\n”,*it); – Remove an element from the list int elementToRemove = 2; for( list ::iterator it=myList.begin(); it!=myList.end(); ++it) { if (*it == elementToRemove) { myList.erase(it); break; // not breaking would result in a crash } } – Alternatively myList.remove(1); // removes all elements == 1. But this requires == operator, which exists for int, but might not for other types

for( list ::iterator it=myList.begin(); it!=myList.end(); ++it) – printf(“entry=%d\n”,*it); Boost foreach.hpp foreach( int x, mylist) – printf(“entry=%d\n”,x);

Classes Packet – ptr: holds the data as a char buffer – totalSize: When data is being written to the pkt, totalSize is the size of the buffer, which is Packet::bufferLength, which is 2000 When data is being read from pkt, total size is the total amount to data available for rading – offset: where data should be read or written from – E.g., writing a char c to pkt – *(char *)pkt.getPtr() = c; – Pkt.incOffset(sizeof(c )); Writing an int x to pkt – *(boost::int16_t *)pkt.getPtr() = htons((boost::int16_t)x); – pkt.incOffset(sizeof(boost:int16_t)); Reading char c from pkt – C = *(char *)pkt.getPtr(); – Pkt.incOffset(sizeof(char)(); Reading int x from pkt – X = ntohs(*(boost:int16_t *)pkt.getPtr())); – Pkt.incOffset(sizeof(boot::int16_t)); Before writing to pkt – Pkt.getReadyForWriting(); UdpSocket – E.g., bind socket to port UdpSocket udpSocket; udpSocket.bindToPort(10000); – Get packet is ready Packet pkt; If (udpSocket.checkForNewPacket(pkt, 2)>0) – // process data else – // data is not ready e.g., send pkt Packet pkt; pkt.getReadyForWriting(); …. udpSocket.sendTo(pkt,destinationHostId) // see HostId class

Classes Packet – ptr: holds the data as a char buffer – totalSize: When data is being written to the pkt, totalSize is the size of the buffer, which is Packet::bufferLength, which is 2000 When data is being read from pkt, total size is the total amount to data available for rading – offset: where data should be read or written from – E.g., writing a char c to pkt – *(char *)pkt.getPtr() = c; – Pkt.incOffset(sizeof(c )); Writing an int x to pkt – *(boost::int16_t *)pkt.getPtr() = htons((boost::int16_t)x); – pkt.incOffset(sizeof(boost:int16_t)); Reading char c from pkt – C = *(char *)pkt.getPtr(); – Pkt.incOffset(sizeof(char)(); Reading int x from pkt – X = ntohs(*(boost:int16_t *)pkt.getPtr())); – Pkt.incOffset(sizeof(boot::int16_t)); Before writing to pkt – Pkt.getReadyForWriting();

Classes UdpSocket – E.g., bind socket to port UdpSocket udpSocket; udpSocket.bindToPort(10000); – Get packet is ready Packet pkt; If (udpSocket.checkForNewPacket(pkt, 2)>0) – // process data else – // data is not ready e.g., send pkt Packet pkt; …. udpSocket.sendTo(pkt,destinationHostId) // see HostId class

Classes HostId – char _address[ADDRESS_LENGTH]; – Boost::uint16_t _port; – E.g., set address and port HostId host(address, port); – E.g., get HostId from packet Packet pkt; HostId host; If (udpSocket.checkForNewPacket(pkt, 2)>0) – host.getFromPacket(pkt); – E.g., put HostId onto packet HostId thisHost; … thisHost is the the ip and port of this host Packet pkt; thisHost.addToPacket(pkt); udpSocket.sendTo(pkt, hostId); – E.g., check if thisHost is the same as hostId If (thisHost == hostId) { – // yes, they are the same } – E.g., send pkt with thisHost to all host in allHost list Packet pkt; thisHost.addToPacket(pkt); foreach(HostId &hostid, allHost) – udpSocket.sendTo(pkt, hostId);

classes NeighborInfo – HostId hostId; // the id of neighbor – time_t timeWhenLastHelloArrived; – Functions addToPacket getFromPacket updateTimeToCurrentTime() == – Only checks hostId’s match, ignores timeWhenLastHelloArrived – E.g., Packet pkt; Foreach( NeighborInfo &neighbor, allNeighbors) – Neighbor.addToPkt(pkt);

classes HelloMessage – boost::uint8_t type // not important for this project – HostId source; – Boost::uint16_t numberOfNeighbors; – list neighbors; Functions – Show – addToPacket – getFromPacket – addToNeighborList E.g., add neighbors to helloMessage – HelloMessage helloMessage; – helloMessage.type = HELLO_MESSAGE_TYPE; – helloMessage.source = thisHost; – foreach(NeighborInfo &neighborInfo, bidirectionalNeighbors) helloMessage.addToNeighborList(neighborInfo.hostId); – Packet pkt; – helloMessage.getPktReadyForWriting…. – helloMessage.addToPacket(pkt); – udpSocket.sentTo(pkt, someDestinationHostId);

List Check if thisHost is in list of neighbors received from neighbor Packet pkt; If (udpSocket.checkForNewPacket(pkt, 2)>0) { HelloMessage helloMessage; helloMessage.getFromPacket(pkt); foreach(HostId &hostId, helloMessage.neighbors) { if (thisHost == hostId) { // yes it is } Remove element from list List neighbors; …. NeighborInfo neighborToRemove; … neighbors.remove(neighborToRemove); Remove a host List neighbors; …. HostId hostToRemove(address, port); NeighborInfo neighborToRemove(hostToRemove); neighbors.remove(neighborToRemove); /// or list ::iterator it; for(it = neighbors.begin(); it!=neighbors.end(); ++it) { if (it->hostId == hostToRemove) { neighbors.erase(it); break; // would crash without this break }

Neighbor List Activity Diagram waiting Hello arrived from node B Node B is unidirectionalNeighbors Node B is bidirectionalNeighbors Node B is neither list Move B from unidirectionalNeighbors to bidirectionalNeighbors Move B from bidirectionalNeighbors to unidirectionalNeighbors Put B into unidirectionalNeighbors Put B into bidirectionalNeighbors This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node

Neighbor List Activity Diagram waiting Hello arrived from node B checkIfInList(sender, unidirectionalNeighbors) ==true else Move B from unidirectionalNeighbors to bidirectionalNeighbors Move B from bidirectionalNeighbors to bidirectionalNeighbors Put B into unidirectionalNeighbors Put B into bidirectionalNeig hbors This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node checkIfInList(sender, bidirectionalNeighbo rs) ==true This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node

Neighbor List Activity Diagram int udpSocket.checkIfPacketIsReady( Packet &pkt, int TimeOut) Hello arrived checkIfInList( sender, unidirectionalNeighbors ) ==true else Move B from unidirectionalNeighbors to bidirectionalNeighbors Move B from bidirectionalNeighbors to unidirectionalNeighbors Put B into unidirectionalNeighbors Put B into bidirectional Neighbors checkIfInList( sender, biidirectionalNeighbors ) ==true Extract sender from hello else This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node

thisHost int main(int argc, char* argv[]) { HostId thisHost; fillThisHostIP(thisHost); // provided in someFunctions.cpp thisHost._port = atoi(argv[1]); …

checkIfThisHostIsInRecentlyHeardNeighbors foreach(HostId &advertisedNeighbor, helloMessage.neighbors) { if (advertisedNeighbor == thisHost) { // thisHost is advertised by neighbor

Neighbor List Activity Diagram int checkForNewPacket(SOCKET UDPSock, char *pkt, int TimeOut) Hello arrived checkIfInList(sender, unidirectionalNeighbors) ==true else Move B from unidirectionalNeighbors to biidirectionalNeighbors Move B from bidirectionalNeighbors to unidirectionalNeighbors Put B into bidirectionalNeighbors This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node checkIfInList(sender, bidirectionalNeighbo rs) ==true Extract sender from hello else This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node

Neighbor List Activity Diagram int checkForNewPacket(SOCKET UDPSock, char *pkt, int TimeOut) Hello arrived checkIfInList(sender, unidirectionalNeighbors) ==true else Move B from unidirectionalNeighbors to biidirectionalNeighbors Move B from bidirectionalNeighbors to unidirectionalNeighbors Put B into unidirectionalNeighbor s Put B into bidirectional Neighbors This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node checkIfInList(sender, bidirectionalNeighbo rs) ==true Extract sender from hello else This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node

Lists C++ Standard template library list #include using namespace std; Making a list of ints list myList; Add an element to myList myList.push_back(1); myList.push_back(2); myList.push_back(1); Remove an element from the list int elementToRemove = 2; myList.remove(elementToRemove); alternatively for( list iterator::it=myList.begin(); it!=myList.end(); ++it) { if (*it == elementToRemove) { myList.erase(it); break; // not breaking would result in a crash }

Objectives Find N neighbors – A node is a neighbor if two-way communication is possible and verified Two-communication == bidirectional link Maintain N neighbors – If two-way communication is no longer verified, the node is no longer a neighbor

To do While (1) – Receive hello Process neighbor states (as we just talked about) – Search for more neighbors? Check and if so, search – Update neighbor set If some neighbors have timed out, remove them – Send hello messages to neighbors Send every 10 sec

To do While (1) – Receive hello Process neighbor states (sort of like what we did) – Search for more neighbors? Check and if so, search – Update neighbor set If some neighbors have timed out, remove them – Send hello messages to neighbors Send every 10 sec

Search for more neighbors int main(int argc, char* argv[]) { bool searchingForNeighborFlag = false; readAllHostsList(argv[2], allHosts); // provided while (1) { if (bidirectionalNeighbors.size() + unidirectionalNeighbors.size() < TARGET_NUMBER_OF_NEIGHBORS && searchingForNeighborFlag ==false) { searchingForNeighborFlag = true; tempNeighbor = selectNeighborAtRandom(bidirectionalNeighbors, unidirectionalNeighbors, allHost, thisHost); // provided } ….

To do While (1) – Receive hello Process neighbor states (sort of like what we did) – Search for more neighbors? Check and if so, search – Update neighbor set If some neighbors have timed out, remove them – Send hello messages to neighbors Send every 10 sec

Neighbor List Activity Diagram int checkForNewPacket(SOCKET UDPSock, char *pkt, int TimeOut) Hello arrived checkIfInList(sender, unidirectionalNeighbors) ==true else Move B from unidirectionalNeighbors to biidirectionalNeighbors Move B from bidirectionalNeighbors to unidirectionalNeighbors Put B into bidirectionalNeighbors This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node checkIfInList(sender, bidirectionalNeighbo rs) ==true Extract sender from hello else This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node sender==tempNeighbor searchingForNeighborFlag = false checkIfThisHostIsInRecently HeardNeighbors(pkt,thisHost) ==false checkIfThisHostIsInRecently HeardNeighbors(pkt,thisHost) ==true Put sender into bidirectionalNeighbors Put sender into unidirectionalNeighbors

To do While (1) – Receive hello Process neighbor states (sort of like what we did) – Search for more neighbors? Check and if so, search – Update neighbor set If some neighbors have timed out, remove them – Send hello messages to neighbors Send every 10 sec

Neighbor List Activity Diagram int checkForNewPacket(SOCKET UDPSock, char *pkt, int TimeOut) Hello arrived checkIfInList(sender, unidirectionalNeighbors) ==true else Move B from unidirectionalNeighbors to biidirectionalNeighbors Move B from bidirectionalNeighbors to unidirectionalNeighbors Put B into bidirectionalNeighbors This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node checkIfInList(sender, bidirectionalNeighbo rs) ==true Extract sender from hello else This node is listed in the hello as a recently heard node This node is NOT listed in the hello as a recently heard node sender==tempNeighbor searchingForNeighborFlag = false checkIfThisHostIsInRecently HeardNeighbors(pkt,thisHost) ==false checkIfThisHostIsInRecently HeardNeighbors(pkt,thisHost) ==true Put sender into bidirectionalNeighbors Put sender into unidirectionalNeighbors updateLastReceivedTime

Lists foreach(NeighborInfo & neighborInfo, bidirectionalNeighbors) { – If (neighborInfo.hostId == helloMessage.source) { neighborInfo. updateTimeToCurrentTime(); break; – } }

To do While (1) – Receive hello Process neighbor states (sort of like what we did) – Search for more neighbors? Check and if so, search – Update neighbor set If some neighbors have timed out, remove them – Send hello messages to neighbors Send every 10 sec

Send hello messages to neighbors every 10 sec #include int main(int argc, char* argv[]) { …. time_t lastTimeHellosWereSent; time( &lastTimeHellosWereSent ); time_t currentTime; while (1) { time( &currentTime ); if (difftime(currentTime, lastTimeHellosWereSent) >= 10) { lastTimeHellosWereSent = currentTime; sendHellos(…) } ….

Send hello messages to neighbors every 10 sec #include int main(int argc, char* argv[]) { …. time_t lastTimeHellosWereSent; //time( &lastTimeHellosWereSent ); lastTimeHellosWereSent = 0; time_t currentTime; while (1) { time_t( &currentTime ); if (difftime(currentTime, lastTimeHellosWereSent) >= 10) { lastTimeHellosWereSent = currentTime; sendHellos(…) } ….

sendHellos(…) sendHelloToNeighbors Hello must include all heard neighbors – bidirectionalNeighbors – unidirectionalNeighbors – Not tempNeighbor Hello must be sent to – bidirectionalNeighbors – unidirectionalNeighbors – AND tempNeighbor Steps – HelloMessage helloMessage; – // fill out helloMessage – Packet pkt; – pkt.getPacketReadyForWriting(); – helloMessage.addToPacket(pkt); – // send to all neighbors udpSocket(pkt, hostId)

boost Get boost library Put it somewhere and decompress Add it to include path

Add boost to include path In visual studio: Tools ->options

Add boost to include path Along the left, find “Projects and Solutions” group Expand and find “VC++ Directories” In the upper right, select “Include Files”

Add boost to include path Add the directory of boost 1. Add directory 2. Press to select directory 3. This is the right directory. You can see that boost, docs etc are subdirectories of this directory

Strcpy security error The code has several security issues including that it uses insecure string handling functions The use of these functions gives an error that includes the text _CRT_SECURE_NO_WARNINGS To fix this error, go to project->properties- >configuration properties -> C/C++ -> Command line In the box in the lower right, add the text – /D _CRT_SECURE_NO_WARNINGS Note that there is a space between /D and _CRT_SECURE_NO_WARNINGS

There is a space between /D and _CRT_SECURE_NO_WARNINGS