Peer-2-Peer Programming Greg Gamm Senior Seminar Fall 2007.

Post on 01-Jan-2016

214 views 0 download

Tags:

Transcript of Peer-2-Peer Programming Greg Gamm Senior Seminar Fall 2007.

Peer-2-Peer ProgrammingPeer-2-Peer Programming

Greg GammGreg Gamm

Senior Seminar Senior Seminar

Fall 2007Fall 2007

What is a P2P NetworkWhat is a P2P Network

Specific set of rules and regulations Specific set of rules and regulations that allow clients to transfer files that allow clients to transfer files through connected network of through connected network of

personal computerspersonal computers

P2P NetworkP2P Network

Client/Server NetworkClient/Server Network

LimeWire

Morpheus

Ares

HistoryHistory

First Generation – Napster (1999)First Generation – Napster (1999) ‘‘Hybrid’ Hybrid’ Easy to control networkEasy to control network Easy to manage filesEasy to manage files Single point of failureSingle point of failure Single applicationSingle application Used centralized serverUsed centralized server Long connection times to serverLong connection times to server

NapsterNapster

Created by Shawn Fanning in JulyCreated by Shawn Fanning in July Immediately RIAA sued Napster for Immediately RIAA sued Napster for

copyright infringement copyright infringement Napster shutdown in December 2001Napster shutdown in December 2001 Gnutella was released in 2000 to counter Gnutella was released in 2000 to counter

shutdown of Napstershutdown of Napster By 2003, 14 programs were using Gnutella By 2003, 14 programs were using Gnutella

network alonenetwork alone Napster releases paid version in 2004Napster releases paid version in 2004

History (cont.)History (cont.)

Second Generation – Gnutella (2000)Second Generation – Gnutella (2000) ‘‘Pure’Pure’ DecentralizedDecentralized Giant network of connected usersGiant network of connected users Many different applications on networkMany different applications on network Slow searchSlow search BottlenecksBottlenecks Unconnected ‘islandsUnconnected ‘islands’’ Uses a lot of bandwidthUses a lot of bandwidth

GnutellaGnutella

Created by Justin Frankel and Tom Pepper

Project dropped due to legal concerns In 2001, client LimeWire became open

source increasing popularity In 2002, FastTrack client, Morpheus,

dropped current network for Gnutella

History (cont.)History (cont.)

‘‘Fixed’ Second Generation – Fixed’ Second Generation – FastTrack (2001)FastTrack (2001)

Equal Super nodesEqual Super nodes Faster searchesFaster searches Most popularMost popular ScalabilityScalability Download segments from multiple peersDownload segments from multiple peers Resume interrupted downloadsResume interrupted downloads

FastTrackFastTrack

Created by Niklas Zennström and Janus Friis

Most popular for mp3 sharingAutomatically creates and uses

supernodes before creating list for future use

History (cont.)History (cont.)

Third GenerationThird Generation – Anonymous P2PAnonymous P2PStrong encryption to resist traffic sniffingUses clients as nodes for routingEveryone acts as universal sender/receiverUses virtual IP addressesNot used mainstream yetCould ban all applications

History (cont.)History (cont.)

Fourth Generation – Streams P2PFourth Generation – Streams P2PSends streams instead of filesMulticastTV, radio, movies

Ideal P2P FeaturesIdeal P2P Features

Fully distributableFully distributable Totally Server lessTotally Server less Fully ScalableFully Scalable Globally SearchableGlobally Searchable Bandwidth EfficientBandwidth Efficient RobustRobust EncryptedEncrypted AnonymousAnonymous

Peer ModulePeer Module

Manages overall operations of single nodeManages overall operations of single node Creates separate threads for different Creates separate threads for different

connectionsconnections Main Loop listens for:Main Loop listens for:

Incoming ConnectionsIncoming Connections Node IdentifiersNode Identifiers Host AddressHost Address

Will then set up PeerConnection ObjectWill then set up PeerConnection Object

ListeningListening

def makeserversocket( self, port, backlog=5 ):

s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )

s.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )

s.bind( ( '', port ) )

s.listen( backlog )

return s

AcceptingAccepting

s = self.makeserversocket( self.serverport )

while 1:

clientsock, clientaddr = s.accept()

t = threading.Thread( target = self.__handlepeer, args = [clientsock] ) t.start()

ConnectionConnection

host, port = clientsock.getpeername()

peerconn = BTPeerConnection( None, host, port, clientsock, debug=False )

Functions of Peer NodesFunctions of Peer Nodes startstabilizer(): Runs the provided 'stabilizer' function in a

separate thread, activating it repeatedly after every delay seconds, until the shutdown flag of the Peer object is set.

addhandler(): Registers a handler function for the given message type with the Peer object. Only one handler function may be provided per message type. Message types do not have to be defined in advance of calling this method.

