Skip to content

Commit

Permalink
mega service sharing update, browsing through squid works!
Browse files Browse the repository at this point in the history
  • Loading branch information
isdal committed Aug 2, 2011
1 parent 828932a commit f46f8aa
Show file tree
Hide file tree
Showing 36 changed files with 1,655 additions and 489 deletions.
Expand Up @@ -20,11 +20,12 @@

import com.aelitis.azureus.ui.UIFunctionsManager;

import edu.washington.cs.oneswarm.f2f.network.SearchManager;
import edu.washington.cs.oneswarm.f2f.servicesharing.DataMessage;
import edu.washington.cs.oneswarm.f2f.servicesharing.EchoServer;
import edu.washington.cs.oneswarm.f2f.servicesharing.ServiceConnection;
import edu.washington.cs.oneswarm.f2f.servicesharing.ServiceSharingLoopback;
import edu.washington.cs.oneswarm.f2f.servicesharing.ServiceSharingManager;
import edu.washington.cs.oneswarm.f2f.servicesharing.ServiceSharingManager.SharedService;
import edu.washington.cs.oneswarm.test.util.OneSwarmTestBase;
import edu.washington.cs.oneswarm.test.util.TestUtils;

Expand Down Expand Up @@ -55,9 +56,9 @@ public void setupLogging() {
logFinest(EchoServer.logger);
logFinest(ServiceSharingLoopback.logger);

// logFinest(ServiceSharingManager.logger);
// logFinest(ServiceConnection.logger);
// logFinest(SearchManager.logger);
logFinest(ServiceSharingManager.logger);
logFinest(ServiceConnection.logger);
logFinest(SearchManager.logger);
}

