Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions js-client/src/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
* @todo TODO: use only one port for https+wss
*
* @param {string} host (ex: localhost, example.com)
* @param {string} port (ex: 4990, 8080, 5000, 443…)
* @param {string|number} port (ex: 443, 8443)
* @param {string} [pathSuffix] Format: "guard-node/path-spec/proxy-auth"
* @return {endpoint_t}
*/
lnn.endpoint = function(host, port)
lnn.endpoint = function(host, port, pathSuffix)
{
const parseSuffix = (suffix) => {
const components = (suffix || '').split('/').filter(Boolean);
return {
guard: components[0] || 'default-guard',
pathSpec: '/' + (components[1] || 'tor/default-path'),
proxyAuth: components[2] ? decodeURIComponent(components[2]) : null
};
};
const {guard, pathSpec, proxyAuth} = parseSuffix(pathSuffix);
const baseURL = `https://${host}:${port}${pathSpec}`;
const wsBaseURL = `wss://${host}:${port}${pathSpec}`;

var http = "http://" + host + ":" + port.toString()
http += lnn.api.url

Expand All @@ -36,9 +49,9 @@ lnn.endpoint = function(host, port)
* @property {string} consensus GET /consensus
*/
var urls = {
ws: ws,
http: http,
guard: http + "/guard",
ws: wsBaseURL,
http: baseURL,
guard: `${baseURL}/guard/${guard}`,
socket: ws + "/channels",
channels: http + "/channels",
consensus: http + "/consensus",
Expand Down Expand Up @@ -166,17 +179,18 @@ lnn.endpoint = function(host, port)
signing_keys: null,

select_path: false,
proxyAuth: proxyAuth,

/*perform http get/post request*/

http_request: function(url, method, data, data_type, success, error)
{
if (error === undefined)
error = function() { }
if (success === undefined)
success = function() { }

lnn.send_req(endpoint,url, method, data, data_type, success,error)

const headers = this.proxyAuth ? {'Proxy-Authorization': `Bearer ${this.proxyAuth}`} : {};
lnn.send_req(endpoint,url, method, data, data_type, success,error, headers)
},

/*destroy the circuit*/
Expand Down
57 changes: 57 additions & 0 deletions tools/download_consensus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import requests
import tarfile

base_url_server = "https://collector.torproject.org/archive/relay-descriptors/server-descriptors/server-descriptors-{month}.tar.xz"
base_url_consensus = "https://collector.torproject.org/archive/relay-descriptors/consensuses/consensuses-{month}.tar.xz"

months_of_interest = ["2024-10", "2024-11"] # Add the months for which tor data needs to be downloaded
output_dir = "./Tor_consensus"

if not os.path.exists(output_dir):
os.makedirs(output_dir)


for month in months_of_interest:
print(f"Processing data for {month}...")
folder_name = month.replace("-", "_")
month_folder_path = os.path.join(output_dir, folder_name)
if not os.path.exists(month_folder_path):
os.makedirs(month_folder_path)

consensus_folder = os.path.join(month_folder_path, f"consensuses-{month}")
server_descriptors_folder = os.path.join(month_folder_path, f"server-descriptors-{month}")

os.makedirs(consensus_folder, exist_ok=True)
os.makedirs(server_descriptors_folder, exist_ok=True)

server_file_url = base_url_server.format(month=month)
consensus_file_url = base_url_consensus.format(month=month)

server_file_path = os.path.join(month_folder_path, f"server-descriptors-{month}.tar.xz")
consensus_file_path = os.path.join(month_folder_path, f"consensuses-{month}.tar.xz")

response = requests.get(server_file_url, stream=True)
with open(server_file_path, "wb") as file:
for chunk in response.iter_content(chunk_size=1024):
file.write(chunk)
with tarfile.open(server_file_path, "r:xz") as tar:
for member in tar.getmembers():
member.name = os.path.basename(member.name) # Avoid nested folders
tar.extract(member, server_descriptors_folder)
os.remove(server_file_path)
print("Server-descriptors downloaded and extracted successfully.")


response = requests.get(consensus_file_url, stream=True)
with open(consensus_file_path, "wb") as file:
for chunk in response.iter_content(chunk_size=1024):
file.write(chunk)
with tarfile.open(consensus_file_path, "r:xz") as tar:
for member in tar.getmembers():
member.name = os.path.basename(member.name) # Avoid nested folders
tar.extract(member, consensus_folder)
os.remove(consensus_file_path)
print("Consensuses downloaded and extracted successfully.")

print("All data processed successfully.")