Skip to content

Commit

Permalink
Fix notary proxy logic.
Browse files Browse the repository at this point in the history
The move to physical notaries broke the proxy logic for
individual notary connections.  This fixes proxying support
for multi-connect to destinations with proxies defined, although
it still uses a roughly scoped proxy definition.
  • Loading branch information
moxie0 committed Dec 25, 2011
1 parent f1e310e commit 559a453
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 97 deletions.
45 changes: 23 additions & 22 deletions client/chrome/content/proxy/BaseProxyConnector.js
@@ -1,5 +1,6 @@

function BaseProxyConnector() {
function BaseProxyConnector(proxy) {
this.proxy = proxy;
var self = this;

this.waitForConnection = function(clientSockets, destinations) {
Expand All @@ -17,40 +18,40 @@ function BaseProxyConnector() {
var eventCount = NSPR.lib.PR_Poll(pollfds, pollfds.length, 5000);

if (eventCount == -1) {
dump("BaseProxy Poll failed!\n");
return -1;
dump("BaseProxy Poll failed!\n");
return -1;
}

if (eventCount == 0) {
dump("BaseProxy Poll timeout!\n");
return -1;
dump("BaseProxy Poll timeout!\n");
return -1;
}

for (var i=0;i<pollfds.length;i++) {
if (pollfds[i].out_flags != 0) {
try {
self.readMultiConnectResponse(clientSockets[i], destinations[i].host);
return i;
} catch (e) {
dump("Got BaseProxy connection error...\n");
if (--activeCount <= 0) {
dump("All BaseProxy connections failed...\n");
return -1;
}
pollfds[i].in_flags = 0;
}
}
if (pollfds[i].out_flags != 0) {
try {
self.readMultiConnectResponse(clientSockets[i], destinations[i].host);
return i;
} catch (e) {
dump("Got BaseProxy connection error...\n");
if (--activeCount <= 0) {
dump("All BaseProxy connections failed...\n");
return -1;
}
pollfds[i].in_flags = 0;
}
}
}
}
};

this.makeMultiConnection = function(destinations, proxy) {
dump("Proxy host: " + proxy.host + " , port: " + proxy.port + "\n");
this.makeMultiConnection = function(destinations) {
dump("Proxy host: " + self.proxy.host + " , port: " + self.proxy.port + "\n");
var clientSockets = new Array();

for (var i=0;i<destinations.length;i++) {
dump("Sending connection request for: " + destinations[i].host + "\n");
var clientSocket = new ConvergenceClientSocket(proxy.host, proxy.port, null);
var clientSocket = new ConvergenceClientSocket(self.proxy.host, self.proxy.port, null);
self.sendMultiConnectRequest(clientSocket, destinations[i].host, destinations[i].port);
clientSockets[i] = clientSocket;
}
Expand All @@ -61,7 +62,7 @@ function BaseProxyConnector() {

for (var i=0;i<clientSockets.length;i++) {
if (readyIndex != i) {
clientSockets[i].close();
clientSockets[i].close();
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/chrome/content/proxy/HttpProxyConnector.js
Expand Up @@ -22,9 +22,9 @@
**/


function HttpProxyConnector() {
function HttpProxyConnector(proxy) {
this.base = BaseProxyConnector;
this.base();
this.base(proxy);
}

HttpProxyConnector.prototype.readResponse = function(proxySocket) {
Expand Down
24 changes: 11 additions & 13 deletions client/chrome/content/proxy/ProxyConnector.js
Expand Up @@ -23,32 +23,30 @@


function ProxyConnector(proxyInfo) {
this.type = proxyInfo.type;
this.host = proxyInfo.host;
this.port = proxyInfo.port;
this.proxy = proxyInfo;
}

ProxyConnector.prototype.makeMultiConnection = function(destinations) {
if (this.type == "http") {
var proxyConnector = new HttpProxyConnector();
if (this.proxy.type == "http") {
var proxyConnector = new HttpProxyConnector(this.proxy);
return proxyConnector.makeMultiConnection(destinations);
} else if (this.type == "socks") {
var proxyConnector = new SOCKS5Connector();
} else if (this.proxy.type == "socks") {
var proxyConnector = new SOCKS5Connector(this.proxy);
return proxyConnector.makeMultiConnection(destinations);
} else {
throw "Unsupported proxy type: " + this.type;
throw "Unsupported proxy type: " + this.proxy.type;
}
};

ProxyConnector.prototype.makeConnection = function(destinationSocket, host, port) {
if (this.type == "http") {
var proxyConnector = new HttpProxyConnector();
if (this.proxy.type == "http") {
var proxyConnector = new HttpProxyConnector(this.proxy);
proxyConnector.makeConnection(destinationSocket, host, port);
} else if (this.type == "socks") {
var proxyConnector = new SOCKS5Connector();
} else if (this.proxy.type == "socks") {
var proxyConnector = new SOCKS5Connector(this.proxy);
proxyConnector.makeConnection(destinationSocket, host, port);
} else {
throw "Unsupported proxy type: " + this.type;
throw "Unsupported proxy type: " + this.proxy.type;
}

return destinationSocket;
Expand Down
4 changes: 2 additions & 2 deletions client/chrome/content/proxy/SOCKS5Connector.js
Expand Up @@ -21,9 +21,9 @@
*
**/

function SOCKS5Connector() {
function SOCKS5Connector(proxy) {
this.base = BaseProxyConnector;
this.base();
this.base(proxy);
}

SOCKS5Connector.prototype.sendClientHello = function(proxySocket) {
Expand Down
54 changes: 31 additions & 23 deletions client/chrome/content/ssl/Notary.js
Expand Up @@ -55,18 +55,26 @@ Notary.prototype.getHttpDestinations = function() {
for (var i=0;i<this.physicalNotaries.length;i++) {
dump("Adding: " + this.physicalNotaries[i].host + " : " + this.physicalNotaries[i].httpPort + "\n");
destinations.push({"host" : this.physicalNotaries[i].host ,
"port" : this.physicalNotaries[i].httpPort});
"port" : this.physicalNotaries[i].httpPort});
}

return destinations;
};

Notary.prototype.getHttpProxy = function() {
return this.physicalNotaries[0].httpProxy;
};

Notary.prototype.getSslProxy = function() {
return this.physicalNotaries[0].sslProxy;
};

Notary.prototype.getSslDestinations = function() {
var destinations = new Array();

for (var i=0;i<this.physicalNotaries.length;i++) {
destinations.push({"host" : this.physicalNotaries[i].host ,
"port" : this.physicalNotaries[i].sslPort});
"port" : this.physicalNotaries[i].sslPort});
}

return destinations;
Expand All @@ -77,7 +85,7 @@ Notary.prototype.getBouncedDestinations = function() {

for (var i=0;i<this.physicalNotaries.length;i++) {
destinations.push({"host" : this.physicalNotaries[i].host ,
"port" : 4242});
"port" : 4242});
}

return destinations;
Expand All @@ -90,13 +98,13 @@ Notary.prototype.makeConnection = function(proxy) {
if (typeof proxy != 'undefined' && proxy != null) {
dump("Network proxy for notary: " + this.httpProxy + "\n");
dump("Bouncing request through: " + proxy.getHttpDestinations() + " to: " + this.getBouncedDestinations() + "\n");
notarySocket = new ConvergenceNotarySocket(proxy.getHttpDestinations(), this.httpProxy);
notarySocket = new ConvergenceNotarySocket(proxy.getHttpDestinations(), this.getHttpProxy());
var proxyConnector = new NotaryProxyConnector();
proxyConnector.makeConnection(notarySocket, this.getBouncedDestinations());
} else {
dump("Making unbounced request...\n");
dump("SSL proxy for notary: " + this.sslProxy + "\n");
notarySocket = new ConvergenceNotarySocket(this.getSslDestinations(), this.sslProxy);
notarySocket = new ConvergenceNotarySocket(this.getSslDestinations(), this.getSslProxy());
}

return notarySocket;
Expand Down Expand Up @@ -199,20 +207,20 @@ Notary.prototype.update = function() {
var self = this;

ConvergenceUtil.persistUrl(this.bundleLocation, function(temporaryFile) {
var notary = Notary.constructFromBundle(temporaryFile.path);
if (notary.version < this.version)
return;
dump("Updating notary with new bundle...\n");

self.setName(notary.getName());
self.setBundleLocation(notary.getBundleLocation());
self.setPhysicalNotaries(notary.getPhysicalNotaries());

var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.notifyObservers(observerService, "convergence-notary-updated", null);
});
var notary = Notary.constructFromBundle(temporaryFile.path);
if (notary.version < this.version)
return;

dump("Updating notary with new bundle...\n");

self.setName(notary.getName());
self.setBundleLocation(notary.getBundleLocation());
self.setPhysicalNotaries(notary.getPhysicalNotaries());

var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.notifyObservers(observerService, "convergence-notary-updated", null);
});
};

Notary.prototype.setRegion = function(region) {
Expand Down Expand Up @@ -263,10 +271,10 @@ Notary.prototype.serializeForTransport = function() {
}

var serialized = {'name' : this.name,
'enabled' : this.enabled,
'bundle_location' : this.bundleLocation,
'region' : this.region,
'physical_notaries' : serializedPhysicalNotaries};
'enabled' : this.enabled,
'bundle_location' : this.bundleLocation,
'region' : this.region,
'physical_notaries' : serializedPhysicalNotaries};

return serialized;
};
Expand Down

0 comments on commit 559a453

Please sign in to comment.