Compare commits

...

2 Commits

Author SHA1 Message Date
raven 1efec85494 update 2023-01-10 12:27:58 -05:00
raven 9a53fceaee changes, adding error handles for connections and command blocking 2023-01-10 12:27:25 -05:00
1 changed files with 18 additions and 4 deletions

View File

@ -18,7 +18,7 @@ goodbye(() => swarm.destroy())
const conns = []
let USERPWD = "/"
let DAPI_KEY = {}
let USERNAME = "annon" + rand
let USERNAME = "anon" + rand
let LOGGEDIN = false
async function clearCursor() {
@ -105,6 +105,10 @@ swarm.on('connection', conn => {
})
})
swarm.on('error', (err) => {
console.log('Error connecting to peer:', err);
});
// Use readline to accept input from the user
const rl = readline.createInterface({
input: process.stdin,
@ -145,6 +149,8 @@ rl.on('line', input => {
}
const execute = input.startsWith(">")
if (input.startsWith("/") || input.startsWith("!")) return
if (execute) {
let inputdata = input.split(2)
const cmdToRun = inputdata.join(" ").replace("> ", "").replace(">", "")
@ -169,7 +175,6 @@ rl.on('line', input => {
})
}
const start = input.startsWith("/start")
if (start) {
startContainer(DAPI_KEY.key).then((data) => {
@ -224,11 +229,20 @@ rl.on('line', input => {
// Join a common topic
const topic = process.argv[2] ? b4a.from(process.argv[2], 'hex') : crypto.randomBytes(32)
const discovery = swarm.join(topic, { client: true, server: true })
// The flushed promise will resolve when the topic has been fully announced to the DHT
setTimeout(() => {
const discovery = swarm.join(topic, {
lookup: true,
announce: true
});
// The flushed promise will resolve when the topic has been fully announced to the DHT
discovery.flushed().then(() => {
console.log(`joined topic: ${b4a.toString(topic, 'hex')}\n(Share this key to others so they may join.)`)
console.log('You are now in a chatroom for your topic, feel free to chat.\n')
console.log('Want to login to the SSH.SURF API? Type "/login [APIKEY]" to login.\n\n')
})
}, 3000);