2009-10-15 22:42:22 +00:00
package net.i2p.router.web ;
2004-09-07 07:17:02 +00:00
import java.io.IOException ;
2004-09-29 22:49:19 +00:00
import java.io.Writer ;
2004-09-07 07:17:02 +00:00
import java.text.DecimalFormat ;
2005-03-17 05:29:55 +00:00
import java.util.Comparator ;
2004-09-07 07:17:02 +00:00
import java.util.Iterator ;
import java.util.Set ;
2005-03-17 05:29:55 +00:00
import java.util.TreeSet ;
2004-09-07 07:17:02 +00:00
2008-03-30 21:50:35 +00:00
import net.i2p.data.DataHelper ;
2004-09-07 07:17:02 +00:00
import net.i2p.data.Hash ;
2008-02-19 15:32:39 +00:00
import net.i2p.data.RouterInfo ;
2004-09-07 07:17:02 +00:00
import net.i2p.router.RouterContext ;
2009-10-15 22:42:22 +00:00
import net.i2p.router.peermanager.DBHistory ;
import net.i2p.router.peermanager.PeerProfile ;
import net.i2p.router.peermanager.ProfileOrganizer ;
2008-03-30 21:50:35 +00:00
import net.i2p.stat.Rate ;
import net.i2p.stat.RateStat ;
2004-09-07 07:17:02 +00:00
/ * *
* Helper class to refactor the HTML rendering from out of the ProfileOrganizer
*
* /
class ProfileOrganizerRenderer {
private RouterContext _context ;
private ProfileOrganizer _organizer ;
2005-03-17 05:29:55 +00:00
private ProfileComparator _comparator ;
2004-09-07 07:17:02 +00:00
public ProfileOrganizerRenderer ( ProfileOrganizer organizer , RouterContext context ) {
_context = context ;
_organizer = organizer ;
2005-03-17 05:29:55 +00:00
_comparator = new ProfileComparator ( ) ;
2004-09-07 07:17:02 +00:00
}
2009-11-24 20:20:30 +00:00
public void renderStatusHTML ( Writer out , boolean full ) throws IOException {
2010-01-24 15:34:40 +00:00
Set < Hash > peers = _organizer . selectAllPeers ( ) ;
2004-09-07 07:17:02 +00:00
2008-03-30 21:50:35 +00:00
long now = _context . clock ( ) . now ( ) ;
2009-08-19 15:26:35 +00:00
long hideBefore = now - 90 * 60 * 1000 ;
2004-09-07 07:17:02 +00:00
2010-01-24 15:34:40 +00:00
TreeSet < PeerProfile > order = new TreeSet ( _comparator ) ;
TreeSet < PeerProfile > integratedPeers = new TreeSet ( _comparator ) ;
2009-11-24 20:20:30 +00:00
int older = 0 ;
int standard = 0 ;
2010-01-24 15:34:40 +00:00
for ( Iterator < Hash > iter = peers . iterator ( ) ; iter . hasNext ( ) ; ) {
Hash peer = iter . next ( ) ;
2004-09-07 07:17:02 +00:00
if ( _organizer . getUs ( ) . equals ( peer ) ) continue ;
PeerProfile prof = _organizer . getProfile ( peer ) ;
2009-11-29 18:48:03 +00:00
//if (_organizer.isWellIntegrated(peer)) {
// integratedPeers.add(prof);
//} else {
2008-03-30 21:50:35 +00:00
RouterInfo info = _context . netDb ( ) . lookupRouterInfoLocally ( peer ) ;
if ( info ! = null & & info . getCapabilities ( ) . indexOf ( " f " ) > = 0 )
integratedPeers . add ( prof ) ;
2009-11-29 18:48:03 +00:00
//}
2009-11-24 20:20:30 +00:00
if ( prof . getLastSendSuccessful ( ) < = hideBefore ) {
older + + ;
continue ;
}
if ( ( ! full ) & & ! _organizer . isHighCapacity ( peer ) ) {
standard + + ;
continue ;
}
2005-03-17 05:29:55 +00:00
order . add ( prof ) ;
2004-09-07 07:17:02 +00:00
}
int fast = 0 ;
int reliable = 0 ;
int integrated = 0 ;
int failing = 0 ;
2009-07-01 16:00:43 +00:00
StringBuilder buf = new StringBuilder ( 16 * 1024 ) ;
2009-10-29 09:03:32 +00:00
buf . append ( " <h2> " ) . append ( _ ( " Peer Profiles " ) ) . append ( " </h2> \ n<p> " ) ;
2009-10-26 14:24:25 +00:00
buf . append ( _ ( " Showing {0} recent profiles. " , order . size ( ) ) ) . append ( '\n' ) ;
2009-11-24 20:20:30 +00:00
if ( older > 0 )
buf . append ( _ ( " Hiding {0} older profiles. " , older ) ) . append ( '\n' ) ;
if ( standard > 0 )
2010-11-17 22:26:31 +00:00
buf . append ( " <a href= \" /profiles?f=1 \" > " ) . append ( _ ( " Hiding {0} standard profiles. " , standard ) ) . append ( " </a> \ n " ) ;
2009-10-29 09:03:32 +00:00
buf . append ( " </p> " ) ;
buf . append ( " <table> " ) ;
buf . append ( " <tr> " ) ;
buf . append ( " <th> " ) . append ( _ ( " Peer " ) ) . append ( " </th> " ) ;
buf . append ( " <th> " ) . append ( _ ( " Groups (Caps) " ) ) . append ( " </th> " ) ;
buf . append ( " <th> " ) . append ( _ ( " Speed " ) ) . append ( " </th> " ) ;
buf . append ( " <th> " ) . append ( _ ( " Capacity " ) ) . append ( " </th> " ) ;
buf . append ( " <th> " ) . append ( _ ( " Integration " ) ) . append ( " </th> " ) ;
buf . append ( " <th> " ) . append ( _ ( " Status " ) ) . append ( " </th> " ) ;
buf . append ( " <th> </th> " ) ;
buf . append ( " </tr> " ) ;
2005-03-17 05:29:55 +00:00
int prevTier = 1 ;
2010-01-24 15:34:40 +00:00
for ( Iterator < PeerProfile > iter = order . iterator ( ) ; iter . hasNext ( ) ; ) {
PeerProfile prof = iter . next ( ) ;
2004-09-07 07:17:02 +00:00
Hash peer = prof . getPeer ( ) ;
int tier = 0 ;
boolean isIntegrated = false ;
if ( _organizer . isFast ( peer ) ) {
tier = 1 ;
fast + + ;
reliable + + ;
} else if ( _organizer . isHighCapacity ( peer ) ) {
tier = 2 ;
reliable + + ;
} else if ( _organizer . isFailing ( peer ) ) {
failing + + ;
} else {
2005-03-17 05:29:55 +00:00
tier = 3 ;
2004-09-07 07:17:02 +00:00
}
if ( _organizer . isWellIntegrated ( peer ) ) {
isIntegrated = true ;
integrated + + ;
}
2005-03-17 05:29:55 +00:00
if ( tier ! = prevTier )
2009-08-17 14:35:18 +00:00
buf . append ( " <tr><td colspan= \" 7 \" ><hr></td></tr> \ n " ) ;
2005-03-17 05:29:55 +00:00
prevTier = tier ;
2009-07-28 13:06:19 +00:00
buf . append ( " <tr><td align= \" center \" nowrap> " ) ;
2009-05-19 18:07:19 +00:00
buf . append ( _context . commSystem ( ) . renderPeerHTML ( peer ) ) ;
2009-11-02 16:50:28 +00:00
// debug
//if(prof.getIsExpandedDB())
// buf.append(" ** ");
2009-07-28 13:06:19 +00:00
buf . append ( " </td><td align= \" center \" > " ) ;
2005-03-17 05:29:55 +00:00
2004-09-07 07:17:02 +00:00
switch ( tier ) {
2009-10-29 09:03:32 +00:00
case 1 : buf . append ( _ ( " Fast, High Capacity " ) ) ; break ;
case 2 : buf . append ( _ ( " High Capacity " ) ) ; break ;
2009-10-30 14:04:58 +00:00
case 3 : buf . append ( _ ( " Standard " ) ) ; break ;
2009-10-29 09:03:32 +00:00
default : buf . append ( _ ( " Failing " ) ) ; break ;
2004-09-07 07:17:02 +00:00
}
2009-10-29 09:03:32 +00:00
if ( isIntegrated ) buf . append ( " , " ) . append ( _ ( " Integrated " ) ) ;
2008-02-19 15:32:39 +00:00
RouterInfo info = _context . netDb ( ) . lookupRouterInfoLocally ( peer ) ;
2008-05-05 16:26:15 +00:00
if ( info ! = null ) {
2009-08-21 23:36:21 +00:00
// prevent HTML injection in the caps and version
buf . append ( " ( " ) . append ( DataHelper . stripHTML ( info . getCapabilities ( ) ) ) ;
2008-05-05 16:26:15 +00:00
String v = info . getOption ( " router.version " ) ;
if ( v ! = null )
2009-08-21 23:36:21 +00:00
buf . append ( ' ' ) . append ( DataHelper . stripHTML ( v ) ) ;
2008-05-05 16:26:15 +00:00
buf . append ( ')' ) ;
}
2004-09-07 07:17:02 +00:00
2005-03-15 03:47:14 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( num ( prof . getSpeedValue ( ) ) ) ;
2008-07-16 15:05:07 +00:00
long bonus = prof . getSpeedBonus ( ) ;
if ( bonus ! = 0 ) {
if ( bonus > 0 )
buf . append ( " (+ " ) ;
else
buf . append ( " ( " ) ;
buf . append ( bonus ) . append ( ')' ) ;
}
buf . append ( " </td><td align= \" right \" > " ) . append ( num ( prof . getCapacityValue ( ) ) ) ;
bonus = prof . getCapacityBonus ( ) ;
if ( bonus ! = 0 ) {
if ( bonus > 0 )
buf . append ( " (+ " ) ;
else
buf . append ( " ( " ) ;
buf . append ( bonus ) . append ( ')' ) ;
}
buf . append ( " </td><td align= \" right \" > " ) . append ( num ( prof . getIntegrationValue ( ) ) ) ;
2009-07-28 13:06:19 +00:00
buf . append ( " </td><td align= \" center \" > " ) ;
2009-10-29 09:03:32 +00:00
if ( _context . shitlist ( ) . isShitlisted ( peer ) ) buf . append ( _ ( " Banned " ) ) ;
2009-11-03 20:37:21 +00:00
if ( prof . getIsFailing ( ) ) buf . append ( ' ' ) . append ( _ ( " Failing " ) ) ;
if ( _context . commSystem ( ) . wasUnreachable ( peer ) ) buf . append ( ' ' ) . append ( _ ( " Unreachable " ) ) ;
2008-05-20 12:48:41 +00:00
Rate failed = prof . getTunnelHistory ( ) . getFailedRate ( ) . getRate ( 30 * 60 * 1000 ) ;
long fails = failed . getCurrentEventCount ( ) + failed . getLastEventCount ( ) ;
if ( fails > 0 ) {
Rate accepted = prof . getTunnelCreateResponseTime ( ) . getRate ( 30 * 60 * 1000 ) ;
long total = fails + accepted . getCurrentEventCount ( ) + accepted . getLastEventCount ( ) ;
if ( total / fails < = 10 ) // hide if < 10%
2009-11-03 20:37:21 +00:00
buf . append ( ' ' ) . append ( fails ) . append ( '/' ) . append ( total ) . append ( ' ' ) . append ( _ ( " Test Fails " ) ) ;
2008-05-20 12:48:41 +00:00
}
2009-08-17 13:24:08 +00:00
buf . append ( " </td> " ) ;
2009-11-02 16:50:28 +00:00
buf . append ( " <td nowrap align= \" center \" ><a target= \" _blank \" href= \" dumpprofile.jsp?peer= " )
. append ( peer . toBase64 ( ) . substring ( 0 , 6 ) ) . append ( " \" > " ) . append ( _ ( " profile " ) ) . append ( " </a> " ) ;
2010-11-17 22:26:31 +00:00
buf . append ( " <a href= \" configpeer?peer= " ) . append ( peer . toBase64 ( ) ) . append ( " \" >+-</a></td> \ n " ) ;
2004-09-07 07:17:02 +00:00
buf . append ( " </tr> " ) ;
2009-08-21 23:36:21 +00:00
// let's not build the whole page in memory (~500 bytes per peer)
out . write ( buf . toString ( ) ) ;
buf . setLength ( 0 ) ;
2004-09-07 07:17:02 +00:00
}
buf . append ( " </table> " ) ;
2008-03-30 21:50:35 +00:00
2009-11-24 20:20:30 +00:00
buf . append ( " <h2><a name= \" flood \" ></a> " ) . append ( _ ( " Floodfill and Integrated Peers " ) ) . append ( " </h2> \ n " ) ;
2009-10-29 09:03:32 +00:00
buf . append ( " <table> " ) ;
2009-11-07 19:32:00 +00:00
buf . append ( " <tr> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Peer " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Caps " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Integ. Value " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Heard About " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Heard From " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Good Send " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Bad Send " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " 10m Resp. Time " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " 1h Resp. Time " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " 1d Resp. Time " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Good Lookup " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Bad Lookup " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Good Store " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " Last Bad Store " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " 1h Fail Rate " ) ) . append ( " </th> " ) ;
buf . append ( " <th class= \" smallhead \" > " ) . append ( _ ( " 1d Fail Rate " ) ) . append ( " </th> " ) ;
buf . append ( " </tr> " ) ;
2010-01-24 15:34:40 +00:00
for ( Iterator < PeerProfile > iter = integratedPeers . iterator ( ) ; iter . hasNext ( ) ; ) {
PeerProfile prof = iter . next ( ) ;
2008-03-30 21:50:35 +00:00
Hash peer = prof . getPeer ( ) ;
2009-07-28 13:06:19 +00:00
buf . append ( " <tr><td align= \" center \" nowrap> " ) ;
2009-05-19 18:07:19 +00:00
buf . append ( _context . commSystem ( ) . renderPeerHTML ( peer ) ) ;
buf . append ( " </td> " ) ;
2008-03-30 21:50:35 +00:00
RouterInfo info = _context . netDb ( ) . lookupRouterInfoLocally ( peer ) ;
if ( info ! = null )
2009-08-21 23:36:21 +00:00
buf . append ( " <td align= \" center \" > " ) . append ( DataHelper . stripHTML ( info . getCapabilities ( ) ) ) . append ( " </td> " ) ;
2008-03-30 21:50:35 +00:00
else
buf . append ( " <td> </td> " ) ;
buf . append ( " </code></td> " ) ;
buf . append ( " <td align= \" right \" > " ) . append ( num ( prof . getIntegrationValue ( ) ) ) . append ( " </td> " ) ;
long time ;
time = now - prof . getLastHeardAbout ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2008-03-30 21:50:35 +00:00
time = now - prof . getLastHeardFrom ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2008-03-30 21:50:35 +00:00
time = now - prof . getLastSendSuccessful ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2008-03-30 21:50:35 +00:00
time = now - prof . getLastSendFailed ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2008-03-30 21:50:35 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( avg ( prof , 10 * 60 * 1000l ) ) . append ( " </td> " ) ;
buf . append ( " <td align= \" right \" > " ) . append ( avg ( prof , 60 * 60 * 1000l ) ) . append ( " </td> " ) ;
buf . append ( " <td align= \" right \" > " ) . append ( avg ( prof , 24 * 60 * 60 * 1000l ) ) . append ( " </td> " ) ;
DBHistory dbh = prof . getDBHistory ( ) ;
if ( dbh ! = null ) {
2009-11-07 19:32:00 +00:00
time = now - dbh . getLastLookupSuccessful ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2009-11-07 19:32:00 +00:00
time = now - dbh . getLastLookupFailed ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2009-11-07 19:32:00 +00:00
time = now - dbh . getLastStoreSuccessful ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2009-11-07 19:32:00 +00:00
time = now - dbh . getLastStoreFailed ( ) ;
2010-11-06 12:28:38 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( DataHelper . formatDuration2 ( time ) ) . append ( " </td> " ) ;
2008-03-30 21:50:35 +00:00
buf . append ( " <td align= \" right \" > " ) . append ( davg ( dbh , 60 * 60 * 1000l ) ) . append ( " </td> " ) ;
buf . append ( " <td align= \" right \" > " ) . append ( davg ( dbh , 24 * 60 * 60 * 1000l ) ) . append ( " </td> " ) ;
2009-11-02 16:50:28 +00:00
} else {
2009-11-03 20:37:21 +00:00
for ( int i = 0 ; i < 6 ; i + + )
buf . append ( " <td align= \" right \" > " ) . append ( _ ( NA ) ) ;
2008-03-30 21:50:35 +00:00
}
2009-11-24 20:20:30 +00:00
buf . append ( " </tr> \ n " ) ;
2008-03-30 21:50:35 +00:00
}
buf . append ( " </table> " ) ;
2009-11-11 20:28:13 +00:00
buf . append ( " <h3> " ) . append ( _ ( " Thresholds " ) ) . append ( " </h3> " ) ;
2009-11-03 20:37:21 +00:00
buf . append ( " <p><b> " ) . append ( _ ( " Speed " ) ) . append ( " :</b> " ) . append ( num ( _organizer . getSpeedThreshold ( ) ) )
. append ( " ( " ) . append ( fast ) . append ( ' ' ) . append ( _ ( " fast peers " ) ) . append ( " )<br> " ) ;
buf . append ( " <b> " ) . append ( _ ( " Capacity " ) ) . append ( " :</b> " ) . append ( num ( _organizer . getCapacityThreshold ( ) ) )
. append ( " ( " ) . append ( reliable ) . append ( ' ' ) . append ( _ ( " high capacity peers " ) ) . append ( " )<br> " ) ;
buf . append ( " <b> " ) . append ( _ ( " Integration " ) ) . append ( " :</b> " ) . append ( num ( _organizer . getIntegrationThreshold ( ) ) )
. append ( " ( " ) . append ( integrated ) . append ( ' ' ) . append ( _ ( " well integrated peers " ) ) . append ( " )</p> " ) ;
2009-11-11 20:28:13 +00:00
buf . append ( " <h3> " ) . append ( _ ( " Definitions " ) ) . append ( " </h3><ul> " ) ;
2009-11-07 19:32:00 +00:00
buf . append ( " <li><b> " ) . append ( _ ( " groups " ) ) . append ( " </b>: " ) . append ( _ ( " as determined by the profile organizer " ) ) . append ( " </li> " ) ;
buf . append ( " <li><b> " ) . append ( _ ( " caps " ) ) . append ( " </b>: " ) . append ( _ ( " capabilities in the netDb, not used to determine profiles " ) ) . append ( " </li> " ) ;
buf . append ( " <li><b> " ) . append ( _ ( " speed " ) ) . append ( " </b>: " ) . append ( _ ( " peak throughput (bytes per second) over a 1 minute period that the peer has sustained in a single tunnel " ) ) . append ( " </li> " ) ;
buf . append ( " <li><b> " ) . append ( _ ( " capacity " ) ) . append ( " </b>: " ) . append ( _ ( " how many tunnels can we ask them to join in an hour? " ) ) . append ( " </li> " ) ;
buf . append ( " <li><b> " ) . append ( _ ( " integration " ) ) . append ( " </b>: " ) . append ( _ ( " how many new peers have they told us about lately? " ) ) . append ( " </li> " ) ;
buf . append ( " <li><b> " ) . append ( _ ( " status " ) ) . append ( " </b>: " ) . append ( _ ( " is the peer banned, or unreachable, or failing tunnel tests? " ) ) . append ( " </li> " ) ;
buf . append ( " </ul></i> " ) ;
2004-09-29 22:49:19 +00:00
out . write ( buf . toString ( ) ) ;
2004-09-30 13:10:02 +00:00
out . flush ( ) ;
2004-09-07 07:17:02 +00:00
}
2010-01-24 15:34:40 +00:00
private class ProfileComparator implements Comparator < PeerProfile > {
public int compare ( PeerProfile left , PeerProfile right ) {
2005-03-17 05:29:55 +00:00
if ( _context . profileOrganizer ( ) . isFast ( left . getPeer ( ) ) ) {
if ( _context . profileOrganizer ( ) . isFast ( right . getPeer ( ) ) ) {
return compareHashes ( left , right ) ;
} else {
return - 1 ; // fast comes first
}
} else if ( _context . profileOrganizer ( ) . isHighCapacity ( left . getPeer ( ) ) ) {
if ( _context . profileOrganizer ( ) . isFast ( right . getPeer ( ) ) ) {
return 1 ;
} else if ( _context . profileOrganizer ( ) . isHighCapacity ( right . getPeer ( ) ) ) {
return compareHashes ( left , right ) ;
} else {
return - 1 ;
}
} else if ( _context . profileOrganizer ( ) . isFailing ( left . getPeer ( ) ) ) {
if ( _context . profileOrganizer ( ) . isFailing ( right . getPeer ( ) ) ) {
return compareHashes ( left , right ) ;
} else {
return 1 ;
}
} else {
// left is not failing
if ( _context . profileOrganizer ( ) . isFast ( right . getPeer ( ) ) ) {
return 1 ;
} else if ( _context . profileOrganizer ( ) . isHighCapacity ( right . getPeer ( ) ) ) {
return 1 ;
} else if ( _context . profileOrganizer ( ) . isFailing ( right . getPeer ( ) ) ) {
return - 1 ;
} else {
return compareHashes ( left , right ) ;
}
}
}
private int compareHashes ( PeerProfile left , PeerProfile right ) {
return left . getPeer ( ) . toBase64 ( ) . compareTo ( right . getPeer ( ) . toBase64 ( ) ) ;
}
}
2008-10-26 18:12:36 +00:00
private final static DecimalFormat _fmt = new DecimalFormat ( " ###,##0.00 " ) ;
2004-09-07 07:17:02 +00:00
private final static String num ( double num ) { synchronized ( _fmt ) { return _fmt . format ( num ) ; } }
2009-11-03 20:37:21 +00:00
private final static String NA = HelperBase . _x ( " n/a " ) ;
2008-03-30 21:50:35 +00:00
2009-11-03 20:37:21 +00:00
private String avg ( PeerProfile prof , long rate ) {
2008-03-30 21:50:35 +00:00
RateStat rs = prof . getDbResponseTime ( ) ;
if ( rs = = null )
2009-11-03 20:37:21 +00:00
return _ ( NA ) ;
2008-03-30 21:50:35 +00:00
Rate r = rs . getRate ( rate ) ;
if ( r = = null )
2009-11-03 20:37:21 +00:00
return _ ( NA ) ;
2008-03-30 21:50:35 +00:00
long c = r . getCurrentEventCount ( ) + r . getLastEventCount ( ) ;
if ( c = = 0 )
2009-11-03 20:37:21 +00:00
return _ ( NA ) ;
2008-03-30 21:50:35 +00:00
double d = r . getCurrentTotalValue ( ) + r . getLastTotalValue ( ) ;
2010-11-06 12:28:38 +00:00
return DataHelper . formatDuration2 ( Math . round ( d / c ) ) ;
2008-03-30 21:50:35 +00:00
}
2009-11-03 20:37:21 +00:00
private String davg ( DBHistory dbh , long rate ) {
2008-03-30 21:50:35 +00:00
RateStat rs = dbh . getFailedLookupRate ( ) ;
if ( rs = = null )
2009-11-24 20:20:30 +00:00
return " 0% " ;
2008-03-30 21:50:35 +00:00
Rate r = rs . getRate ( rate ) ;
if ( r = = null )
2009-11-24 20:20:30 +00:00
return " 0% " ;
2008-03-30 21:50:35 +00:00
long c = r . getCurrentEventCount ( ) + r . getLastEventCount ( ) ;
2009-11-24 20:20:30 +00:00
if ( c < = 0 )
return " 0% " ;
double avg = 0 . 5 + 100 * ( r . getCurrentTotalValue ( ) + r . getLastTotalValue ( ) ) / c ;
return ( ( int ) avg ) + " % " ;
2008-03-30 21:50:35 +00:00
}
2009-10-18 14:06:07 +00:00
/** translate a string */
private String _ ( String s ) {
return Messages . getString ( s , _context ) ;
}
2009-10-26 14:24:25 +00:00
/ * *
* translate a string with a parameter
* This is a lot more expensive than _ ( s ) , so use sparingly .
*
* @param s string to be translated containing { 0 }
* The { 0 } will be replaced by the parameter .
* Single quotes must be doubled , i . e . ' - > ' ' in the string .
* @param o parameter , not translated .
* To tranlslate parameter also , use _ ( " foo {0} bar " , _ ( " baz " ) )
* Do not double the single quotes in the parameter .
* Use autoboxing to call with ints , longs , floats , etc .
* /
2009-10-28 18:26:50 +00:00
private String _ ( String s , Object o ) {
2009-10-26 14:24:25 +00:00
return Messages . getString ( s , o , _context ) ;
}
2004-09-07 07:17:02 +00:00
}