Search in sources :

Example 6 with PeerItem

use of com.biglybt.core.peermanager.peerdb.PeerItem in project BiglyBT by BiglySoftware.

the class UTPeerExchange method extractPeers.

private List extractPeers(String key_name, Map root_map, int peer_byte_size, boolean noSeeds) {
    ArrayList peers = new ArrayList();
    byte[] raw_peer_data = (byte[]) root_map.get(key_name);
    if (raw_peer_data != null) {
        if (raw_peer_data.length % peer_byte_size != 0) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "PEX (UT): peer data size not multiple of " + peer_byte_size + ": " + raw_peer_data.length));
        }
        int peer_num = raw_peer_data.length / peer_byte_size;
        byte[] flags = null;
        Object flags_obj = root_map.get(key_name + ".f");
        if (flags_obj instanceof byte[]) {
            flags = (byte[]) flags_obj;
        }
        if (flags != null && flags.length != peer_num) {
            if (flags.length > 0) {
                if (Logger.isEnabled()) {
                    Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "PEX (UT): invalid peer flags: peers=" + peer_num + ", flags=" + flags.length));
                }
            }
            flags = null;
        }
        for (int i = 0; i < peer_num; i++) {
            byte[] full_address = new byte[peer_byte_size];
            System.arraycopy(raw_peer_data, i * peer_byte_size, full_address, 0, peer_byte_size);
            byte type = PeerItemFactory.HANDSHAKE_TYPE_PLAIN;
            if (flags != null && (flags[i] & 0x01) != 0)
                type = PeerItemFactory.HANDSHAKE_TYPE_CRYPTO;
            if (flags != null && (flags[i] & 0x02) != 0 && noSeeds)
                continue;
            try {
                PeerItem peer = PeerItemFactory.createPeerItem(full_address, PeerItemFactory.PEER_SOURCE_PEER_EXCHANGE, type, 0, AENetworkClassifier.AT_PUBLIC);
                peers.add(peer);
            } catch (Exception e) {
                if (Logger.isEnabled())
                    Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "PEX (UT): invalid peer received"));
            }
        }
    }
    return peers;
}
Also used : PeerItem(com.biglybt.core.peermanager.peerdb.PeerItem) LogEvent(com.biglybt.core.logging.LogEvent) MessageException(com.biglybt.core.peermanager.messaging.MessageException)

Example 7 with PeerItem

use of com.biglybt.core.peermanager.peerdb.PeerItem in project BiglyBT by BiglySoftware.

the class UTPeerExchange method insertPeers.

private void insertPeers(String key_name, Map root_map, boolean include_flags, List peers, int peer_byte_size) {
    if (peers == null) {
        return;
    }
    if (peers.isEmpty()) {
        return;
    }
    byte[] raw_peers = new byte[peers.size() * peer_byte_size];
    byte[] peer_flags = (include_flags) ? new byte[peers.size()] : null;
    PeerItem peer;
    for (int i = 0; i < peers.size(); i++) {
        peer = (PeerItem) peers.get(i);
        byte[] serialised_peer = peer.getSerialization();
        if (serialised_peer.length != peer_byte_size) {
            Debug.out("invalid serialization- " + serialised_peer.length + ":" + peer_byte_size);
        }
        System.arraycopy(serialised_peer, 0, raw_peers, i * peer_byte_size, peer_byte_size);
        if (peer_flags != null && NetworkManager.getCryptoRequired(peer.getCryptoLevel())) {
            // Encrypted connection.
            peer_flags[i] |= 0x01;
        }
    // 0x02 indicates if the peer is a seed, but that's difficult to determine
    // so we'll leave it.
    }
    // end for
    root_map.put(key_name, raw_peers);
    if (peer_flags != null) {
        root_map.put(key_name + ".f", peer_flags);
    }
}
Also used : PeerItem(com.biglybt.core.peermanager.peerdb.PeerItem)

Example 8 with PeerItem

use of com.biglybt.core.peermanager.peerdb.PeerItem in project BiglyBT by BiglySoftware.

the class ClientStatsView method peerRemoved.

@Override
public void peerRemoved(PEPeer peer) {
    synchronized (mapData) {
        ClientStatsDataSource stat = mapData.get(getID(peer));
        if (stat != null) {
            stat.current--;
            String network = null;
            if (peer instanceof PEPeerTransport) {
                PeerItem identity = ((PEPeerTransport) peer).getPeerItemIdentity();
                if (identity != null) {
                    network = identity.getNetwork();
                }
            }
            stat.bytesReceived += peer.getStats().getTotalDataBytesReceived();
            stat.bytesSent += peer.getStats().getTotalDataBytesSent();
            stat.bytesDiscarded += peer.getStats().getTotalBytesDiscarded();
            if (network != null) {
                Map<String, Object> map = stat.perNetworkStats.get(network);
                if (map == null) {
                    map = new HashMap<>();
                    stat.perNetworkStats.put(network, map);
                }
                long bytesReceived = MapUtils.getMapLong(map, "bytesReceived", 0);
                map.put("bytesReceived", bytesReceived + peer.getStats().getTotalDataBytesReceived());
                long bytesSent = MapUtils.getMapLong(map, "bytesSent", 0);
                map.put("bytesSent", bytesSent + peer.getStats().getTotalDataBytesSent());
                long bytesDiscarded = MapUtils.getMapLong(map, "bytesDiscarded", 0);
                map.put("bytesDiscarded", bytesDiscarded + peer.getStats().getTotalBytesDiscarded());
            }
            if (tv != null) {
                TableRowCore row = tv.getRow(stat);
                if (row != null) {
                    row.invalidate();
                }
            }
        }
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) PeerItem(com.biglybt.core.peermanager.peerdb.PeerItem) PEPeerTransport(com.biglybt.core.peer.impl.PEPeerTransport)

Example 9 with PeerItem

use of com.biglybt.core.peermanager.peerdb.PeerItem in project BiglyBT by BiglySoftware.

the class ColumnPeerNetwork method refresh.

@Override
public void refresh(TableCell cell) {
    Object ds = cell.getDataSource();
    String text = "";
    Comparable val = null;
    if (ds instanceof PEPeerTransport) {
        PEPeerTransport peer = (PEPeerTransport) ds;
        PeerItem identity = peer.getPeerItemIdentity();
        if (identity != null) {
            val = text = identity.getNetwork();
        }
    }
    if (!cell.setSortValue(val) && cell.isValid()) {
        return;
    }
    cell.setText(text);
}
Also used : PeerItem(com.biglybt.core.peermanager.peerdb.PeerItem) PEPeerTransport(com.biglybt.core.peer.impl.PEPeerTransport)

Aggregations

PeerItem (com.biglybt.core.peermanager.peerdb.PeerItem)9 PEPeerTransport (com.biglybt.core.peer.impl.PEPeerTransport)3 MessageException (com.biglybt.core.peermanager.messaging.MessageException)3 LogEvent (com.biglybt.core.logging.LogEvent)2 PeerExchangerItem (com.biglybt.core.peermanager.peerdb.PeerExchangerItem)2 TableRowCore (com.biglybt.ui.common.table.TableRowCore)2 MessageStreamEncoder (com.biglybt.core.peermanager.messaging.MessageStreamEncoder)1 InetAddress (java.net.InetAddress)1 SimpleDateFormat (java.text.SimpleDateFormat)1