-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessage.uc
More file actions
executable file
·63 lines (56 loc) · 1.38 KB
/
message.uc
File metadata and controls
executable file
·63 lines (56 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as math from "math";
import * as node from "node";
import * as channel from "channel";
const DEFAULT_PRIORITY = 64;
const ACK_PRIORITY = 120;
let callsign = null;
export function createMessage(to, from, namekey, type, payload, extra)
{
const hops = node.hopLimit();
const msg = {
from: from ?? node.id(), // From me by default
to: to ?? node.BROADCAST,
namekey: channel.getChannelByNameKey(namekey)?.namekey,
id: math.rand(),
rx_time: time(),
priority: DEFAULT_PRIORITY,
hop_limit: hops,
transport: "native",
originating_callsign: callsign,
data: {
[type]: payload
}
};
if (extra) {
for (let k in extra) {
if (k === "data") {
for (let j in extra.data) {
msg.data[j] = extra.data[j];
}
}
else {
msg[k] = extra[k];
}
}
}
return msg;
};
export function createAckMessage(msg, reason)
{
return createMessage(msg.from, null, msg.namekey, "routing", { error_reason: reason ?? 0, checksum: msg.data?.checksum }, {
priority: ACK_PRIORITY,
data: {
request_id: msg.id
}
});
};
export function setup(config)
{
callsign = config.callsign;
};
export function tick()
{
};
export function process()
{
};