Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
privatestoragemobile
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PrivateStorage
privatestoragemobile
Commits
f02c9069
Commit
f02c9069
authored
1 year ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
remove dev aid
parent
929c0e92
No related branches found
No related tags found
1 merge request
!57
Magic wormhole invites
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
obelisk/Main.hs
+0
-106
0 additions, 106 deletions
obelisk/Main.hs
with
0 additions
and
106 deletions
obelisk/Main.hs
deleted
100644 → 0
+
0
−
106
View file @
929c0e92
{-# LANGUAGE OverloadedStrings #-}
import
MagicWormhole
import
MagicWormhole.Internal.Messages
(
Mood
(
..
))
import
qualified
MagicWormhole.Internal.Versions
as
Versions
import
Crypto.Spake2
import
Control.Monad.IO.Class
import
Protolude.Conv
(
toS
)
import
GHC.Conc
(
atomically
)
import
qualified
Data.ByteString
as
B
import
qualified
Data.Text
as
T
import
Data.Text.Encoding
(
encodeUtf8
)
import
Data.Aeson.Types
-- encode version information
data
InvitesVersion0
=
InvitesVersion0
deriving
(
Eq
,
Show
)
instance
ToJSON
InvitesVersion0
where
toJSON
InvitesVersion0
=
object
[
"magic-folder"
.=
object
[
"supported-messages"
.=
[
"invite-v1"
::
String
]]]
instance
FromJSON
InvitesVersion0
where
parseJSON
(
Object
v
)
=
do
(
Object
mf
)
<-
v
.:
"magic-folder"
-- supported <- mf .: "supported-messages"
return
InvitesVersion0
{-
interactively, this works:
Data.Aeson.decode "{\"app_versions\": {\"magic-folder\": {\"supported-messages\": [\"invite-v1\"]}}}" :: Maybe (V.Versions InvitesVersion0)
fromList [("app_versions",Object (fromList [("magic-folder",Object (fromList [("supported-messages",Array [String "invite-v1"])]))]))]
Just (Versions InvitesVersion0)
-}
--
-- Nothing -> retry
-- STM thing, only retry when the var yhou read changes
{-
{
"protocol": "invite-v1",
"kind": "join-folder",
"folder-name": "<free-form string>",
"collective": "<read-capability of the Collective>",
"participant-name": "<admin-provided name>",
"mode": "read-write",
}
-}
--performInvite :: MagicWormhole.EncryptedConnection -> IO a
performInvite
conn
=
do
MagicWormhole
.
PlainText
msg
<-
atomically
$
receiveMessage
conn
print
msg
sendMessage
conn
(
MagicWormhole
.
PlainText
"{
\"
protocol
\"
:
\"
invite-v1
\"
,
\"
kind
\"
:
\"
join-folder-accept
\"
}"
)
pure
msg
-- "undefined" can be any type
-- Password == ByteString (i think?)
receiveInvite
::
String
->
String
->
MagicWormhole
.
Session
->
IO
()
receiveInvite
nameplate
code
session
=
do
-- nameplate <- liftIO $ MagicWormhole.allocate session
print
nameplate
mailbox
<-
liftIO
$
MagicWormhole
.
claim
session
(
MagicWormhole
.
Nameplate
(
T
.
pack
nameplate
))
print
mailbox
peer
<-
liftIO
$
MagicWormhole
.
open
session
mailbox
let
passcode
=
encodeUtf8
$
T
.
pack
(
nameplate
++
"-"
++
code
)
print
passcode
-- let passcode = (toS n) <> "-" <> "foo-bar" -- toS code
result
<-
liftIO
$
MagicWormhole
.
withEncryptedConnection
peer
(
Crypto
.
Spake2
.
makePassword
passcode
)
InvitesVersion0
performInvite
MagicWormhole
.
release
session
(
Just
(
MagicWormhole
.
Nameplate
(
T
.
pack
nameplate
)))
x
<-
MagicWormhole
.
close
session
(
Just
mailbox
)
(
Just
Happy
)
print
"hi"
pure
()
--result
main
::
IO
()
main
=
do
side
<-
MagicWormhole
.
generateSide
-- "ws://relay.magic-wormhole.io:4000/v1"
let
endpoint
=
MagicWormhole
.
WebSocketEndpoint
"relay.magic-wormhole.io"
4000
"/v1"
print
side
MagicWormhole
.
runClient
endpoint
appID
side
Nothing
$
(
receiveInvite
"5"
"decimal-slowdown"
)
where
appID
=
MagicWormhole
.
AppID
"private.storage/magic-folder/invites"
-- let endpoint = rendezvousEndpoint options
-- case cmd options of
-- Send -> MagicWormhole.runClient endpoint appID side Nothing $ \session ->
-- sendText session "potato" "Brave new world that has such offers in it"
-- Receive -> MagicWormhole.runClient endpoint appID side Nothing $ \session -> do
-- message <- receiveText session
-- putStr message
-- Bounce -> bounce endpoint appID
-- where
-- appID = MagicWormhole.AppID "jml.io/hocus-pocus"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment