mirror of
https://github.com/cupcakearmy/master-thesis.git
synced 2026-04-02 11:55:30 +00:00
Clear History
This commit is contained in:
31
code/scenarios/one-sat-two-base/sat/index.js
Normal file
31
code/scenarios/one-sat-two-base/sat/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import pino from 'pino'
|
||||
|
||||
const logger = pino({ base: false })
|
||||
|
||||
const interval = setInterval(async () => {
|
||||
const ips = await fetch('http://localhost:42069/discoverable')
|
||||
.then((res) => res.json())
|
||||
.catch(() => [])
|
||||
|
||||
if (!ips.length) {
|
||||
logger.info('no peers found')
|
||||
return
|
||||
}
|
||||
|
||||
for (const ip of ips) {
|
||||
// Sync some data
|
||||
// Don't await on purpose
|
||||
fetch(`http://${ip}:3000/time`)
|
||||
.then((res) => res.text())
|
||||
.then((time) => logger.info({ peer: ip }, `time from peer: ${time}`))
|
||||
.catch(logger.error)
|
||||
fetch(`http://${ip}:3000/transmit`, { method: 'POST', body: `Observation: ${Math.random()}` }).catch(logger.error)
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
function exit() {
|
||||
clearInterval(interval)
|
||||
process.exit(0)
|
||||
}
|
||||
process.on('SIGINT', exit)
|
||||
process.on('SIGTERM', exit)
|
||||
Reference in New Issue
Block a user