distributed programming in...

14
1 Distributed Programming in Java Networking (4) 2/40 Peer-to-Peer A peer-to-peer (or P2P) computer network is a network that relies primarily on the computing power and bandwidth of the participants in the network rather than concentrating it in a relatively low number of servers. P2P networks are typically used for connecting nodes via largely ad hoc connections. Such networks are useful for many purposes. Sharing content files (see file sharing) containing audio, video, data or anything in digital format is very common, and real-time data, such as telephony traffic, is also passed using P2P technology 3/40 Properties of P2P A pure peer-to-peer network does not have the notion of clients or servers, but only equal peer nodes that simultaneously function as both "clients" and "servers" to the other nodes on the network. This model of network arrangement differs from the client- server model where communication is usually to and from a central server. A typical example for a non peer-to-peer file transfer is an FTP server where the client and server programs are quite distinct, and the clients initiate the download/uploads and the servers react to and satisfy these requests.

Upload: others

Post on 31-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

1

DistributedProgramming in Java

Networking (4)

2/40

Peer-to-Peer

• A peer-to-peer (or P2P) computer network is anetwork that relies primarily on the computing power andbandwidth of the participants in the network rather thanconcentrating it in a relatively low number of servers.

• P2P networks are typically used for connecting nodes vialargely ad hoc connections. Such networks are useful formany purposes.• Sharing content files (see file sharing) containing audio,

video, data or• anything in digital format is very common, and real-timedata, such as telephony traffic, is also passed using P2Ptechnology

3/40

Properties of P2P

• A pure peer-to-peer network does not have the notion ofclients or servers, but only equal peer nodes thatsimultaneously function as both "clients" and "servers" tothe other nodes on the network.

• This model of network arrangement differs from the client-server model where communication is usually to and from acentral server.

• A typical example for a non peer-to-peer file transfer is anFTP server where the client and server programs are quitedistinct, and the clients initiate the download/uploads andthe servers react to and satisfy these requests.

Page 2: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

2

4/40

Acceptor-Connector

•Decouple the connection of peercomponents from the processing the peersperform after they are connected

[BH]

active

passive

passive

active

5/40

Case Study

• JSquiggle is a peer-to-peer program written inJava for handheld devices.

•Runs on desktops and PDAs

•can be used to write to any other JSquigglewithin the same local network or far away bysimply put their IP addresses.

•No centralized control – each device is a peerin a P2P network

6/40

•Open protocols – uses HTTP and XML formessaging between peers

•Ordered messages – uses logical timestampto ensure messages are in order

•http://www.aspectsolution.com/sketch

Page 3: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

3

7/40

Usage Scenario

•Peer connect to any other peer, eg using awireless network (WLAN)

8/40

How to use it

9/40

Page 4: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

4

10/40

11/40

12/40

Page 5: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

5

13/40

Use Cases

•Discussed•Draw Sketch•Add Peer•Add Message

•Not discussed:•Search Peer, Get Info,•Save Sketch, Open Sketch, and•Print Sketch

14/40

Draw Sketch

• Precondition• Peers are added in the peer lists

• Postcondition• Sketch message is constructed and sent to peer

• 1. Capture sketch activites until pen is released

• 2. Increase the logical time for new event

• 3. Construct sketch message

• 4. Send the message to each peer on the list

15/40

Add Peer

• Precondition• Peer's IP address is known

• Post condition• Peers are added to peer list

• 1. User inputs peer's IP address

• 2. User inputs peer's port number

• 3. Add the peer into list of peers

Page 6: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

6

16/40

Add Message

• Precondition• Peer is started at correct port

• Post condition• Sketch messages are processed/drawn on the screen

• 1. Remote peer sends out sketch message

• 2. System gets and parses the message

• 3. If logical time is bigger, advance the logical clock

• 4. Execute the message (ie update sketch)

17/40

Sending a Message

18/40

SketchCanvas

•Press mouse: start, dragging: add new points,release mouse: create and send path

Page 7: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

7

19/40

Command Builder•Separate the construction of commands

from their representation

20/40

SketchSender

21/40

SketchSender

•Send command to all known peers

Page 8: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

8

22/40

SketchPeer

•Follows Half-Sync/Half-Async pattern

23/40

SketchPeer.SenderThread

24/40

Scalable Vector Graphics

•Scalable Vector Graphics (SVG) is anXML markup language for describing two-dimensional vector graphics, both static andanimated, and either declarative or scripted.

• It is an open standard created by the WorldWide Web Consortium.

Page 9: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

9

25/40

Command Format•Commands are encoded in XML using the

Scalable Vector Graphics SVG standard forvector graphics

•M = move-to, L = link

26/40

Command Format

27/40

Receiving a Message

parse

Page 10: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

10

28/40

Acceptor-Connector

•Decouple the connection of peercomponents from the processing the peersperform after they are connected

[BH]

active

passive

passive

active

29/40

JSquiggle

•Creates a SketchCanvas (a ServiceHandler) anda SketchServer (an Acceptor)

•The drama unfolds when the SketchServerreceives a connection request ...

30/40

SketchServer

•A typical Acceptor, SketchServer accepts aclient request and hands it over to aSketchService to process (which will invokeour SketchCanvas ... eventually)

Page 11: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

11

31/40

SketchService

•Parse the command, then process it ...

32/40

Command Format•Commands are encoded in XML using the

Scalable Vector Graphics SVG standard forvector graphics

•M = move-to, L = link

33/40

SketchParser

•Decipher the command using the XmlParserfrom org.kxml (small footprint)

Page 12: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

12

34/40

SketchReceiver

•Complete the Command Message pattern

•History of commands for redrawing

35/40

Command Message

•Send command (with state) in a message

•Both sender and receiver contain code forprocessing the command

36/40

Command Message

• Invokes a command on a remote server

•Message handling code separate from codeto process command messages

Page 13: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

13

37/40

Message Ordering

•Correct ordering of messages ensures byusing Lamport’s timestamp algorithm

•Each peer increments clock between anytwo successive events

•When sending message m, use current clockvalue as timestamp Tm

•Upon receiving message m, check thetimestamp Tm, and match the clock to Tm,if current clock is less than Tm

38/40

Lamport’s Algorithm

if a before bthen Ta < Tb

39/40

Lamport Clock

Page 14: Distributed Programming in Javapeople.scs.carleton.ca/~arpwhite/courses/4104/documents/02-Networking-4.pdfProgramming in Java Networking (4) 2/40 Peer-to-Peer • A peer-to-peer (or

14

40/40

Use in JSquiggle

•State contains the peer’s local state,including its timestamp