use of i2p.bote.network.RelayPeer in project i2p.i2p-bote by i2p.
the class RelayPeerManager method packetReceived.
@Override
public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) {
BanList banList = BanList.getInstance();
banList.update(sender, packet);
synchronized (peers) {
if (banList.isBanned(sender)) {
peers.remove(sender);
return;
}
// respond to PeerListRequests
if (packet instanceof PeerListRequest) {
// send up to MAX_PEERS_TO_SEND high-reachability peers minus the sender itself
List<Destination> peersToSend = new ArrayList<Destination>();
peersToSend.addAll(getGoodPeers(MAX_PEERS_TO_SEND));
peersToSend.remove(sender);
PeerList response = new PeerList(peersToSend);
log.debug("Sending a PeerList containing " + peersToSend.size() + " peers in response to a PeerListRequest from " + Util.toShortenedBase32(sender));
sendQueue.sendResponse(response, sender, packet.getPacketId());
}
// as a relay peer. The other MAX_PEERS/2 are reserved for peers from PeerListRequests since they are preferrable.
if (peers.size() < MAX_PEERS / 2)
peers.add(new RelayPeer(sender));
}
}
use of i2p.bote.network.RelayPeer in project i2p.i2p-bote by i2p.
the class RelayPeerManager method parsePeerFileEntry.
/**
* Creates a <code>RelayPeer</code> from an entry of the peer file.
* An entry is an I2P destination which can (but doesn't have to) be
* followed by "requests sent" and "responses received" numbers.
* Returns <code>null</code> if the entry cannot be parsed.
* @param line
*/
private RelayPeer parsePeerFileEntry(String line) {
String[] fields = line.split("\\t");
try {
Destination destination = new Destination(fields[0]);
RelayPeer peer = new RelayPeer(destination);
for (int i = 1; i < fields.length; i++) {
boolean didRespond = Boolean.valueOf(fields[i]);
peer.addReachabilitySample(didRespond);
}
return peer;
} catch (DataFormatException e) {
log.error("Invalid I2P destination: <" + fields[0] + ">");
return null;
} catch (NumberFormatException e) {
log.error("Invalid number in line: <" + line + ">");
return null;
}
}
Aggregations