02 networking 4

Upload: aditya-rai

Post on 04-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 02 Networking 4

    1/14

    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 hocconnections. 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-time

    data, 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 peernodes 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.

  • 7/30/2019 02 Networking 4

    2/14

    2

    4/40

    Acceptor-Connector

    Decouple the connection of peercomponents from the processing the peers

    perform 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 PDAscan be used to write to any other JSquiggle

    within the same local network or far away by

    simply 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

  • 7/30/2019 02 Networking 4

    3/14

    3

    7/40

    Usage Scenario

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

    8/40

    How to use it

    9/40

  • 7/30/2019 02 Networking 4

    4/14

    4

    10/40

    11/40

    12/40

  • 7/30/2019 02 Networking 4

    5/14

    5

    13/40

    Use Cases

    DiscussedDraw SketchAdd PeerAdd MessageNot discussed:Search Peer, Get Info,Save Sketch, Open Sketch, andPrint 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

  • 7/30/2019 02 Networking 4

    6/14

    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

  • 7/30/2019 02 Networking 4

    7/14

    7

    19/40

    Command Builder

    Separate the construction of commandsfrom their representation

    20/40

    SketchSender

    21/40

    SketchSender

    Send command to all known peers

  • 7/30/2019 02 Networking 4

    8/14

    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 and

    animated, and either declarative or scripted.

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

  • 7/30/2019 02 Networking 4

    9/14

    9

    25/40

    Command Format

    Commands are encoded in XML using theScalable Vector Graphics SVG standard forvector graphics

    M = move-to, L = link

    26/40

    Command Format

    27/40

    Receiving a Message

    parse

  • 7/30/2019 02 Networking 4

    10/14

    10

    28/40

    Acceptor-Connector

    Decouple the connection of peercomponents from the processing the peers

    perform 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 a

    SketchService to process (which will invoke

    our SketchCanvas ... eventually)

  • 7/30/2019 02 Networking 4

    11/14

    11

    31/40

    SketchService

    Parse the command, then process it ...

    32/40

    Command Format

    Commands are encoded in XML using theScalable Vector Graphics SVG standard for

    vector graphics

    M = move-to, L = link

    33/40

    SketchParser

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

  • 7/30/2019 02 Networking 4

    12/14

    12

    34/40

    SketchReceiver

    Complete the Command Message patternHistory of commands for redrawing

    35/40

    Command Message

    Send command (with state) in a messageBoth sender and receiver contain code for

    processing the command

    36/40

    Command Message

    Invokes a command on a remote serverMessage handling code separate from code

    to process command messages

  • 7/30/2019 02 Networking 4

    13/14

    13

    37/40

    Message Ordering

    Correct ordering of messages ensures byusing Lamports 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

    Lamports Algorithm

    if a before b

    then Ta < Tb

    39/40

    Lamport Clock

  • 7/30/2019 02 Networking 4

    14/14

    14

    40/40

    Use in JSquiggle

    State contains the peers local state,including its timestamp