use of com.biglybt.core.networkmanager.impl.tcp.TCPTransportHelper in project BiglyBT by BiglySoftware.
the class PHETester method incoming.
protected void incoming(SocketChannel channel) {
try {
TransportHelper helper = new TCPTransportHelper(channel);
final ProtocolDecoderInitial decoder = new ProtocolDecoderInitial(helper, null, false, null, new ProtocolDecoderAdapter() {
@Override
public void decodeComplete(ProtocolDecoder decoder, ByteBuffer remaining_initial_data) {
System.out.println("incoming decode complete: " + decoder.getFilter().getName(false));
readStream("incoming", decoder.getFilter());
writeStream("ten fat monkies", decoder.getFilter());
}
@Override
public void decodeFailed(ProtocolDecoder decoder, Throwable cause) {
System.out.println("incoming decode failed: " + Debug.getNestedExceptionMessage(cause));
}
@Override
public void gotSecret(byte[] session_secret) {
}
@Override
public int getMaximumPlainHeaderLength() {
return (TEST_HEADER.length);
}
@Override
public int matchPlainHeader(ByteBuffer buffer) {
int pos = buffer.position();
int lim = buffer.limit();
buffer.flip();
boolean match = buffer.compareTo(ByteBuffer.wrap(TEST_HEADER)) == 0;
buffer.position(pos);
buffer.limit(lim);
System.out.println("Match - " + match);
return (match ? ProtocolDecoderAdapter.MATCH_CRYPTO_NO_AUTO_FALLBACK : ProtocolDecoderAdapter.MATCH_NONE);
}
});
} catch (Throwable e) {
e.printStackTrace();
}
}
use of com.biglybt.core.networkmanager.impl.tcp.TCPTransportHelper in project BiglyBT by BiglySoftware.
the class ConnectionManagerImpl method createTransportFilter.
@Override
public TransportFilter createTransportFilter(Connection connection, TransportCipher read_cipher, TransportCipher write_cipher) throws TransportException {
Transport transport = connection.getTransport();
if (transport == null) {
throw (new TransportException("no transport available"));
}
com.biglybt.core.networkmanager.Transport core_transport;
try {
core_transport = ((TransportImpl) transport).coreTransport();
} catch (IOException e) {
throw new TransportException(e);
}
TransportHelper helper;
if (core_transport instanceof TCPTransportImpl) {
TransportHelperFilter hfilter = ((TCPTransportImpl) core_transport).getFilter();
if (hfilter != null) {
helper = hfilter.getHelper();
} else {
helper = new TCPTransportHelper(((TCPTransportImpl) (core_transport)).getSocketChannel());
}
} else if (core_transport instanceof UDPTransport) {
TransportHelperFilter hfilter = ((UDPTransport) core_transport).getFilter();
if (hfilter != null) {
helper = hfilter.getHelper();
} else {
helper = ((UDPTransport) core_transport).getFilter().getHelper();
InetSocketAddress addr = core_transport.getTransportEndpoint().getProtocolEndpoint().getConnectionEndpoint().getNotionalAddress();
if (!connection.isIncoming()) {
try {
helper = new UDPTransportHelper(UDPNetworkManager.getSingleton().getConnectionManager(), addr, (UDPTransport) core_transport);
} catch (IOException ioe) {
throw new TransportException(ioe);
}
} else {
// helper = new UDPTransportHelper(UDPNetworkManager.getSingleton().getConnectionManager(), addr, (UDPTransport)core_transport);
throw new TransportException("udp incoming transport type not supported - " + core_transport);
}
}
} else {
throw new TransportException("transport type not supported - " + core_transport);
}
TransportHelperFilterStreamCipher core_filter = new TransportHelperFilterStreamCipher(helper, ((TransportCipherImpl) read_cipher).cipher, ((TransportCipherImpl) write_cipher).cipher);
return new TransportFilterImpl(core_filter);
}
use of com.biglybt.core.networkmanager.impl.tcp.TCPTransportHelper in project BiglyBT by BiglySoftware.
the class PHETester method outgoing.
protected void outgoing(SocketChannel channel) {
try {
if (OUTGOING_PLAIN) {
writeStream(TEST_HEADER, channel);
writeStream("two jolly porkers".getBytes(), channel);
} else {
TransportHelper helper = new TCPTransportHelper(channel);
final ProtocolDecoderInitial decoder = new ProtocolDecoderInitial(helper, new byte[][] { shared_secret }, true, null, new ProtocolDecoderAdapter() {
@Override
public void decodeComplete(ProtocolDecoder decoder, ByteBuffer remaining_initial_data) {
System.out.println("outgoing decode complete: " + decoder.getFilter().getName(false));
readStream("incoming", decoder.getFilter());
writeStream(TEST_HEADER, decoder.getFilter());
writeStream("two jolly porkers", decoder.getFilter());
}
@Override
public void decodeFailed(ProtocolDecoder decoder, Throwable cause) {
System.out.println("outgoing decode failed: " + Debug.getNestedExceptionMessage(cause));
}
@Override
public void gotSecret(byte[] session_secret) {
}
@Override
public int getMaximumPlainHeaderLength() {
throw (new RuntimeException());
}
@Override
public int matchPlainHeader(ByteBuffer buffer) {
throw (new RuntimeException());
}
});
}
} catch (Throwable e) {
e.printStackTrace();
}
}
Aggregations