-
Notifications
You must be signed in to change notification settings - Fork 3
/
Community.rho
97 lines (97 loc) · 3.98 KB
/
Community.rho
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
new Community, commMap, stdout(`rho:io:stdout`), lookup(`rho:registry:lookup`),
insertArbitrary(`rho:registry:insertArbitrary`), uriCh, ret, ack in {
insertArbitrary!(*Community,*uriCh) |
for ( uri <- uriCh ) {
stdout!(["#define $Community",*uri])
} |
commMap!({}) |
contract Community (@"new", @name, inbox, return) = {
new admin, methods, userlist, infoCh, ret in {
userlist!([]) | methods!({}) |
infoCh!({}) |
stdout!("creating community.") |
for (@comms <- commMap ) {
if ( comms.get(name) != Nil ) {
stdout!("error: community with that name already exists") |
commMap!(comms) |
return!(Nil)
} else {
lookup!($Directory,*ret) |
for ( Directory <- ret ) {
stdout!(["got directory", *Directory]) |
Directory!(*ret) |
for ( @{"read": *read, "write": *write, "grant": *grant, ..._ } <- ret ) {
commMap!(comms.union({name: *infoCh})) |
infoCh!({"name": name, "request": *inbox}) |
return!({"admin": *admin, "read": *read, "write": *write, "grant": *grant}) |
contract admin(@"add info", @key, @value, return) = {
for (info <- infoCh) {
infoCh!(*info.set(key, value))
}
} |
contract admin(@"add user", @username, @inbox, return) = {
//TODO see if already a member
for ( @list <- userlist) {
if ( list.length() == 0 ) { userlist!([username]) |
write!(username, {"inbox": inbox, "delegate": Nil}, *stdout) |
stdout!("first user being added")
} else {
userlist!(list.slice(1,list.length()) ++ [ username, list.nth(0)]) |
write!(username, {"inbox": inbox, "delegate": list.nth(0)}, *stdout) |
stdout!(list.slice(1,list.length()) ++ [username, list.nth(0)])
}
} |
grant!(username, *ret) |
for ( updateself <- ret ) {
return!({"selfupdate": *updateself})
}
}
}
}
}
}
}
} |
contract Community (@"request", @name, @userid, return) = {
for ( @{map /\ {=name: *infoCh, ..._}} <- commMap ) {
commMap!(map) |
for ( @{info /\ {"request": *inbox, ..._ }} <- infoCh ) {
//stdout!(*info) |
inbox!(["Community", "request", name, userid])|
infoCh!(info) |
return!(info)
}
}
} |
contract Community (@"lookup", @name, return) = {
for ( @{map /\ {=name: *infoCh, ..._}} <- commMap ) {
commMap!(map) |
for ( info <- infoCh ) {
//stdout!(*info) |
infoCh!(*info) |
return!(*info)
}
}
} |
contract Community (@"lookup", return) = {
for ( @map <- commMap ) {
//stdout!(map) |
commMap!(map) |
return!(map)
}
} |
Community!("new","test", Nil, *ret) |
Community!("new","test2", Nil, *ret) |
for ( @{"admin": admin, "read": read, "write": write, "grant": grant} <- ret; _ <- ret ) {
stdout!("got em") |
Community!("lookup","test",*stdout) |
Community!("lookup","test2",*stdout) |
Community!("lookup",*stdout) |
//Community!("new","test", Nil, *stdout) |
admin|("add user","jim","xxxxx", *ret) |
for ( _ <- ret ) {
Community!("lookup","test",*stdout) |
Community!("lookup","test2",*stdout)
}
}
}