(command: string)
| 96 | } |
| 97 | |
| 98 | private sendCommand(command: string): Promise<string> { |
| 99 | return new Promise((resolve, reject) => { |
| 100 | if (!this.socket) { |
| 101 | reject(new Error('Not connected to Tor control port')) |
| 102 | return |
| 103 | } |
| 104 | |
| 105 | const socket = this.socket |
| 106 | let buf = '' |
| 107 | |
| 108 | const cleanup = () => { |
| 109 | socket.off('data', onData) |
| 110 | socket.off('error', onError) |
| 111 | } |
| 112 | |
| 113 | const onError = (error: Error) => { |
| 114 | cleanup() |
| 115 | reject(error) |
| 116 | } |
| 117 | |
| 118 | const onData = (data: Buffer) => { |
| 119 | buf += data.toString() |
| 120 | if (!this.isCompleteTorReply(buf)) { |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | cleanup() |
| 125 | if (/^250/.test(buf)) { resolve(buf) } |
| 126 | else { reject(new Error(buf.trim())) } |
| 127 | } |
| 128 | |
| 129 | socket.on('data', onData) |
| 130 | socket.on('error', onError) |
| 131 | socket.write(`${command}\r\n`) |
| 132 | }) |
| 133 | } |
| 134 | |
| 135 | async addOnion(port: number, host?: string, privateKey?: string | null): Promise<OnionResult> { |
| 136 | const key = privateKey ?? 'NEW:BEST' |
no outgoing calls
no test coverage detected