addrouter(): Registers a routing function with this peer. Read the section on routing above for details.

addpeer(): Adds a peer name and IP address/port mapping to the known list of peers.

getpeer(): Returns the (host,port) pair for the given peer name.

Removepeer(): Removes the entry corresponding to the supplied peerid from the list of known pairs.

addpeerat(): Analogous to the prior three methods, except that they access direct (numeric) positions within the list of peers (as opposed to using the peerid as a hash key). These functions should not be used concurrently with the prior three.

getpeerids(): Return a list of all known peer ids.

numberofpeers():

maxpeersreached():

checklivepeers(): Attempt to connect and send a 'PING' message to all currently known peers to ensure that they are still alive. For any connections that fail, the corresponding entry is removed from the list. This method can be used as a simple 'stabilizer' function for a P2P protocol.

PeerConnection ModulePeerConnection Module

Encapsulates a socket connected to a Encapsulates a socket connected to a peer nodepeer node

Uses TCP/IPUses TCP/IP Makes sending/receiving messages easierMakes sending/receiving messages easier Uses 9 different message handlersUses 9 different message handlers

Message HandlingMessage Handling NAME: NAME: Requests a peer to reply with its "official" peer id. Requests a peer to reply with its "official" peer id.

LISTLIST: : Requests a peer to reply with the list of peers that it knows Requests a peer to reply with the list of peers that it knows

about. about.

JOIN pid host portJOIN pid host port: : Requests a peer to add the supplied host/port Requests a peer to add the supplied host/port

combination, associated with the node identified by pid, to its list of combination, associated with the node identified by pid, to its list of

known peers. known peers.

QUER return-pid key ttlQUER return-pid key ttl: : Queries a peer to see if the peer has any Queries a peer to see if the peer has any

record of a file name matching key. If so, send a RESP message record of a file name matching key. If so, send a RESP message

back to the node identified by return-pid; if not, propagate the query back to the node identified by return-pid; if not, propagate the query

to all known peers with a decreased ttl (time-to-live) value, unless ttl to all known peers with a decreased ttl (time-to-live) value, unless ttl

is already 0. is already 0.

Message Handling (Cont.)Message Handling (Cont.) RESP file-name pidRESP file-name pid: : Notifies a peer that the node specified by pid Notifies a peer that the node specified by pid

has a file with the given name. has a file with the given name.

FGET file-nameFGET file-name: : Request a peer to reply with the contents of the Request a peer to reply with the contents of the

specified file. specified file.

QUIT pidQUIT pid: : Indicate to a peer that the node identified by pid wishes to Indicate to a peer that the node identified by pid wishes to

be unregistered from the P2P system. be unregistered from the P2P system.

REPL ...: REPL ...: Used to indicate an acknowledgement of the other Used to indicate an acknowledgement of the other

message types above or to send back results of a successful message types above or to send back results of a successful

request. request.

ERRO msgERRO msg: : Used to indicate an erroneous or unsuccessful Used to indicate an erroneous or unsuccessful

request.. request..

Java ImplementationJava Implementation

PeerbasePeerbase.samplePeerbase.socketPeerbase.util

PeerBase

Classes Interfaces

LoggerUtil Handler

Node Router

PeerConnection Stabilizer

PeerInfo

PeerMessage

PeerBase.sample

Classes

Fileshareapp

Filesharenode

PeerBase.socket

Classes Interfaces

Normalsocket Socket

Socketfactory

PeerBase.util

Classes

SimplePingStabilizer

SimpleRouter

Peer-2-Peer ArchitecturePeer-2-Peer Architecture

LegalitiesLegalities

Sharing public domain filesFree open-source applicationsSharing copyrighted songsSharing copyrighted software

Targeting FastTrack networksPopular, large files

PreventionPrevention

SpoofingSpoofing PollutingPolluting VirusesViruses Denial of ServiceDenial of Service FilteringFiltering Identity attacksIdentity attacks

Other file-sharing programsOther file-sharing programs

Shared folders within network Instant Messaging File TransferFTP SoftwareRemote Access SoftwareEmail

ReferencesReferences Shirky, Clay. (2000, November, 27). What Is P2P…And What Isn’t?

Retrieved September 27, 2007 from http://www.openp2p.com/pub/a/p2p/2000/11/24/shirky1-whatisp2p.html

Hamid, Nadeem Abdul. (2007, March 31). Peer-to-Peer Programming. Retrieved September 29, 2007 from http://cs.berry.edu/~nhamid/p2p/index.html

P2P Introduction and History. Retrieved October 02, 2007 from http://www.mac-p2p.com/p2p-history

McManus, Sean. (2003, August). A Short History of File Sharing. Retrieved October 02, 2007 from http://sean.co.uk/a/musicjournalism/var/historyoffilesharing.shtml