What Is P2P…

Download Report

Transcript What Is P2P…

Peer-2-Peer Programming
Greg Gamm
Senior Seminar
Fall 2007
What is a P2P Network
Specific set of rules and regulations
that allow clients to transfer files
through connected network of
personal computers
P2P Network
Client/Server Network
LimeWire
Morpheus
Ares
History
First Generation – Napster (1999)
 ‘Hybrid’
 Easy to control network
 Easy to manage files
 Single point of failure
 Single application
 Used centralized server
 Long connection times to server
Napster
 Created by Shawn Fanning in July
 Immediately RIAA sued Napster for
copyright infringement
 Napster shutdown in December 2001
 Gnutella was released in 2000 to counter
shutdown of Napster
 By 2003, 14 programs were using Gnutella
network alone
 Napster releases paid version in 2004
History (cont.)
Second Generation – Gnutella
(2000)
 ‘Pure’
 Decentralized
 Giant network of connected users
 Many different applications on network
 Slow search
 Bottlenecks
 Unconnected ‘islands’
Gnutella
 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.)
‘Fixed’ Second Generation –
FastTrack (2001)
 Equal Super nodes
 Faster searches
 Most popular
 Scalability
 Download segments from multiple peers
 Resume interrupted downloads
FastTrack
 Created by Niklas Zennström and Janus
Friis
 Most popular for mp3 sharing
 Automatically creates and uses
supernodes before creating list for future
use
History (cont.)
Third Generation – Anonymous P2P
 Strong encryption to resist traffic sniffing
 Uses clients as nodes for routing
 Everyone acts as universal sender/receiver
 Uses virtual IP addresses
 Not used mainstream yet
 Could ban all applications
History (cont.)
Fourth Generation – Streams P2P
 Sends streams instead of files
 Multicast
 TV, radio, movies
Ideal P2P Features
 Fully distributable
 Totally Server less
 Fully Scalable
 Globally Searchable
 Bandwidth Efficient
 Robust
 Encrypted
 Anonymous
Peer Module
 Manages overall operations of single node
 Creates separate threads for different
connections
 Main Loop listens for:
 Incoming Connections
 Node Identifiers
 Host Address
 Will then set up PeerConnection Object
Listening
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
Accepting
s = self.makeserversocket( self.serverport )
while 1:
clientsock, clientaddr = s.accept()
t = threading.Thread( target =
self.__handlepeer, args = [clientsock] )
t.start()
Connection
host, port = clientsock.getpeername()
peerconn = BTPeerConnection( None, host,
port, clientsock, debug=False )
Functions 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 Module
 Encapsulates a socket connected to a
peer node
 Uses TCP/IP
 Makes sending/receiving messages easier
 Uses 9 different message handlers
Message Handling
 NAME: Requests a peer to reply with its "official" peer id.
 LIST: Requests a peer to reply with the list of peers that it knows
about.
 JOIN pid host port: Requests a peer to add the supplied host/port
combination, associated with the node identified by pid, to its list of
known peers.
 QUER return-pid key ttl: Queries a peer to see if the peer has any
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
to all known peers with a decreased ttl (time-to-live) value, unless ttl
is already 0.
Message Handling (Cont.)
 RESP file-name pid: Notifies a peer that the node specified by pid
has a file with the given name.
 FGET file-name: Request a peer to reply with the contents of the
specified file.
 QUIT pid: Indicate to a peer that the node identified by pid wishes to
be unregistered from the P2P system.
 REPL ...: Used to indicate an acknowledgement of the other
message types above or to send back results of a successful
request.
 ERRO msg: Used to indicate an erroneous or unsuccessful
request..
Java Implementation
 Peerbase
 Peerbase.sample
 Peerbase.socket
 Peerbase.util
PeerBase
Classes
Interfaces
LoggerUtil
Node
PeerConnection
PeerInfo
PeerMessage
Handler
Router
Stabilizer
PeerBase.sample
Classes
Fileshareapp
Filesharenode
PeerBase.socket
Classes
Normalsocket
Socketfactory
Interfaces
Socket
PeerBase.util
Classes
SimplePingStabilizer
SimpleRouter
Peer-2-Peer Architecture
Legalities
 Sharing public domain files
 Free open-source applications
 Sharing copyrighted songs
 Sharing copyrighted software
 Targeting FastTrack networks
 Popular, large files
Prevention
 Spoofing
 Polluting
 Viruses
 Denial of Service
 Filtering
 Identity attacks
Other file-sharing programs
 Shared folders within network
 Instant Messaging File Transfer
 FTP Software
 Remote Access Software
 Email
References
 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/shirky1whatisp2p.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