gps.protocol.BT
Class BTPeer

java.lang.Object
  extended by gps.protocol.Agent
      extended by gps.protocol.Peer
          extended by gps.protocol.BT.BTPeer
All Implemented Interfaces:
SimEventHandler

public class BTPeer
extends Peer

BT Peer

Version:
1.2, 6/20/2005
Author:
Weishuai Yang

Field Summary
static int MAX_ALLOWED_CONNECTION_NUM
          maximum allowed connection number on this peer
static int MAX_ALLOWED_SESSION_NUM
          maximum allowed session number on this peer
static double MAX_OUT_BANDWIDTH_PER_NODE
          maximum out bandwidth, not used now
 BTAlgorithmPeerSelectionAtPeer mPeerSelection
          peer selection algorithm
 
Fields inherited from class gps.protocol.Peer
mDocDBbyKey
 
Constructor Summary
BTPeer(int i)
          constructs a new BTPeer with id provided
 
Method Summary
 void agentDraw(java.awt.Graphics g, int x, int y)
          do some BTPeer specific drawing on the graph
 BTDocument getBTDocument(java.lang.String key)
          retrieves a document by key
 BTSession getSession(java.lang.String key)
          gets session for a specific document
 java.util.LinkedHashMap getSessions()
          gets all sessions on this peer
 boolean handle(SimEvent e)
          handles peer level events
 void handleDownload(BTEvent e)
          handles events for downloading a specific ducument from a specified tracker at a specific time.
 void handleHandShaking(BTEvent e)
          handleHandShaking makes sure each side a session.
 void handlePeerMessage(BTEvent e)
          handles HAND_SHAKING, all other peer messages are not supposed to be sent to BTPeer.
 void handlePublish(BTEvent e)
          handles events for publishing a specific ducument to a specified tracker at a specific time.
 void handleRandomDownload(BTEvent e)
          handles events for downloading a random ducument from a specified tracker at a specific time.
 void publish(java.lang.String docHashkey, BTTracker tracker)
          publishing the document to tracker
 BTSession removeSession(java.lang.String key)
          removes session for a specific document
 void reset()
          reset internal values
 java.lang.String toString()
          gets string description
 
Methods inherited from class gps.protocol.Peer
getDocument, ownDocument
 
Methods inherited from class gps.protocol.Agent
attachTo, getID, getNode, isActive
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_ALLOWED_SESSION_NUM

public static final int MAX_ALLOWED_SESSION_NUM
maximum allowed session number on this peer

See Also:
Constant Field Values

MAX_ALLOWED_CONNECTION_NUM

public static final int MAX_ALLOWED_CONNECTION_NUM
maximum allowed connection number on this peer

See Also:
Constant Field Values

MAX_OUT_BANDWIDTH_PER_NODE

public static final double MAX_OUT_BANDWIDTH_PER_NODE
maximum out bandwidth, not used now

See Also:
Constant Field Values

mPeerSelection

public BTAlgorithmPeerSelectionAtPeer mPeerSelection
peer selection algorithm

Constructor Detail

BTPeer

public BTPeer(int i)
constructs a new BTPeer with id provided

Parameters:
i - BTPeer id
Method Detail

reset

public void reset()
reset internal values

Overrides:
reset in class Peer

agentDraw

public void agentDraw(java.awt.Graphics g,
                      int x,
                      int y)
do some BTPeer specific drawing on the graph

Overrides:
agentDraw in class Agent
Parameters:
g - Graphics object
x - x position
y - y position

getSessions

public java.util.LinkedHashMap getSessions()
gets all sessions on this peer

Returns:
hash map of sessions

getSession

public BTSession getSession(java.lang.String key)
gets session for a specific document

Parameters:
key - document hash key
Returns:
session object

removeSession

public BTSession removeSession(java.lang.String key)
removes session for a specific document

Parameters:
key - document hash key
Returns:
the removed session object

getBTDocument

public BTDocument getBTDocument(java.lang.String key)
retrieves a document by key

Parameters:
key - document hash key
Returns:
BTDocument object

handle

public boolean handle(SimEvent e)
handles peer level events

Specified by:
handle in interface SimEventHandler
Overrides:
handle in class Agent
Parameters:
e - the event to be handled
Returns:
true if already handled

handlePublish

public void handlePublish(BTEvent e)
handles events for publishing a specific ducument to a specified tracker at a specific time.

Parameters:
e - the event object

handleDownload

public void handleDownload(BTEvent e)
handles events for downloading a specific ducument from a specified tracker at a specific time.

Parameters:
e - the event object

handleRandomDownload

public void handleRandomDownload(BTEvent e)
handles events for downloading a random ducument from a specified tracker at a specific time.

Parameters:
e - the event object

handlePeerMessage

public void handlePeerMessage(BTEvent e)
handles HAND_SHAKING, all other peer messages are not supposed to be sent to BTPeer. They are handled by BTSession and BTConnection

Parameters:
e - is the event object

handleHandShaking

public void handleHandShaking(BTEvent e)
handleHandShaking makes sure each side a session. The initiator should already has a session, but the other side may or may not has one yet. if the receiver doesn't have one, set up one for it, and response a bitfield to the initiator's session. for simplicity, handshake already includes bitfield in the message, and the receiver of handshake replys a bitfield message, and set up the connection. The initiator also set up connection after receive the bitfield.

Parameters:
e - is the event object

publish

public void publish(java.lang.String docHashkey,
                    BTTracker tracker)
publishing the document to tracker

Parameters:
docHashkey - the hashkey of the document
tracker - the tracker instance

toString

public java.lang.String toString()
gets string description

Overrides:
toString in class Peer
Returns:
string description