mirror of
https://github.com/Cameri/nostream.git
synced 2025-08-09 04:31:59 +02:00
fix: 🐛 error retrying the connection
If the first connection attempt failed. Later it was given as connected
This commit is contained in:
@@ -16,7 +16,7 @@ const getPrivateKeyFile = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const createTorConfig = (): TorConfig => {
|
export const createTorConfig = (): TorConfig => {
|
||||||
return {
|
return {
|
||||||
host: process.env.TOR_HOST,
|
host: process.env.TOR_HOST,
|
||||||
port: process.env.TOR_CONTROL_PORT ? Number(process.env.TOR_CONTROL_PORT) : 9051,
|
port: process.env.TOR_CONTROL_PORT ? Number(process.env.TOR_CONTROL_PORT) : 9051,
|
||||||
@@ -31,16 +31,27 @@ export const getTorClient = async () => {
|
|||||||
const config = createTorConfig()
|
const config = createTorConfig()
|
||||||
debug('config: %o', config)
|
debug('config: %o', config)
|
||||||
|
|
||||||
if (config.port) {
|
if (config.host !== undefined) {
|
||||||
debug('connecting')
|
debug('connecting')
|
||||||
client = new Tor(config)
|
client = new Tor(config)
|
||||||
|
try{
|
||||||
await client.connect()
|
await client.connect()
|
||||||
|
}catch(error){
|
||||||
|
client = undefined
|
||||||
|
}
|
||||||
debug('connected')
|
debug('connected')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
export const closeTorClient = async () => {
|
||||||
|
if (client) {
|
||||||
|
|
||||||
|
await client.quit()
|
||||||
|
client = undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const addOnion = async (
|
export const addOnion = async (
|
||||||
port: number,
|
port: number,
|
||||||
@@ -66,6 +77,7 @@ export const addOnion = async (
|
|||||||
debug('hidden service: %s:%d', hiddenService.ServiceID, port)
|
debug('hidden service: %s:%d', hiddenService.ServiceID, port)
|
||||||
|
|
||||||
if (hiddenService?.PrivateKey) {
|
if (hiddenService?.PrivateKey) {
|
||||||
|
console.log('saving private key to %s', path)
|
||||||
debug('saving private key to %s', path)
|
debug('saving private key to %s', path)
|
||||||
|
|
||||||
await writeFile(path, hiddenService.PrivateKey, 'utf8')
|
await writeFile(path, hiddenService.PrivateKey, 'utf8')
|
||||||
|
Reference in New Issue
Block a user