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);
}
}
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()) + "'");
}
}
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 );
*/
}
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);
}
}
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);
}
}
Aggregations