Search in sources :

Example 11 with DHTTransportContact

use of com.biglybt.core.dht.transport.DHTTransportContact in project BiglyBT by BiglySoftware.

the class DHTDBMapping method removeFromBloom.

protected void removeFromBloom(DHTDBValueImpl value) {
    DHTTransportContact originator = value.getOriginator();
    if (ip_count_bloom_filter == null) {
        return;
    }
    byte[] bloom_key = originator.getBloomKey();
    if (ip_count_bloom_filter instanceof byte[]) {
        byte[] existing_address = (byte[]) ip_count_bloom_filter;
        if (Arrays.equals(bloom_key, existing_address)) {
            ip_count_bloom_filter = null;
        }
        return;
    }
    BloomFilter filter = (BloomFilter) ip_count_bloom_filter;
    int hit_count = filter.remove(bloom_key);
    if (DHTLog.LOCAL_BLOOM_TRACE) {
        System.out.println("direct local remove from " + originator.getAddress() + ", hit count = " + hit_count);
    }
}
Also used : DHTTransportContact(com.biglybt.core.dht.transport.DHTTransportContact) BloomFilter(com.biglybt.core.util.bloom.BloomFilter)

Example 12 with DHTTransportContact

use of com.biglybt.core.dht.transport.DHTTransportContact in project BiglyBT by BiglySoftware.

the class DHTDBMapping method addToBloom.

protected void addToBloom(DHTDBValueImpl value) {
    // we don't check for flooding on indirect stores as this could be used to force a
    // direct store to be bounced (flood a node with indirect stores before the direct
    // store occurs)
    DHTTransportContact originator = value.getOriginator();
    byte[] bloom_key = originator.getBloomKey();
    if (ip_count_bloom_filter == null) {
        ip_count_bloom_filter = bloom_key;
        return;
    }
    BloomFilter filter;
    if (ip_count_bloom_filter instanceof byte[]) {
        byte[] existing_address = (byte[]) ip_count_bloom_filter;
        ip_count_bloom_filter = filter = BloomFilterFactory.createAddRemove4Bit(IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK);
        filter.add(existing_address);
    } else {
        filter = (BloomFilter) ip_count_bloom_filter;
    }
    int hit_count = filter.add(bloom_key);
    if (DHTLog.LOCAL_BLOOM_TRACE) {
        System.out.println("direct local add from " + originator.getAddress() + ", hit count = " + hit_count);
    }
    if (filter.getSize() / filter.getEntryCount() < 10) {
        rebuildIPBloomFilter(true);
    }
    if (hit_count >= 15) {
        db.banContact(originator, "local flood on '" + DHTLog.getFullString(key.getBytes()) + "'");
    }
}
Also used : DHTTransportContact(com.biglybt.core.dht.transport.DHTTransportContact) BloomFilter(com.biglybt.core.util.bloom.BloomFilter)

Example 13 with DHTTransportContact

use of com.biglybt.core.dht.transport.DHTTransportContact in project BiglyBT by BiglySoftware.

the class DHTDBMapping method getOriginatorValueID.

private HashWrapper getOriginatorValueID(DHTDBValueImpl value) {
    DHTTransportContact originator = value.getOriginator();
    byte[] originator_id = originator.getID();
    return (new HashWrapper(originator_id));
/*
		byte[]	value_bytes 	= value.getValue();

		byte[]	x = new byte[originator_id.length + value_bytes.length];

		System.arraycopy( originator_id, 0, x, 0, originator_id.length );
		System.arraycopy( value_bytes, 0, x, originator_id.length, value_bytes.length );

		HashWrapper	originator_value_id = new HashWrapper( new SHA1Hasher().calculateHash( x ));

		return( originator_value_id );
		*/
}
Also used : DHTTransportContact(com.biglybt.core.dht.transport.DHTTransportContact) HashWrapper(com.biglybt.core.util.HashWrapper)

Example 14 with DHTTransportContact

use of com.biglybt.core.dht.transport.DHTTransportContact in project BiglyBT by BiglySoftware.

the class NATTraverser method syncTraverse.

