gps.protocol.BT
Class BTSocket

java.lang.Object
  extended by gps.protocol.BT.BTSocket
All Implemented Interfaces:
SimEventHandler

public class BTSocket
extends java.lang.Object
implements SimEventHandler

BT socket deals with lower level connection issue

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

Field Summary
static int CONNECTION_KEEP_ALIVE
          keep alive time
static int CONNECTION_TIMEOUT
          connection timeout
 boolean mAmChoking
          I chocked the other side
 boolean mAmInterested
          I'm interested in their file
 int mBegin
          offset within a downloading piece
 boolean[] mBitField
          bit field of that peer
 boolean mClosed
          if closed, set up the mClosed flag, and remove from hashmap
 BTConnection mConnection
          lower level connection
 BTSocket mCounterpart
          the connection at the other side
 boolean mDownloading
          downloading or not
 int mDownloadLeft
          bytes left within this block
 BTEvent mEstimateFinish
          estimate finish event
 java.util.LinkedList mInBandwidthHistory
          in bandwidth history
 BTEvent mKeepAlive
          keep alive event
 BTEvent mKeepAliveMsg
          the keep alive message to be sent
 int mLength
          length of the current downloading block
 java.util.LinkedList mOutBandwidthHistory
          out bandwidth history
 boolean mPeerChoking
          the other side chocked me
 boolean mPeerInterested
          the other side is interested at my file
 float mPreviousPercent
          previous finished percent
 int mRequestingPieceIndex
          the piece that I'm interested, this variable is set when request is sent
 BTEvent mRequestTimeout
          request time out event
 BTSession mSession
          reference back to the session to which this connection belongs
 double mStartTime
          start time for this downloading bandwidth
 BTEvent mTimeout
          connection time out event
 boolean mUploading
          uploading or not
 int mUploadingPieceIndex
          the current uploading piece index
static int REQUEST_TIMEOUT
          request timeout
 
Constructor Summary
BTSocket(BTSession s)
          constructs a new bt socket object
 
Method Summary
 void adjustInBandwidth(double adj)
          adjusts bandwidth during download, called by counterpart
 void adjustOutBandwidth(double adj)
          adjust out bandwidth
 double calcInAverageSince(double time)
          calculate average input bandwidth since a time spot
 double calcOutAverageSince(double time)
          calculate average output bandwidth since a time spot
 java.util.ArrayList comparePieces()
          compare piece between two peers at both end of the connection
 boolean handle(SimEvent e)
          process event sent to this connection
 void handleBlockFinished(BTEvent e)
          when a block is finished downloading, this event is triggered
 void handleKeepAlive(BTEvent e)
          handles keep alive event
 void handleRequestTimeout(BTEvent e)
          handles request timeout event
 java.lang.String toString()
          gets string description
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REQUEST_TIMEOUT

public static final int REQUEST_TIMEOUT
request timeout

See Also:
Constant Field Values

CONNECTION_TIMEOUT

public static final int CONNECTION_TIMEOUT
connection timeout

See Also:
Constant Field Values

CONNECTION_KEEP_ALIVE

public static final int CONNECTION_KEEP_ALIVE
keep alive time

See Also:
Constant Field Values

mAmChoking

public boolean mAmChoking
I chocked the other side


mPeerChoking

public boolean mPeerChoking
the other side chocked me


mPeerInterested

public boolean mPeerInterested
the other side is interested at my file


mAmInterested

public boolean mAmInterested
I'm interested in their file


mBitField

public boolean[] mBitField
bit field of that peer


mClosed

public boolean mClosed
if closed, set up the mClosed flag, and remove from hashmap


mSession

public BTSession mSession
reference back to the session to which this connection belongs


mCounterpart

public BTSocket mCounterpart
the connection at the other side


mUploading

public boolean mUploading
uploading or not


mUploadingPieceIndex

public int mUploadingPieceIndex
the current uploading piece index


mDownloading

public boolean mDownloading
downloading or not


mRequestingPieceIndex

public int mRequestingPieceIndex
the piece that I'm interested, this variable is set when request is sent


mBegin

public int mBegin
offset within a downloading piece


mLength

public int mLength
length of the current downloading block


mStartTime

public double mStartTime
start time for this downloading bandwidth


mDownloadLeft

public int mDownloadLeft
bytes left within this block


mPreviousPercent

public float mPreviousPercent
previous finished percent


mTimeout

public BTEvent mTimeout
connection time out event


mKeepAlive

public BTEvent mKeepAlive
keep alive event


mKeepAliveMsg

public BTEvent mKeepAliveMsg
the keep alive message to be sent


mEstimateFinish

public BTEvent mEstimateFinish
estimate finish event


mRequestTimeout

public BTEvent mRequestTimeout
request time out event


mConnection

public BTConnection mConnection
lower level connection


mInBandwidthHistory

public java.util.LinkedList mInBandwidthHistory
in bandwidth history


mOutBandwidthHistory

public java.util.LinkedList mOutBandwidthHistory
out bandwidth history

Constructor Detail

BTSocket

public BTSocket(BTSession s)
constructs a new bt socket object

Parameters:
s - session this socket belongs to
Method Detail

handle

public boolean handle(SimEvent e)
process event sent to this connection

Specified by:
handle in interface SimEventHandler
Parameters:
e - the event object with some parameters in it
Returns:
true if already handled

handleRequestTimeout

public void handleRequestTimeout(BTEvent e)
handles request timeout event

Parameters:
e - the event object

handleKeepAlive

public void handleKeepAlive(BTEvent e)
handles keep alive event

Parameters:
e - the event object

comparePieces

public java.util.ArrayList comparePieces()
compare piece between two peers at both end of the connection

Returns:
array of piece index that doesn't existing at local, but existing at remote

handleBlockFinished

public void handleBlockFinished(BTEvent e)
when a block is finished downloading, this event is triggered

Parameters:
e - the event object

adjustInBandwidth

public void adjustInBandwidth(double adj)
adjusts bandwidth during download, called by counterpart

Parameters:
adj - the adjustment amount

adjustOutBandwidth

public void adjustOutBandwidth(double adj)
adjust out bandwidth

Parameters:
adj - the adjustment amount

calcInAverageSince

public double calcInAverageSince(double time)
calculate average input bandwidth since a time spot

Parameters:
time - time spot
Returns:
average bandwidth

calcOutAverageSince

public double calcOutAverageSince(double time)
calculate average output bandwidth since a time spot

Parameters:
time - time spot
Returns:
average bandwidth

toString

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

Overrides:
toString in class java.lang.Object
Returns:
a string describing this session