summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/app/nostrill.hoon59
-rw-r--r--app/lib/nostrill.hoon19
-rw-r--r--app/lib/websockets.hoon3
3 files changed, 60 insertions, 21 deletions
diff --git a/app/app/nostrill.hoon b/app/app/nostrill.hoon
index 2a1fa2f..271f774 100644
--- a/app/app/nostrill.hoon
+++ b/app/app/nostrill.hoon
@@ -30,8 +30,8 @@
^- (quip card:agent:gall agent:gall)
=/ default (default-state:lib bowl)
:_ this(state default)
- :~ shim-binding:cards
- ==
+ bindings:cards
+
::
++ on-save
^- vase
@@ -42,7 +42,9 @@
^- (quip card:agent:gall agent:gall)
=/ old-state !<(versioned-state old-state)
?- -.old-state
- %0 `this(state old-state)
+ %0 :_ this(state old-state)
+ bindings:cards
+
==
:: `this(state (default-state:lib bowl))
::
@@ -60,31 +62,48 @@
==
++ handle-ws-handshake
=/ order !<([@ inbound-request:eyre] vase)
+ ~& >> nostrill-ws-handshake=order
+ =/ url url.request.order
+ =/ pat=(unit path) (rush url stap)
+ ?~ pat ~& "pat-parsing-failed" `this
+ =/ ok=? ?+ u.pat .n
+ [%nostrill-ui ~] authenticated.order
+ [%nostrill ~] .y :: TODO which nostr clients do we filter
+ [%nostr-shim ~] .y :: TODO deprecate?
+ ==
:_ this
- :: TODO refuse if...?
- (accept-handshake:ws -.order)
+ ?: ok (accept-handshake:ws -.order) (refuse-handshake:ws -.order)
:: we behave like a Server here, mind you. messages from clients, not relays
++ handle-ws-msg
- =/ order !<([wid=@ msg=websocket-message:eyre] vase)
+ =/ order !<([wid=@ =path msg=websocket-message:eyre] vase)
:: ~& opcode=op=opcode.msg.order :: 0 for continuation, 1 for text, 2 for binary, 9 for ping 0xa for pong
=/ msg message.msg.order
?~ msg `this
- =/ jsons=@t q.data.u.msg
- ~& >> ws-msg-jsons=jsons
- =/ jsonm (de:json:html jsons)
- ?~ jsonm `this
- =/ client-msg (parse-client-msg:nreq u.jsonm)
- ?~ client-msg ~& "wrong nostr ws msg from client" `this
- :: TODO de-json thing and handle whatever
- =^ cs state ?- -.u.client-msg
- %req `state
- %event (handle-client-event:mutan -.order event.u.client-msg)
- %auth `state
- %close `state
+ =/ wsdata=@t q.data.u.msg
+ ~& >> ws-msg-data=[path.order wsdata]
+ |^
+ ?+ path.order `this
+ [%nostrill-ui ~] handle-ui-ws
+ [%nostrill ~] handle-nostr-client-ws
==
- [cs this]
::
- ::
+ ++ handle-ui-ws
+ =/ cs (ui-ws-res:lib -.order wsdata)
+ [cs this]
+ ++ handle-nostr-client-ws
+ =/ jsonm (de:json:html wsdata)
+ ?~ jsonm `this
+ =/ client-msg (parse-client-msg:nreq u.jsonm)
+ ?~ client-msg ~& "wrong nostr ws msg from client" `this
+ :: TODO de-json thing and handle whatever
+ =^ cs state ?- -.u.client-msg
+ %req `state
+ %event (handle-client-event:mutan -.order event.u.client-msg)
+ %auth `state
+ %close `state
+ ==
+ [cs this]
+ --
++ handle-comms
=/ pok (cast-poke:coms q.vase)
?: ?=(%dbug -.pok) (debug +.pok)
diff --git a/app/lib/nostrill.hoon b/app/lib/nostrill.hoon
index 41caff2..933dc7f 100644
--- a/app/lib/nostrill.hoon
+++ b/app/lib/nostrill.hoon
@@ -1,5 +1,6 @@
/- post=trill-post, nsur=nostr, sur=nostrill, gate=trill-gate, comms=nostrill-comms
-/+ trill=trill-post, nostr-keys, sr=sortug, jsonlib=json-nostrill
+/+ trill=trill-post, nostr-keys, sr=sortug, jsonlib=json-nostrill,
+ ws=websockets
|%
::
++ default-state |= =bowl:gall ^- state:sur
@@ -28,12 +29,28 @@
~& >> total=total-received
$(l t.l)
+++ ui-ws-res |= [wid=@ msg=@t]
+
+ =/ resmsg (cat 3 msg (cat 3 msg msg))
+ =/ octs (as-octs:mimes:html resmsg)
+ =/ res-event=websocket-event:eyre [%message 1 `octs]
+ (give-ws-payload:ws wid res-event)
::
++ cards
|_ =bowl:gall
++ shim-binding ^- card:agent:gall
[%pass /binding %arvo %e %connect [~ /nostr-shim] dap.bowl]
+
+ ++ relay-binding ^- card:agent:gall
+ [%pass /binding %arvo %e %connect [~ /nostrill] dap.bowl]
+ ++ ui-binding ^- card:agent:gall
+ [%pass /binding %arvo %e %connect [~ /nostrill-ui] dap.bowl]
+ ++ bindings
+ :~ shim-binding
+ relay-binding
+ ui-binding
+ ==
++ update-ui |= =fact:ui:sur ^- card:agent:gall
=/ jon (fact:en:jsonlib fact)
[%give %fact ~[/ui] %json !>(jon)]
diff --git a/app/lib/websockets.hoon b/app/lib/websockets.hoon
index 9faea96..4d1f952 100644
--- a/app/lib/websockets.hoon
+++ b/app/lib/websockets.hoon
@@ -10,5 +10,8 @@
++ accept-handshake |= wid=@
=/ response [%accept ~]
(give-ws-payload wid response)
+ ++ refuse-handshake |= wid=@
+ =/ response [%reject ~]
+ (give-ws-payload wid response)
--