Permalink
Browse files

Merge branch 'master' of github.com:CSEMike/OneSwarm

  • Loading branch information...
2 parents 16467d2 + 919a8aa commit 0cd3d3fbbcba07df28167fd9deff5999391c34a7 @isdal isdal committed Apr 13, 2012
View
41 az_src/jsocks/net/sourceforge/jsocks/socks/ProxyServer.java
@@ -1,13 +1,19 @@
package net.sourceforge.jsocks.socks;
-import net.sourceforge.jsocks.socks.server.ServerAuthenticator;
-
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.log4j.Logger;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.io.PushbackInputStream;
+import java.net.ConnectException;
+import java.net.InetAddress;
+import java.net.NoRouteToHostException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.logging.Logger;
-import java.net.*;
-import java.util.Random;
-import java.io.*;
+import net.sourceforge.jsocks.socks.server.ServerAuthenticator;
/**
SOCKS4 and SOCKS5 proxy, handles both protocols simultaniously.
@@ -47,11 +53,11 @@
static int iddleTimeout = 180000; //3 minutes
static int acceptTimeout = 180000; //3 minutes
- private static final Logger LOG = Logger.getLogger(ProxyServer.class);
+ private static final Logger LOG = Logger.getLogger(ProxyServer.class.getName());
static Proxy proxy;
- private String connectionId;
+ private final String connectionId;
//Public Constructors
@@ -181,7 +187,7 @@ public void start(int port,int backlog,InetAddress localIP){
* @return a random-enough ID.
*/
private String newConnectionId() {
- return "[" + RandomStringUtils.randomAlphanumeric(4) + "]";
+ return "[" + Math.random() + "]";
}
/**
@@ -197,7 +203,8 @@ public void stop(){
//Runnable interface
////////////////////
- public void run(){
+ @Override
+public void run(){
switch(mode){
case START_MODE:
try{
@@ -208,7 +215,7 @@ public void run(){
}finally{
abort();
if(auth!=null) auth.endSession();
- LOG.debug(connectionId + " Main thread(client->remote)stopped.");
+ LOG.fine(connectionId + " Main thread(client->remote)stopped.");
}
break;
case ACCEPT_MODE:
@@ -223,7 +230,7 @@ public void run(){
handleException(ioe);
}finally{
abort();
- LOG.debug(connectionId + " Accept thread(remote->client) stopped");
+ LOG.fine(connectionId + " Accept thread(remote->client) stopped");
}
break;
case PIPE_MODE:
@@ -232,7 +239,7 @@ public void run(){
}catch(IOException ioe){
}finally{
abort();
- LOG.debug(connectionId + " Support thread(remote->client) stopped");
+ LOG.fine(connectionId + " Support thread(remote->client) stopped");
}
break;
case ABORT_MODE:
@@ -250,13 +257,13 @@ private void startSession() throws IOException{
try{
auth = auth.startSession(sock);
}catch(IOException ioe){
- LOG.info(connectionId + " Auth exception", ioe);
+ LOG.info(connectionId + " Auth exception");
auth = null;
return;
}
if(auth == null){ //Authentication failed
- LOG.warn(connectionId + " Authentication failed");
+ LOG.warning(connectionId + " Authentication failed");
return;
}
@@ -285,7 +292,7 @@ private void handleRequest(ProxyMessage msg)
}else
throw new SocksException(Proxy.SOCKS_FAILURE);
}
- LOG.debug(connectionId + " " + msg);
+ LOG.fine(connectionId + " " + msg);
switch(msg.command){
case Proxy.SOCKS_CMD_CONNECT:
View
17 az_src/jsocks/net/sourceforge/jsocks/socks/UDPRelayServer.java
@@ -1,11 +1,15 @@
package net.sourceforge.jsocks.socks;
-import net.sourceforge.jsocks.socks.server.*;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.logging.Logger;
-import org.apache.log4j.Logger;
-
-import java.net.*;
-import java.io.*;
+import net.sourceforge.jsocks.socks.server.ServerAuthenticator;
/**
UDP Relay server, used by ProxyServer to perform udp forwarding.
@@ -28,7 +32,7 @@
long lastReadTime;
- private static final Logger LOG = Logger.getLogger(UDPRelayServer.class);
+ private static final Logger LOG = Logger.getLogger(UDPRelayServer.class.getName());
static Proxy proxy = null;
static int datagramSize = 0xFFFF;//64K, a bit more than max udp size
@@ -143,6 +147,7 @@ public synchronized void stop(){
//Runnable interface
////////////////////
+ @Override
public void run(){
try{
if(Thread.currentThread().getName().equals("pipe1"))
View
2 javatests/edu/washington/cs/oneswarm/test/integration/oop/LocalOneSwarmExperiment.java
@@ -42,7 +42,7 @@
@SuppressWarnings("unchecked")
@Override
public void execute(String command) {
- logger.info("parsing command: '" + command + "'");
+ logger.finest("parsing command: '" + command + "'");
String[] toks = command.split("\\s+");
toks[0] = toks[0].toLowerCase();
if (toks[0].equals("port")) {
View
23 oneswarm_az_mods/mods_f2f/edu/washington/cs/oneswarm/f2f/permissions/PermissionsDAO.java
@@ -141,7 +141,8 @@ private synchronized void sanity_check_perms() {
*/
public synchronized void f2fInitialized() {
AzureusCoreImpl.getSingleton().getGlobalManager().addDownloadManagerInitialisationAdapter(new DownloadManagerInitialisationAdapter(){
- public void initialised(DownloadManager manager) {
+ @Override
+ public void initialised(DownloadManager manager) {
try {
String hexHash = ByteFormatter.encodeString(manager.getTorrent().getHash());
ArrayList<GroupBean> groups = PermissionsDAO.this.getGroupsForHash(hexHash);
@@ -354,7 +355,7 @@ public synchronized void refresh_friend_groups() {
removeGroupID(base64Key_to_groupid.get(key), true);
save = true;
} catch (IOException e) {
- e.printStackTrace();
+ // e.printStackTrace();
logger.warning(e.toString());
}
}
@@ -619,22 +620,28 @@ private synchronized void setGroupsForHash( String inHexHash, final ArrayList<Gr
if (dm != null) {
if (dm.getState() != DownloadManager.STATE_STOPPED || dm.getState() != DownloadManager.STATE_STOPPING) {
dm.addListener(new DownloadManagerListener() {
- public void completionChanged(DownloadManager manager, boolean completed) {
+ @Override
+ public void completionChanged(DownloadManager manager, boolean completed) {
}
- public void downloadComplete(DownloadManager manager) {
+ @Override
+ public void downloadComplete(DownloadManager manager) {
}
- public void filePriorityChanged(DownloadManager download, DiskManagerFileInfo file) {
+ @Override
+ public void filePriorityChanged(DownloadManager download, DiskManagerFileInfo file) {
}
- public void positionChanged(DownloadManager download, int oldPosition, int newPosition) {
+ @Override
+ public void positionChanged(DownloadManager download, int oldPosition, int newPosition) {
}
- public void stateChanged(final DownloadManager manager, int state) {
+ @Override
+ public void stateChanged(final DownloadManager manager, int state) {
if (state == DownloadManager.STATE_QUEUED) {
DownloadManagerStarter.startDownload(manager, new DownloadManagerStartListener() {
- public void downloadStarted() {
+ @Override
+ public void downloadStarted() {
if (started_with_public == false && inGroups.contains(GroupBean.PUBLIC) == true) {
logger.finer("public network added, forcing tracker update");
manager.getTrackerClient().update(true);
View
2 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/ExperimentalHarnessManager.java
@@ -131,7 +131,7 @@ protected void distribute(String command) {
for (ExperimentInterface ei : experiments) {
for (String offer : ei.getKeys()) {
if (offer.equals(key)) {
- logger.info(key + " is executed by " + ei.getClass().getName());
+ logger.fine(key + " is executed by " + ei.getClass().getName());
ei.execute(command);
return;
}
View
4 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/datagram/DatagramConnection.java
@@ -605,6 +605,10 @@ private void sendMessage(RawMessage[] messages, int num) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("encrypting " + size + " bytes");
}
+ if (size > outgoingPacketBuf.length) {
+ logger.warning("Attempting to encrypt over-full packet of size " + size
+ + " bytes.");
+ }
// Encrypt the serialized payload into the payload buffer.
EncryptedPacket encrypted = encrypter.encrypt(unencryptedPayload, buffers,
outgoingPacketBuf);
View
27 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/friends/FriendManager.java
@@ -35,8 +35,8 @@
import edu.washington.cs.oneswarm.f2f.dht.DHTConnector;
import edu.washington.cs.oneswarm.f2f.permissions.PermissionsDAO;
import edu.washington.cs.oneswarm.f2f.xml.OSF2FXMLBeanReader;
-import edu.washington.cs.oneswarm.f2f.xml.OSF2FXMLBeanWriter;
import edu.washington.cs.oneswarm.f2f.xml.OSF2FXMLBeanReader.OSF2FXMLBeanReaderCallback;
+import edu.washington.cs.oneswarm.f2f.xml.OSF2FXMLBeanWriter;
import edu.washington.cs.publickey.PublicKeyFriend;
public class FriendManager {
@@ -56,15 +56,16 @@
private final FriendImportManager friendImportManager;
- private ConcurrentHashMap<FriendKey, Friend> friends;
- private Set<String> ignoreFutureFriendRequestsFrom = Collections
+ private final ConcurrentHashMap<FriendKey, Friend> friends;
+ private final Set<String> ignoreFutureFriendRequestsFrom = Collections
.synchronizedSet(new HashSet<String>());
private final Map<FriendKey, Long> nonFriendConnectionAttempts = Collections
.synchronizedMap(new LinkedHashMap<FriendKey, Long>() {
private static final int MAX_ENTRIES = 20;
private static final long serialVersionUID = 1L;
+ @Override
protected boolean removeEldestEntry(Map.Entry<FriendKey, Long> eldest) {
return size() > MAX_ENTRIES;
}
@@ -429,12 +430,14 @@ private void readFromDisk() {
OSF2FXMLBeanReader<FriendBean> reader = new OSF2FXMLBeanReader<FriendBean>(cl,
FriendBean.class, OSF2F_FRIEND_FILE, diskSemaphore,
new OSF2FXMLBeanReaderCallback<FriendBean>() {
+ @Override
public void readObject(FriendBean object) {
Friend friend = getFriend(object);
FriendKey fk = new FriendKey(friend.getPublicKey());
friends.put(fk, friend);
}
+ @Override
public void completed() {
// update community server friends to not request file
// list, can
@@ -463,46 +466,58 @@ private void handleFileListRequestInitial() {
// t.setDaemon(true);
// t.start();
logger.finer("reading friend file from disk, reading");
- reader.run();
+ try {
+ reader.run();
+ } catch (Exception e) {
+ // TODO: Attempt recovery from backup.
+ e.printStackTrace();
+ }
logger.finer("reading friend file from disk, completed");
}
private void registerShutdownHook() {
AzureusCoreImpl.getSingleton().addLifecycleListener(new AzureusCoreLifecycleListener() {
+ @Override
public void componentCreated(AzureusCore core, AzureusCoreComponent component) {
// TODO Auto-generated method stub
}
+ @Override
public boolean restartRequested(AzureusCore core) throws AzureusCoreException {
// TODO Auto-generated method stub
return false;
}
+ @Override
public void started(AzureusCore core) {
// TODO Auto-generated method stub
}
+ @Override
public void stopped(AzureusCore core) {
// TODO Auto-generated method stub
}
+ @Override
public void stopping(AzureusCore core) {
logger.fine("stopping, ");
flushToDisk(false, true, false);
}
+ @Override
public boolean stopRequested(AzureusCore core) throws AzureusCoreException {
// System.out
// .println("stop requested, flushing friends to disk");
// flushToDisk(false);
return true;
}
+ @Override
public boolean syncInvokeRequired() {
// TODO Auto-generated method stub
return false;
@@ -538,12 +553,13 @@ private void waitForRead() {
private class FriendKey {
private int hash = 0;
private String ip;
- private byte[] publicKey;
+ private final byte[] publicKey;
public FriendKey(byte[] publicKey) {
this.publicKey = publicKey;
}
+ @Override
public boolean equals(Object obj) {
if (obj instanceof FriendKey) {
FriendKey comp = (FriendKey) obj;
@@ -558,6 +574,7 @@ public boolean equals(Object obj) {
return publicKey;
}
+ @Override
public int hashCode() {
if (hash == 0) {
hash = Arrays.hashCode(publicKey);
View
12 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/network/FriendConnection.java
@@ -744,19 +744,23 @@ public int getRemotePublicKeyHash() {
}
public int getSendQueueCurrentCapacity(int channelId) {
- if (udpConnection.isSendingActive()) {
+ if (udpConnection != null && udpConnection.isSendingActive()) {
return udpConnection.getCapacityForChannel(channelId);
- } else {
+ } else if (this.overlayTransports.size() > 0) {
return (FriendConnectionQueue.MAX_FRIEND_QUEUE_LENGTH - friendConnectionQueue
.getForwardQueueBytes()) / this.overlayTransports.size();
+ } else {
+ return 0;
}
}
public int getSendQueuePotentialCapacity(int channelId) {
- if (udpConnection.isSendingActive()) {
+ if (udpConnection != null && udpConnection.isSendingActive()) {
return udpConnection.getPotentialCapacityForChannel(channelId);
- } else {
+ } else if (this.overlayTransports.size() > 0) {
return (FriendConnectionQueue.MAX_FRIEND_QUEUE_LENGTH) / this.overlayTransports.size();
+ } else {
+ return 0;
}
}
View
9 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/servicesharing/MessageStreamMultiplexer.java
@@ -5,6 +5,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.logging.Logger;
import org.gudy.azureus2.core3.util.DirectByteBuffer;
@@ -18,6 +19,7 @@
*
*/
public class MessageStreamMultiplexer {
+ public final static Logger logger = Logger.getLogger(MessageStreamMultiplexer.class.getName());
private Integer next;
private final short flow;
private final HashMap<Integer, ServiceChannelEndpoint> channels;
@@ -72,7 +74,7 @@ public void onAck(OSF2FServiceDataMsg message) {
}
}
for (Integer num : retransmissions) {
- System.out.println("Non outstanding packet acked: " + num);
+ logger.info("Non outstanding packet acked: " + num);
}
}
@@ -97,7 +99,10 @@ public boolean hasOutstanding(ServiceChannelEndpoint channel) {
Set<SequenceNumber> outstanding = channelOutstanding.get(channel.getChannelId());
HashMap<SequenceNumber, DirectByteBuffer> mapping = new HashMap<SequenceNumber, DirectByteBuffer>();
for (SequenceNumber s : outstanding) {
- mapping.put(s, channel.getMessage(s));
+ DirectByteBuffer msg = channel.getMessage(s);
+ if (msg != null) {
+ mapping.put(s, msg);
+ }
}
return mapping;
}
View
9 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/servicesharing/ProxyServer.java
@@ -8,6 +8,9 @@
import java.util.concurrent.Semaphore;
import java.util.logging.Logger;
+import net.sourceforge.jsocks.socks.InetRange;
+import net.sourceforge.jsocks.socks.server.IdentAuthenticator;
+
public class ProxyServer implements Runnable {
public static Logger logger = Logger.getLogger(ProxyServer.class.getName());
@@ -53,8 +56,12 @@ public int waitForStart() throws InterruptedException {
@Override
public void run() {
+ IdentAuthenticator localAuth = new net.sourceforge.jsocks.socks.server.IdentAuthenticator();
+ InetRange hostRange = new net.sourceforge.jsocks.socks.InetRange();
+ hostRange.add("127.0.0.1");
+ localAuth.add(hostRange, null);
net.sourceforge.jsocks.socks.ProxyServer server = new net.sourceforge.jsocks.socks.ProxyServer(
- new net.sourceforge.jsocks.socks.server.ServerAuthenticatorNone());
+ localAuth);
started.release();
server.start(port);
}
View
5 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/servicesharing/SequenceNumber.java
@@ -54,4 +54,9 @@ public void removeChannel(int channelId) {
public short getFlow() {
return flow;
}
+
+ @Override
+ public String toString() {
+ return "[message " + this.number + "." + this.flow + "]";
+ }
}
View
12 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/servicesharing/ServiceChannelEndpoint.java
@@ -217,8 +217,7 @@ private void writeMessage(final SequenceNumber num, DirectByteBuffer buffer, int
long totalWritten = buffer.remaining(DirectByteBuffer.SS_MSG);
if (logger.isLoggable(Level.FINEST)) {
- logger.finest(String.format("Wrote msg to network. bytes: %d, sequence number: %d",
- length, num.getNum()));
+ logger.finest(String.format("Wrote %s to network. bytes: %d", num, length));
}
super.writeMessage(msg);
bytesOut += totalWritten;
@@ -244,7 +243,11 @@ public long getLatency() {
}
public DirectByteBuffer getMessage(SequenceNumber num) {
- return this.sentMessages.get(num).msg;
+ sentMessage m = this.sentMessages.get(num);
+ if (m != null) {
+ return m.msg;
+ }
+ return null;
}
/**
@@ -313,8 +316,7 @@ public void run() {
sentMessage self = sentMessages.remove(num);
if (self != null && !closed) {
if (self.attempt == attempt) {
- logger.fine("Message with sequence number " + num.getNum()
- + " was retransmitted.");
+ logger.fine(num + " was retransmitted.");
outstandingBytes -= length;
msg.position(ss, position);
writeMessage(num, msg, attempt + 1, datagram);
View
8 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/servicesharing/ServiceConnection.java
@@ -30,8 +30,6 @@
static final int SERVICE_MSG_BUFFER_SIZE = 1024 * COConfigurationManager.getIntParameter(
"SERVICE_CLIENT_flow", 10);
- private final int CHANNEL_BUFFER = 1024 * COConfigurationManager.getIntParameter(
- "SERVICE_CLIENT_window", 4);
protected final int MAX_CHANNELS = COConfigurationManager.getIntParameter(
"SERVICE_CLIENT_channels", 4);
protected final EnumSet<ServiceFeatures> FEATURES;
@@ -60,6 +58,7 @@ public BufferedMessage(DirectByteBuffer msg, SequenceNumber msgId) {
protected final boolean isOutgoing;
protected final short subchannelId;
protected int serviceSequenceNumber;
+ protected int windowSize = COConfigurationManager.getIntParameter("SERVICE_CLIENT_channels", 4);
public ServiceConnection(boolean outgoing, short subchannel,
final NetworkConnection serviceChannel) {
@@ -87,8 +86,8 @@ public ServiceConnection(boolean outgoing, short subchannel,
features.add(ServiceFeatures.ADAPTIVE_DUPLICATION);
}
this.FEATURES = EnumSet.copyOf(features);
- logger.info("Service Connection active with settings: window = "
- + (CHANNEL_BUFFER / 1024)
+ logger.info("Service Connection active with settings: start window = "
+ + (windowSize / 1024)
+ ", flow="
+ (SERVICE_MSG_BUFFER_SIZE / 1024)
+ ", max="
@@ -289,6 +288,7 @@ public boolean channelGotMessage(ServiceChannelEndpoint sender, OSF2FServiceData
if (msg.isAck()) {
logger.fine("Acked msg " + msg.getSequenceNumber());
mmt.onAck(msg);
+ windowSize += 1;
return true;
}

0 comments on commit 0cd3d3f

Please sign in to comment.