Doc
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Chrome App - SOCKS5 Proxy with Bidirectional Tunneling
|
||||
* Chrome's Hammer - SOCKS5 Proxy with Bidirectional Tunneling
|
||||
* Supports both HTTP and HTTPS through true SOCKS5 tunneling
|
||||
*/
|
||||
|
||||
@@ -367,7 +367,7 @@ function handleDestinationData(destSocketId, data) {
|
||||
function setupConnectionHandlers() {
|
||||
// Handle new connections from clients
|
||||
chrome.sockets.tcpServer.onAccept.addListener(function(acceptInfo) {
|
||||
console.log('[Proxy] New client connected: ' + acceptInfo.clientSocketId);
|
||||
console.log('[Hammer] New client connected: ' + acceptInfo.clientSocketId);
|
||||
|
||||
// Initialize SOCKS state for this connection
|
||||
initConnection(acceptInfo.clientSocketId);
|
||||
@@ -378,7 +378,7 @@ function setupConnectionHandlers() {
|
||||
|
||||
// Handle accept errors
|
||||
chrome.sockets.tcpServer.onAcceptError.addListener(function(errorInfo) {
|
||||
console.error('[Proxy] Accept error:', errorInfo);
|
||||
console.error('[Hammer] Accept error:', errorInfo);
|
||||
});
|
||||
|
||||
// Handle receive errors
|
||||
@@ -388,9 +388,9 @@ function setupConnectionHandlers() {
|
||||
|
||||
// Error code -100 is ERR_CONNECTION_CLOSED - normal disconnect, not an error
|
||||
if (resultCode === -100) {
|
||||
console.log('[Proxy] Socket ' + socketId + ' connection closed');
|
||||
console.log('[Hammer] Socket ' + socketId + ' connection closed');
|
||||
} else {
|
||||
console.error('[Proxy] Receive error on socket ' + socketId + ': ' + resultCode);
|
||||
console.error('[Hammer] Receive error on socket ' + socketId + ': ' + resultCode);
|
||||
}
|
||||
|
||||
// Clean up connections
|
||||
@@ -405,7 +405,7 @@ function setupConnectionHandlers() {
|
||||
chrome.sockets.tcp.onReceive.addListener(function(receiveInfo) {
|
||||
if (receiveInfo.data.byteLength === 0) {
|
||||
var socketId = receiveInfo.socketId;
|
||||
console.log('[Proxy] Socket ' + socketId + ' disconnected (EOF)');
|
||||
console.log('[Hammer] Socket ' + socketId + ' disconnected (EOF)');
|
||||
if (connections[socketId]) {
|
||||
closeConnection(socketId);
|
||||
} else if (reverseConnections[socketId]) {
|
||||
@@ -420,13 +420,13 @@ function setupConnectionHandlers() {
|
||||
// Check if this is data from a client or destination
|
||||
if (connections[socketId]) {
|
||||
// Data from client
|
||||
console.log('[Proxy] Received from client ' + socketId + ': ' + receiveInfo.data.byteLength + ' bytes');
|
||||
console.log('[Hammer] Received from client ' + socketId + ': ' + receiveInfo.data.byteLength + ' bytes');
|
||||
handleSocksData(socketId, receiveInfo.data);
|
||||
} else if (reverseConnections[socketId]) {
|
||||
// Data from destination
|
||||
handleDestinationData(socketId, receiveInfo.data);
|
||||
} else {
|
||||
console.warn('[Proxy] Received data from unknown socket: ' + socketId);
|
||||
console.warn('[Hammer] Received data from unknown socket: ' + socketId);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -434,21 +434,21 @@ function setupConnectionHandlers() {
|
||||
function initializeProxy() {
|
||||
// Prevent double initialization
|
||||
if (isInitialized) {
|
||||
console.log('[Proxy] Already initialized or initializing...');
|
||||
console.log('[Hammer] Already initialized or initializing...');
|
||||
return;
|
||||
}
|
||||
isInitialized = true;
|
||||
|
||||
console.log('[Proxy] Initializing Chrome SOCKS Proxy (with tunneling)...');
|
||||
console.log('[Hammer] Initializing Chrome\'s Hammer (with tunneling)...');
|
||||
|
||||
createServer(PROXY_HOST, PROXY_PORT, function(error, socketId) {
|
||||
if (error) {
|
||||
console.error('[Proxy] Failed to initialize:', error);
|
||||
console.error('[Hammer] Failed to initialize:', error);
|
||||
isInitialized = false; // Allow retry on failure
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[Proxy] SOCKS proxy is running on ' + PROXY_HOST + ':' + PROXY_PORT);
|
||||
console.log('[Hammer] Chrome\'s Hammer is running on ' + PROXY_HOST + ':' + PROXY_PORT);
|
||||
|
||||
// Setup handlers only once
|
||||
if (!handlersSetup) {
|
||||
@@ -460,13 +460,13 @@ function initializeProxy() {
|
||||
|
||||
// Chrome App lifecycle events
|
||||
chrome.app.runtime.onLaunched.addListener(function() {
|
||||
console.log('[Proxy] App launched');
|
||||
console.log('[Hammer] App launched');
|
||||
initializeProxy();
|
||||
});
|
||||
|
||||
// Chrome App lifecycle - restart when app is restarted
|
||||
chrome.app.runtime.onRestarted.addListener(function() {
|
||||
console.log('[Proxy] App restarted');
|
||||
console.log('[Hammer] App restarted');
|
||||
// Reset state and reinitialize
|
||||
isListening = false;
|
||||
isInitialized = false;
|
||||
@@ -476,7 +476,7 @@ chrome.app.runtime.onRestarted.addListener(function() {
|
||||
|
||||
// Handle the app window being closed
|
||||
chrome.app.window.onClosed.addListener(function() {
|
||||
console.log('[Proxy] App window closed');
|
||||
console.log('[Hammer] App window closed');
|
||||
// Clean up connections
|
||||
for (var socketId in connections) {
|
||||
try {
|
||||
@@ -510,11 +510,11 @@ chrome.alarms.create('keepAlive', { periodInMinutes: 1 });
|
||||
chrome.alarms.onAlarm.addListener(function(alarm) {
|
||||
if (alarm.name === 'keepAlive') {
|
||||
// Heartbeat: log activity to keep the app alive
|
||||
console.log('[Proxy] Heartbeat - Proxy is ' + (isListening ? 'active' : 'inactive'));
|
||||
console.log('[Hammer] Heartbeat - Proxy is ' + (isListening ? 'active' : 'inactive'));
|
||||
|
||||
// Check if server is still listening, restart if needed
|
||||
if (!isListening && !isInitialized) {
|
||||
console.log('[Proxy] Server not listening, reinitializing...');
|
||||
console.log('[Hammer] Server not listening, reinitializing...');
|
||||
initializeProxy();
|
||||
}
|
||||
|
||||
@@ -525,18 +525,18 @@ chrome.alarms.onAlarm.addListener(function(alarm) {
|
||||
|
||||
// Handle when app is suspended and resumed
|
||||
chrome.runtime.onSuspend.addListener(function() {
|
||||
console.log('[Proxy] App being suspended...');
|
||||
console.log('[Hammer] App being suspended...');
|
||||
});
|
||||
|
||||
chrome.runtime.onSuspendCanceled.addListener(function() {
|
||||
console.log('[Proxy] Suspend canceled - app is active again');
|
||||
console.log('[Hammer] Suspend canceled - app is active again');
|
||||
|
||||
// Reinitialize if needed after unsuspend
|
||||
if (!isListening) {
|
||||
console.log('[Proxy] Reinitializing after unsuspend...');
|
||||
console.log('[Hammer] Reinitializing after unsuspend...');
|
||||
isInitialized = false;
|
||||
initializeProxy();
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[Proxy] Background script loaded');
|
||||
console.log('[Hammer] Chrome\'s Hammer background script loaded');
|
||||
|
||||
Reference in New Issue
Block a user