use of com.biglybt.core.util.SHA1Simple in project BiglyBT by BiglySoftware.
the class SubscriptionBodyImpl method deriveSingletonShortID.
protected static byte[] deriveSingletonShortID(Map singleton_details) {
byte[] short_id = new byte[SIMPLE_ID_LENGTH];
byte[] explicit_sid = new SHA1Simple().calculateHash((byte[]) singleton_details.get("key"));
System.arraycopy(explicit_sid, 0, short_id, 0, SIMPLE_ID_LENGTH);
return (short_id);
}
use of com.biglybt.core.util.SHA1Simple in project BiglyBT by BiglySoftware.
the class SubscriptionBodyImpl method deriveShortID.
protected static byte[] deriveShortID(byte[] public_key, Map singleton_details) {
if (singleton_details != null) {
return (deriveSingletonShortID(singleton_details));
} else {
byte[] hash = new SHA1Simple().calculateHash(public_key);
byte[] short_id = new byte[SIMPLE_ID_LENGTH];
System.arraycopy(hash, 0, short_id, 0, SIMPLE_ID_LENGTH);
return (short_id);
}
}
use of com.biglybt.core.util.SHA1Simple in project BiglyBT by BiglySoftware.
the class MessageManagerImpl method registerGenericMessageType.
@Override
public GenericMessageRegistration registerGenericMessageType(final String _type, final String description, final int stream_crypto, final GenericMessageHandler handler) throws MessageException {
final String type = "AEGEN:" + _type;
final byte[] type_bytes = type.getBytes();
final byte[][] shared_secrets = new byte[][] { new SHA1Simple().calculateHash(type_bytes) };
synchronized (message_handlers) {
message_handlers.put(type, handler);
}
final NetworkManager.ByteMatcher matcher = new NetworkManager.ByteMatcher() {
@Override
public int matchThisSizeOrBigger() {
return (maxSize());
}
@Override
public int maxSize() {
return type_bytes.length;
}
@Override
public int minSize() {
return maxSize();
}
@Override
public Object matches(TransportHelper transport, ByteBuffer to_compare, int port) {
int old_limit = to_compare.limit();
to_compare.limit(to_compare.position() + maxSize());
boolean matches = to_compare.equals(ByteBuffer.wrap(type_bytes));
// restore buffer structure
to_compare.limit(old_limit);
return matches ? "" : null;
}
@Override
public Object minMatches(TransportHelper transport, ByteBuffer to_compare, int port) {
return (matches(transport, to_compare, port));
}
@Override
public byte[][] getSharedSecrets() {
return (shared_secrets);
}
@Override
public int getSpecificPort() {
return (-1);
}
};
NetworkManager.getSingleton().requestIncomingConnectionRouting(matcher, new NetworkManager.RoutingListener() {
@Override
public void connectionRouted(final NetworkConnection connection, Object routing_data) {
try {
ByteBuffer[] skip_buffer = { ByteBuffer.allocate(type_bytes.length) };
connection.getTransport().read(skip_buffer, 0, 1);
if (skip_buffer[0].remaining() != 0) {
Debug.out("incomplete read");
}
GenericMessageEndpointImpl endpoint = new GenericMessageEndpointImpl(connection.getEndpoint());
GenericMessageConnectionDirect direct_connection = GenericMessageConnectionDirect.receive(endpoint, type, description, stream_crypto, shared_secrets);
GenericMessageConnectionImpl new_connection = new GenericMessageConnectionImpl(MessageManagerImpl.this, direct_connection);
direct_connection.connect(connection);
if (handler.accept(new_connection)) {
new_connection.accepted();
} else {
connection.close("connection not accepted");
}
} catch (Throwable e) {
Debug.printStackTrace(e);
connection.close(e == null ? null : Debug.getNestedExceptionMessage(e));
}
}
@Override
public boolean autoCryptoFallback() {
return (stream_crypto != MessageManager.STREAM_ENCRYPTION_RC4_REQUIRED);
}
}, new MessageStreamFactory() {
@Override
public MessageStreamEncoder createEncoder() {
return new GenericMessageEncoder();
}
@Override
public MessageStreamDecoder createDecoder() {
return new GenericMessageDecoder(type, description);
}
});
return (new GenericMessageRegistration() {
@Override
public GenericMessageEndpoint createEndpoint(InetSocketAddress notional_target) {
return (new GenericMessageEndpointImpl(notional_target));
}
@Override
public GenericMessageConnection createConnection(GenericMessageEndpoint endpoint) throws MessageException {
return (new GenericMessageConnectionImpl(MessageManagerImpl.this, type, description, (GenericMessageEndpointImpl) endpoint, stream_crypto, shared_secrets));
}
@Override
public void cancel() {
NetworkManager.getSingleton().cancelIncomingConnectionRouting(matcher);
synchronized (message_handlers) {
message_handlers.remove(type);
}
}
});
}
use of com.biglybt.core.util.SHA1Simple in project BiglyBT by BiglySoftware.
the class DDBaseHelpers method getKey.
protected static HashWrapper getKey(DistributedDatabaseTransferType transfer_type) throws DistributedDatabaseException {
Class<?> c = transfer_type.getClass();
String new_name = c.getName();
String old_name = xfer_migration.get(new_name);
if (old_name == null) {
Debug.out("Missing xfer name map entry for '" + new_name + "'");
old_name = new_name;
}
if (old_name == null) {
throw (new DistributedDatabaseException("name doesn't exist for '" + c.getName() + "'"));
}
return (new HashWrapper(new SHA1Simple().calculateHash(old_name.getBytes())));
}
Aggregations