@Test
Expand All @@ -75,11 +76,11 @@ public void testLocalServiceEcho() throws Exception {
*/
try {
// Register the server service
ServiceSharingManager.getInstance().registerServerService(SEARCH_KEY,
new SharedService(new InetSocketAddress(LOCALHOST, ECHO_PORT), "echo"));
ServiceSharingManager.getInstance().registerSharedService(SEARCH_KEY, "echo",
new InetSocketAddress(LOCALHOST, ECHO_PORT));

// Register the client service
ServiceSharingManager.getInstance().createClientService("echoclient", CLIENT_PORT,
ServiceSharingManager.getInstance().registerClientService("echoclient", CLIENT_PORT,
SEARCH_KEY);
doEchoTest();

Expand Down
Expand Up @@ -52,7 +52,7 @@ public void testServiceSharing() throws InterruptedException {
try {
tellRemoteToShareService("echo", SEARCH_KEY, LOCALHOST, ECHO_PORT);
// Register the client service
ServiceSharingManager.getInstance().createClientService("echoclient", CLIENT_PORT,
ServiceSharingManager.getInstance().registerClientService("echoclient", CLIENT_PORT,
SEARCH_KEY);
Thread.sleep(5000);
ServiceSharingSingleProcessTest.doEchoTest();
Expand Down
Expand Up @@ -30,7 +30,10 @@
import java.security.KeyPairGenerator;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import javax.crypto.Cipher;
import javax.crypto.KeyAgreement;
Expand Down Expand Up @@ -697,6 +700,8 @@ private static SslHandShakeMatch isSSL(byte[] data) {
// **********************************************
} else if (selected_protocol == CRYPTO_SSL) {
filter = sslFilter;
System.err.println("HANDSHAKE COMPLETED: outgoing=" + outBoundSSL + " filter: "
+ sslFilter.getName());
// **********************************************

/*
Expand Down
Expand Up @@ -8,13 +8,14 @@
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLEngineResult.Status;
import javax.net.ssl.SSLSession;

import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.encoders.Hex;
Expand All @@ -25,7 +26,6 @@

import com.aelitis.azureus.core.networkmanager.impl.TransportHelper;
import com.aelitis.azureus.core.networkmanager.impl.TransportHelperFilterStream;
import com.aelitis.azureus.core.networkmanager.impl.TransportHelper.selectListener;

public class OneSwarmSslTransportHelperFilterStream
extends TransportHelperFilterStream
Expand Down Expand Up @@ -252,13 +252,17 @@ public long read(ByteBuffer[] buffers, int array_offset, int length)
if (leftovers > 0) {
int copied = this.putInBuffers(buffers, array_offset, length,
decryptedDataForApp);
logger.finest("found " + leftovers + " old bytes, copied: " + copied);
if (logger.isLoggable(Level.FINEST)) {
logger.finest("found " + leftovers + " old bytes, copied: " + copied);
}
total_read += copied;

if (decryptedDataForApp.hasRemaining()) {
totalDataRead += total_read;
logger.finest("returning decoded " + total_read + " bytes, total: "
if (logger.isLoggable(Level.FINEST)) {
logger.finest("returning decoded " + total_read + " bytes, total: "
+ totalDataRead);
}
return total_read;
}
}
Expand All @@ -275,7 +279,9 @@ public long read(ByteBuffer[] buffers, int array_offset, int length)
spaceInBuffers += buffers[i].remaining();
}
if (spaceInBuffers == 0) {
logger.finest("returning decoded " + total_read + " bytes");
if (logger.isLoggable(Level.FINEST)) {
logger.finest("returning decoded " + total_read + " bytes");
}
return total_read;
}

Expand All @@ -300,8 +306,10 @@ public long read(ByteBuffer[] buffers, int array_offset, int length)
throw new IOException("transport closed (returned -1)");
}
totalNetRead += readFromTransport;
logger.finest("read " + readFromTransport
if (readFromTransport > 0 && logger.isLoggable(Level.FINEST)) {
logger.finest("read " + readFromTransport
+ " bytes from transport, total: " + totalNetRead);
}
encryptedDataForApp.flip();

// ********** decrypt the data, if the input buffers have enough
Expand Down Expand Up @@ -335,8 +343,10 @@ public long read(ByteBuffer[] buffers, int array_offset, int length)
// care
// of the next iter
if (decryptedDataForApp.remaining() > 0) {
logger.finest("got excess data after decrypt, buffering: "
if (logger.isLoggable(Level.FINEST)) {
logger.finest("got excess data after decrypt, buffering: "
+ decryptedDataForApp.remaining());
}
}
}
if (decryptedDataForApp != null && !decryptedDataForApp.hasRemaining()) {
Expand Down Expand Up @@ -371,8 +381,10 @@ public long read(ByteBuffer[] buffers, int array_offset, int length)
Debug.out("unwrapping, got error:\n" + result);
}
totalDataRead += total_read;
logger.finest("returning decoded " + total_read + " bytes, total: "
if (total_read > 0 && logger.isLoggable(Level.FINEST)) {
logger.finest("returning decoded " + total_read + " bytes, total: "
+ totalDataRead);
}
return total_read;
}

Expand Down Expand Up @@ -495,12 +507,16 @@ public long write(ByteBuffer[] buffers, int array_offset, int length)
encryptedDataForNetwork = null;
return -1;
}
logger.finest("THF: wrote: " + bytesConsumed + " partial write: "
if (logger.isLoggable(Level.FINEST)) {
logger.finest("THF: wrote: " + bytesConsumed + " partial write: "
+ partial_write + " total: " + totalDataWritten);
}
if (encryptedDataForNetwork.hasRemaining()) {
logger.finest("encrypted data left to be written out, buffering "
if (logger.isLoggable(Level.FINEST)) {
logger.finest("encrypted data left to be written out, buffering "
+ encryptedDataForNetwork.remaining()
+ " forcing calling transport to call us again on next write select");
}
/*
* this case is a bit tricky, we need the transport to call us again
* so we can write out the buffered data, but the calling transport might think it
Expand Down
Expand Up @@ -34,7 +34,6 @@
import org.gudy.azureus2.core3.peer.PEPeerManager;
import org.gudy.azureus2.core3.torrent.TOTorrent;
import org.gudy.azureus2.core3.torrent.TOTorrentException;
import org.gudy.azureus2.core3.torrent.TOTorrentFile;
import org.gudy.azureus2.core3.torrent.impl.TOTorrentImpl;
import org.gudy.azureus2.core3.util.ByteFormatter;
import org.gudy.azureus2.core3.util.Debug;
Expand Down Expand Up @@ -607,18 +606,19 @@ public List<FileCollection> handleSearch(Friend f, String searchString) {

public List<byte[]> receivedFriendFileList(Friend f, int type, byte[] data,
boolean use_extended_filelists) throws IOException {
FileList friendsList = null;
if (data != null && data.length != 0) {
FileList friendsList = null;
if (use_extended_filelists == false) {
// System.out.println("decoding basic");
friendsList = FileListManager.decode_basic(data);
} else {
// System.out.println("decoding extended");
friendsList = FileListManager.decode_extended(data);
}
return receivedFriendFileList(f, type, friendsList);
} else {
friendsList = new FileList();
}
return new LinkedList<byte[]>();
return receivedFriendFileList(f, type, friendsList);
}

public List<byte[]> receivedFriendFileList(Friend f, int type, FileList friendsList) {
Expand Down
Expand Up @@ -127,4 +127,9 @@ public int getMessageSize() {
return messageLength;
}

public DirectByteBuffer transferPayload() {
DirectByteBuffer payload = buffer[1];
buffer[1] = null;
return payload;
}
}
Expand Up @@ -250,7 +250,6 @@ public void connectSuccess(ByteBuffer remaining_initial_data) {
boolean registered = listener.connectSuccess(FriendConnection.this);
if (!registered || !connection.isConnected()) {
updateFriendConnectionLog(true, "Parallel connection closed");
close();
return;
}
addQueueListener();
Expand Down
Expand Up @@ -110,6 +110,7 @@ public void closeChannelReset() {
// send a reset back to confirm
closed = true;
sendReset();
deregister();
}
}
}
Expand Down

0 comments on commit f46f8aa

Please sign in to comment.