protected void syncTraverse(NATTraversalHandler handler, InetSocketAddress target, Map request, NATTraversalObserver listener) {
    try {
        int type = handler.getType();
        synchronized (this) {
            if (puncher == null) {
                if (!PluginCoreUtils.isInitialisationComplete()) {
                    listener.failed(new Exception("NAT traversal failed, initialisation not complete"));
                    return;
                }
                PluginInterface dht_pi = core.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
                if (dht_pi != null) {
                    DHTPlugin dht_plugin = (DHTPlugin) dht_pi.getPlugin();
                    if (dht_plugin.isEnabled()) {
                        DHT dht = dht_plugin.getDHT(DHT.NW_AZ_MAIN);
                        if (dht == null) {
                            dht = dht_plugin.getDHT(DHT.NW_AZ_CVS);
                        }
                        if (dht != null) {
                            puncher = dht.getNATPuncher();
                        }
                    }
                }
            }
            if (puncher == null) {
                listener.disabled();
                return;
            }
        }
        if (request == null) {
            request = new HashMap();
        }
        request.put("_travreas", new Long(type));
        InetSocketAddress[] target_a = { target };
        DHTTransportContact[] rendezvous_used = { null };
        Map reply = puncher.punch(handler.getName(), target_a, rendezvous_used, request);
        if (reply == null) {
            if (rendezvous_used[0] == null) {
                listener.failed(NATTraversalObserver.FT_NO_RENDEZVOUS);
            } else {
                listener.failed(new Exception("NAT traversal failed"));
            }
        } else {
            listener.succeeded(rendezvous_used[0].getAddress(), target_a[0], reply);
        }
    } catch (Throwable e) {
        listener.failed(e);
    }
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) PluginInterface(com.biglybt.pif.PluginInterface) DHT(com.biglybt.core.dht.DHT) DHTTransportContact(com.biglybt.core.dht.transport.DHTTransportContact) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with DHTTransportContact

use of com.biglybt.core.dht.transport.DHTTransportContact in project BiglyBT by BiglySoftware.

the class DHTPluginContactImpl method openTunnel.

public Map openTunnel(DHTPluginContact[] rendezvous, Map client_data) {
    if (AERunStateHandler.isDHTSleeping()) {
        return (null);
    }
    DHTNATPuncher puncher = plugin.getDHT().getNATPuncher();
    if (puncher == null) {
        return (null);
    }
    if (rendezvous == null || rendezvous.length == 0) {
        return (puncher.punch("Tunnel", contact, null, client_data));
    } else {
        DHTTransportContact[] r = new DHTTransportContact[rendezvous.length];
        for (int i = 0; i < r.length; i++) {
            r[0] = ((DHTPluginContactImpl) rendezvous[i]).contact;
        }
        Map result = puncher.punch("Tunnel", contact, r, client_data);
        DHTTransportContact used = r[0];
        if (used != null) {
            rendezvous[0] = new DHTPluginContactImpl(plugin, used);
        }
        return (result);
    }
}
Also used : DHTNATPuncher(com.biglybt.core.dht.nat.DHTNATPuncher) DHTTransportContact(com.biglybt.core.dht.transport.DHTTransportContact) Map(java.util.Map)

Aggregations

DHTTransportContact (com.biglybt.core.dht.transport.DHTTransportContact)16 InetSocketAddress (java.net.InetSocketAddress)5 DHT (com.biglybt.core.dht.DHT)4 DHTNATPuncher (com.biglybt.core.dht.nat.DHTNATPuncher)4 DHTTransportReplyHandlerAdapter (com.biglybt.core.dht.transport.DHTTransportReplyHandlerAdapter)3 DHTTransportValue (com.biglybt.core.dht.transport.DHTTransportValue)2 HashWrapper (com.biglybt.core.util.HashWrapper)2 BloomFilter (com.biglybt.core.util.bloom.BloomFilter)2 PluginInterface (com.biglybt.pif.PluginInterface)2 DHTPlugin (com.biglybt.plugin.dht.DHTPlugin)2 Map (java.util.Map)2 DHTLogger (com.biglybt.core.dht.DHTLogger)1 DHTControlActivity (com.biglybt.core.dht.control.DHTControlActivity)1 DHTControlContact (com.biglybt.core.dht.control.DHTControlContact)1 DHTNATPuncherListener (com.biglybt.core.dht.nat.DHTNATPuncherListener)1 DHTRouterContact (com.biglybt.core.dht.router.DHTRouterContact)1 DHTTransportFullStats (com.biglybt.core.dht.transport.DHTTransportFullStats)1 DHTTransportUDP (com.biglybt.core.dht.transport.udp.DHTTransportUDP)1 DHTTransportUDPImpl (com.biglybt.core.dht.transport.udp.impl.DHTTransportUDPImpl)1 NATTraversalHandler (com.biglybt.core.nat.NATTraversalHandler)1