Basic Corelink Topologies
Programming Different Corelink Topologies
Corelink is a highly versatile software that allows users to send data in many different arrangements, called topologies. This article talks about the topologies one can create with the Corelink program, and how to make them.
Setting Up the Program
The first part of the program involves being the required setup. To do this, you'll need to supply the following information: - Username and Password - IP and ControlPort - Certificate - Workspace and Data Type - Data Sharing Protocol
On Javascript, this is done as shown below. These constants will be called by the program when initiating the sender.
const corelink = require('corelink-client')
const username = 'Testuser'
const password = 'Testpassword'
const config = {
ControlPort: 20012,
ControlIP: '127.0.0.1',
autoReconnect: false, // This determines whether your program reconnects to the server (if your server shuts down)
cert: 'D:/School/HSRN/test-cases/certificate-authority-crt.crt'
}
const workspace = 'Miscellaneous' // This can be whatever you want, as long as you remember it.
const datatype = 'goobers' // Despite the name, this can also be whatever you want, as long as it's the same for both sender and receiver.
const protocol = 'tcp'
corelink.debug = true
One-Way Senders and One-Way Receivers
The most simple topology involves one or many senders sending data to one or many receivers. The complexity of the program is the same regardless of how many senders or receivers are in your network.
In Javascript, creating a sender uses the following program:
const run_corelink_sender_program = async () => {
// Here we prepare our sender. The data we input earlier tells our program what workspace it should send the data, and what type the data needs to be.
let sender
if (await corelink.connect({ username, password }, config).catch((err) => { console.log(err) })) {
sender = await corelink.createSender({
workspace,
protocol,
type: datatype,
metadata: { name: 'Random Data' }, // In case even more details are needed, we can write metadata so that our receivers can filter for specific kinds of data.
}).catch((err) => { console.log(err) })
}
// Between this interval and the last program is where we run our program.
// Note that the data has to be sent in a Buffer or Unit8 Array Format.
// In this case, we just send 'hello' at an interval.
setInterval(() => corelink.send(sender, Buffer.from('hello')), 1000)
}
run_corelink_sender_program()
Making the receiver involves a similar process, with different ways to customize the data.
const run_corelink_receiver_program = async () => {
if (await corelink.connect({ username, password }, config).catch((err) => { console.log(err) })) {
await corelink.createReceiver({
workspace, protocol, type: datatype, echo: true, alert: true,
corelink.on('receiver', async (data) => {
// This subscribes our program to all of the streams that match our criteria, which you can adjust here
const options = { streamIDs: [data.streamID] }
await corelink.subscribe(options)
})
corelink.on('data', (streamID, data, header) => {
// This is where you decide what to do with the data.
console.log(streamID, data.toString(), JSON.stringify(header))
})
}
}
run_corelink_receiver_program()
Bidirectional Senders and Receivers
Making Corelink programs that both send and receive data are very similar. The only difference is that you create a sender and receiver at the same time.
const bidirectional_program = async () => {
if (await corelink.connect({ username, password }, config).catch((err) => { console.log(err) })) {
\\ This part creates the receiver.
receiver = await corelink.createReceiver({
workspace, protocol, type: datatype, echo: true, alert: true,
}).catch((err) => { console.log(err) })
\\ This part creates the sender.
sender = await corelink.createSender({
workspace,
protocol,
type: datatype,
metadata: { name: 'Random Data' },
}).catch((err) => { console.log(err) })
}
// This section does what the receiver does.
corelink.on('receiver', async (data) => {
const options = { streamIDs: [data.streamID] }
await corelink.subscribe(options)
})
corelink.on('data', (streamID, data, header) => {
// Here you can modify the data you provide.
console.log(streamID, data.toString(), JSON.stringify(header))
})
// This section does what the sender does.
setInterval(() => corelink.send(sender, Buffer.from('Hi!')), 1000)
}