Search in sources :

Example 6 with RelayPeer

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));
    }
}
Also used : Destination(net.i2p.data.Destination) PeerList(i2p.bote.packet.PeerList) ArrayList(java.util.ArrayList) RelayPeer(i2p.bote.network.RelayPeer) BanList(i2p.bote.network.BanList) PeerListRequest(i2p.bote.packet.relay.PeerListRequest)

Example 7 with RelayPeer

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;
    }
}
Also used : Destination(net.i2p.data.Destination) DataFormatException(net.i2p.data.DataFormatException) RelayPeer(i2p.bote.network.RelayPeer)

Aggregations

RelayPeer (i2p.bote.network.RelayPeer)7 Destination (net.i2p.data.Destination)3 BanList (i2p.bote.network.BanList)2 PeerList (i2p.bote.packet.PeerList)2 PeerListRequest (i2p.bote.packet.relay.PeerListRequest)2 IOException (java.io.IOException)2 Segment (com.androidplot.pie.Segment)1 SegmentFormatter (com.androidplot.pie.SegmentFormatter)1 BannedPeer (i2p.bote.network.BannedPeer)1 DhtPeerStats (i2p.bote.network.DhtPeerStats)1 DhtPeerStatsRow (i2p.bote.network.DhtPeerStatsRow)1 PacketBatch (i2p.bote.network.PacketBatch)1 DataPacket (i2p.bote.packet.DataPacket)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JspWriter (javax.servlet.jsp.JspWriter)1 PageContext (javax.servlet.jsp.PageContext)1 DataFormatException (net.i2p.data.DataFormatException)1