Rename "broker" to "server"
This commit is contained in:
parent
b682a3fc3f
commit
32bccdbad9
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
s6-svwait ../avahi-daemon
|
||||
cd /data/packages/broker
|
||||
cd /data/packages/server
|
||||
exec node lib/index.js
|
|
@ -1,85 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
import {
|
||||
Decoder, Encoder, Bytes,
|
||||
Observe, Skeleton,
|
||||
genUuid,
|
||||
} from "@syndicate-lang/core";
|
||||
|
||||
const WS = activate require("@syndicate-lang/driver-websocket");
|
||||
|
||||
const {
|
||||
Connect, Peer,
|
||||
Assert, Clear, Message,
|
||||
Add, Del, Msg, Err,
|
||||
Ping, Pong,
|
||||
makeDecoder,
|
||||
} = activate require("./protocol");
|
||||
|
||||
assertion type WSBroker(url, scope);
|
||||
|
||||
assertion type ToBroker(addr, assertion);
|
||||
assertion type FromBroker(addr, assertion);
|
||||
assertion type BrokerConnection(addr);
|
||||
assertion type BrokerConnected(addr);
|
||||
message type ForceBrokerDisconnect(addr);
|
||||
|
||||
message type _BrokerPacket(addr, packet);
|
||||
|
||||
Object.assign(module.exports, {
|
||||
WSBroker,
|
||||
ToBroker, FromBroker,
|
||||
BrokerConnection, BrokerConnected,
|
||||
ForceBrokerDisconnect,
|
||||
});
|
||||
|
||||
spawn named "BrokerClientFactory" {
|
||||
during ToBroker($addr, _) assert BrokerConnection(addr);
|
||||
during Observe(FromBroker($addr, _)) assert BrokerConnection(addr);
|
||||
during Observe(BrokerConnected($addr)) assert BrokerConnection(addr);
|
||||
|
||||
during BrokerConnection($addr(WSBroker($url, $scope))) spawn named ['Broker', addr] {
|
||||
const wsId = genUuid('broker');
|
||||
|
||||
during WS.WebSocket(wsId, url, {}) {
|
||||
assert BrokerConnected(addr);
|
||||
|
||||
function w(x) {
|
||||
send WS.DataOut(wsId, new Encoder().push(x).contents());
|
||||
}
|
||||
|
||||
on start w(Connect(scope));
|
||||
|
||||
on message WS.DataIn(wsId, $data) {
|
||||
if (data instanceof Bytes) {
|
||||
send _BrokerPacket(addr, makeDecoder(data).next());
|
||||
}
|
||||
}
|
||||
|
||||
during ToBroker(addr, $a) {
|
||||
const ep = genUuid('pub');
|
||||
on start w(Assert(ep, a));
|
||||
on stop w(Clear(ep));
|
||||
}
|
||||
|
||||
on message ToBroker(addr, $a) w(Message(a));
|
||||
|
||||
on message _BrokerPacket(addr, Ping()) w(Pong());
|
||||
|
||||
during Observe(FromBroker(addr, $spec)) {
|
||||
const ep = genUuid('sub');
|
||||
on start w(Assert(ep, Observe(spec)));
|
||||
on stop w(Clear(ep));
|
||||
on message _BrokerPacket(addr, Add(ep, $vs)) {
|
||||
react {
|
||||
assert Skeleton.instantiateAssertion(FromBroker(addr, spec), vs);
|
||||
stop on message _BrokerPacket(addr, Del(ep, vs));
|
||||
}
|
||||
}
|
||||
on message _BrokerPacket(addr, Msg(ep, $vs)) {
|
||||
send Skeleton.instantiateAssertion(FromBroker(addr, spec), vs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@syndicate-lang/broker",
|
||||
"name": "@syndicate-lang/server",
|
||||
"private": true,
|
||||
"version": "0.0.8",
|
||||
"license": "GPL-3.0+",
|
||||
|
@ -26,6 +26,6 @@
|
|||
},
|
||||
"main": "lib/index.js",
|
||||
"bin": {
|
||||
"syndicate-broker": "./bin/syndicate-broker.js"
|
||||
"syndicate-server": "./bin/syndicate-server.js"
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ const UI = activate require("@syndicate-lang/driver-browser-ui");
|
|||
// @jsx UI.html
|
||||
// @jsxFrag UI.htmlFragment
|
||||
|
||||
const { WSBroker, ToBroker, FromBroker, BrokerConnected } = activate require("./client");
|
||||
const { WSServer, ToServer, FromServer, ServerConnected } = activate require("./client");
|
||||
|
||||
assertion type Present(name);
|
||||
assertion type Says(who, what);
|
||||
|
@ -29,31 +29,31 @@ spawn {
|
|||
const ui = new UI.Anchor();
|
||||
|
||||
during UI.UIChangeableProperty('#wsurl', 'value', $url) {
|
||||
const addr = WSBroker(url, "broker");
|
||||
during BrokerConnected(addr) {
|
||||
const addr = WSServer(url, "broker");
|
||||
during ServerConnected(addr) {
|
||||
on start outputItem(<span class="connected">connected to {addr}</span>,
|
||||
'state_connected');
|
||||
on stop outputItem(<span class="disconnected">disconnected from {addr}</span>,
|
||||
'state_disconnected');
|
||||
|
||||
assert ToBroker(addr, Present(this.nym));
|
||||
during FromBroker(addr, Present($who)) {
|
||||
assert ToServer(addr, Present(this.nym));
|
||||
during FromServer(addr, Present($who)) {
|
||||
assert ui.context(who).html('#nymlist', <li><span class="nym">{who}</span></li>);
|
||||
}
|
||||
|
||||
on message UI.GlobalEvent('#send_chat', 'click', _) {
|
||||
if (this.next_chat) send ToBroker(addr, Says(this.nym, this.next_chat));
|
||||
if (this.next_chat) send ToServer(addr, Says(this.nym, this.next_chat));
|
||||
send UI.SetProperty('#chat_input', 'value', '');
|
||||
}
|
||||
|
||||
on message FromBroker(addr, Says($who, $what)) {
|
||||
on message FromServer(addr, Says($who, $what)) {
|
||||
outputItem(<span class="utterance">
|
||||
<span class="nym">{who}</span><span class="utterance">{what}</span>
|
||||
</span>);
|
||||
}
|
||||
|
||||
// on message Syndicate.WakeDetector.wakeEvent() {
|
||||
// :: forceBrokerDisconnect(addr);
|
||||
// :: forceServerDisconnect(addr);
|
||||
// }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
"use strict";
|
||||
|
||||
import {
|
||||
Decoder, Encoder, Bytes,
|
||||
Observe, Skeleton,
|
||||
genUuid,
|
||||
} from "@syndicate-lang/core";
|
||||
|
||||
const WS = activate require("@syndicate-lang/driver-websocket");
|
||||
|
||||
const {
|
||||
Connect, Peer,
|
||||
Assert, Clear, Message,
|
||||
Add, Del, Msg, Err,
|
||||
Ping, Pong,
|
||||
makeDecoder,
|
||||
} = activate require("./protocol");
|
||||
|
||||
assertion type WSServer(url, scope);
|
||||
|
||||
assertion type ToServer(addr, assertion);
|
||||
assertion type FromServer(addr, assertion);
|
||||
assertion type ServerConnection(addr);
|
||||
assertion type ServerConnected(addr);
|
||||
message type ForceServerDisconnect(addr);
|
||||
|
||||
message type _ServerPacket(addr, packet);
|
||||
|
||||
Object.assign(module.exports, {
|
||||
WSServer,
|
||||
ToServer, FromServer,
|
||||
ServerConnection, ServerConnected,
|
||||
ForceServerDisconnect,
|
||||
});
|
||||
|
||||
spawn named "ServerClientFactory" {
|
||||
during ToServer($addr, _) assert ServerConnection(addr);
|
||||
during Observe(FromServer($addr, _)) assert ServerConnection(addr);
|
||||
during Observe(ServerConnected($addr)) assert ServerConnection(addr);
|
||||
|
||||
during ServerConnection($addr(WSServer($url, $scope))) spawn named ['Server', addr] {
|
||||
const wsId = genUuid('server');
|
||||
|
||||
during WS.WebSocket(wsId, url, {}) {
|
||||
assert ServerConnected(addr);
|
||||
|
||||
function w(x) {
|
||||
send WS.DataOut(wsId, new Encoder().push(x).contents());
|
||||
}
|
||||
|
||||
on start w(Connect(scope));
|
||||
|
||||
on message WS.DataIn(wsId, $data) {
|
||||
if (data instanceof Bytes) {
|
||||
send _ServerPacket(addr, makeDecoder(data).next());
|
||||
}
|
||||
}
|
||||
|
||||
during ToServer(addr, $a) {
|
||||
const ep = genUuid('pub');
|
||||
on start w(Assert(ep, a));
|
||||
on stop w(Clear(ep));
|
||||
}
|
||||
|
||||
on message ToServer(addr, $a) w(Message(a));
|
||||
|
||||
on message _ServerPacket(addr, Ping()) w(Pong());
|
||||
|
||||
during Observe(FromServer(addr, $spec)) {
|
||||
const ep = genUuid('sub');
|
||||
on start w(Assert(ep, Observe(spec)));
|
||||
on stop w(Clear(ep));
|
||||
on message _ServerPacket(addr, Add(ep, $vs)) {
|
||||
react {
|
||||
assert Skeleton.instantiateAssertion(FromServer(addr, spec), vs);
|
||||
stop on message _ServerPacket(addr, Del(ep, vs));
|
||||
}
|
||||
}
|
||||
on message _ServerPacket(addr, Msg(ep, $vs)) {
|
||||
send Skeleton.instantiateAssertion(FromServer(addr, spec), vs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ const TCP_PORT = 8001;
|
|||
|
||||
const server = Http.HttpServer(null, HTTP_PORT);
|
||||
|
||||
const dataspaceId = 'EToUNUJI0ykSfudmN9Z99wu62qGQB1nd8SHvjNtL5tM'; // public key of root broker
|
||||
const dataspaceId = 'EToUNUJI0ykSfudmN9Z99wu62qGQB1nd8SHvjNtL5tM'; // public key of root server
|
||||
const localId = RandomID.randomId(8, false);
|
||||
const gatewayId = dataspaceId + ':' + localId;
|
||||
|
||||
|
@ -109,13 +109,13 @@ spawn named 'websocketListener' {
|
|||
spawn named 'tcpListener' {
|
||||
assert M.Publish(M.Service(gatewayId, '_syndicate._tcp'), null, TCP_PORT, ["tier=0"]);
|
||||
on asserted S.IncomingConnection($id, S.TcpListener(TCP_PORT)) {
|
||||
spawnStreamConnection('tcpBroker', id);
|
||||
spawnStreamConnection('tcpServer', id);
|
||||
}
|
||||
}
|
||||
|
||||
spawn named 'unixListener' {
|
||||
on asserted S.IncomingConnection($id, S.UnixSocketServer("./sock")) {
|
||||
spawnStreamConnection('unixBroker', id);
|
||||
spawnStreamConnection('unixServer', id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,11 +226,11 @@ spawn named 'peerDiscovery' {
|
|||
|
||||
/*
|
||||
|
||||
If there's a broker on our gateway interface, see if it's better than us.
|
||||
If there's a server on our gateway interface, see if it's better than us.
|
||||
- if it is, use it.
|
||||
- if it's not, pretend it isn't there.
|
||||
|
||||
If there's no broker on our gateway interface (or we're pretending
|
||||
If there's no server on our gateway interface (or we're pretending
|
||||
none exists), try to connect to the top.
|
||||
|
||||
*/
|
|
@ -4,7 +4,7 @@ const UI = activate require("@syndicate-lang/driver-browser-ui");
|
|||
// @jsx UI.html
|
||||
// @jsxFrag UI.htmlFragment
|
||||
|
||||
const { WSBroker, ToBroker, FromBroker, BrokerConnected } = activate require("./client");
|
||||
const { WSServer, ToServer, FromServer, ServerConnected } = activate require("./client");
|
||||
|
||||
assertion type ConnectionScope(connId, scope);
|
||||
message type Disconnect(connId);
|
||||
|
@ -13,7 +13,7 @@ spawn {
|
|||
const ui = new UI.Anchor();
|
||||
assert ui.html('body',
|
||||
<div id="main">
|
||||
<h1>Broker monitor</h1>
|
||||
<h1>Server monitor</h1>
|
||||
<div id="scopes"></div>
|
||||
</div>);
|
||||
|
||||
|
@ -23,22 +23,22 @@ spawn {
|
|||
u.pathname = '/';
|
||||
return u.toString();
|
||||
})();
|
||||
const addr = WSBroker(url, "monitor");
|
||||
const addr = WSServer(url, "monitor");
|
||||
|
||||
during BrokerConnected(addr) {
|
||||
during FromBroker(addr, ConnectionScope(_, $scope)) {
|
||||
during ServerConnected(addr) {
|
||||
during FromServer(addr, ConnectionScope(_, $scope)) {
|
||||
const ui = new UI.Anchor();
|
||||
assert ui.html('#scopes',
|
||||
<div class={`scope_${scope}`}>
|
||||
<p>Scope: <tt>{scope}</tt></p>
|
||||
<ul></ul>
|
||||
</div>);
|
||||
during FromBroker(addr, ConnectionScope($id, scope)) {
|
||||
during FromServer(addr, ConnectionScope($id, scope)) {
|
||||
const ui = new UI.Anchor();
|
||||
assert ui.html(`#scopes div.scope_${scope} ul`,
|
||||
<li>{id.toString()} <button class="disconnect">Disconnect</button></li>);
|
||||
on message UI.UIEvent(ui.fragmentId, 'button.disconnect', 'click', _) {
|
||||
send ToBroker(addr, Disconnect(id));
|
||||
send ToServer(addr, Disconnect(id));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ spawn named 'test' {
|
|||
// }
|
||||
|
||||
field this.count = 0;
|
||||
dataflow console.log('Broker count:', this.count);
|
||||
dataflow console.log('Service count:', this.count);
|
||||
|
||||
during M.Discovered(M.Service($name, '_syndicate+ws._tcp'), $host, $port, $txt, $addr, "IPv4", _)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue