-
Notifications
You must be signed in to change notification settings - Fork 0
/
sn-ffi.tpl.red
225 lines (185 loc) · 3.81 KB
/
sn-ffi.tpl.red
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
Red [
comment {bg:TPL_COMMENT [TEMPLATE_FILE: "sn-ffi.tpl.red"]} "This file is generated by %bindgen.red from %sn-ffi.tpl.red" comment {bg-end:TPL_COMMENT}
]
#system [
#import [
"sn_ffi/target/i686-unknown-linux-gnu/debug/libsn_ffi.so" cdecl [
comment {bg:OBJ [
NAME: "s-afe"
]}
comment {bg:s-afe_OBJ_DEFAULT []}
c_s-afe_default: "s-afe_default" [
return: [handle!]
]
c_s-afe_free: "s-afe_free" [
ref [handle!]
]
comment {bg-end:s-afe_OBJ_DEFAULT}
comment {bg:s-afe_FIELD_STRING [
FIELDNAME: "xorurl_base"
FIELDNAME_DASH: "xorurl-base"
]}
c_s-afe_xorurl_base: "s-afe_xorurl_base" [
ref [handle!]
return: [c-string!]
]
comment {bg-end:s-afe_FIELD_STRING}
comment {bg:s-afe_METHOD [
METHODNAME: "c-onnect"
]}
c_s-afe_c-onnect: "_s-afe_c-onnect" [
rt [handle!]
ref [handle!]
params [byte-ptr!]
params_size [integer!]
]
comment {bg-end:s-afe_METHOD}
comment {bg-end:OBJ}
init_runtime: "init_runtime" [
return: [handle!]
]
cstring_free: "cstring_free" [
ptr [c-string!]
]
]
]
tokio_runtime: init_runtime
]
; low-level routines
comment {bg:OBJ [
NAME: "s-afe"
]}
comment {bg:s-afe_OBJ_DEFAULT []}
s-afe_default: routine [
return: [handle!]
/local ref
] [
ref: handle/box as integer! c_s-afe_default
as red-handle! SET_RETURN(ref)
]
s-afe_free: routine [
ref [handle!]
] [
c_s-afe_free as handle! ref/value
]
comment {bg-end:s-afe_OBJ_DEFAULT}
comment {bg:s-afe_FIELD_STRING [
FIELDNAME: "xorurl_base"
FIELDNAME_DASH: "xorurl-base"
]}
s-afe_xorurl_base: routine [
ref [handle!]
return: [string!]
/local str buffer size
] [
str: c_s-afe_xorurl_base as handle! ref/value
size: length? str
buffer: string/load str size UTF-8
cstring_free str
as red-string! SET_RETURN(buffer)
]
comment {bg-end:s-afe_FIELD_STRING}
comment {bg:s-afe_METHOD [
METHODNAME: "c-onnect"
]}
s-afe_c-onnect: function [
ref [handle!]
comment {bg:s-afe_c-onnect_PARAM [
PARAMNAME: "app-keypair"
PARAMTYPE: "Option<Keypair>"
]}app-keypair ;; in rust: Option<Keypair>
comment {bg-end:s-afe_c-onnect_PARAM}
] [
params: to binary! ""
save/as
params
reduce [comment {bg:s-afe_c-onnect_PARAM [PARAMNAME: "app-keypair"]} app-keypair comment {bg-end:s-afe_c-onnect_PARAM}]
'redbin
probe length? params
r_s-afe_c-onnect
ref
probe params
]
r_s-afe_c-onnect: routine [
ref [handle!]
params [binary!]
] [
c_s-afe_c-onnect
tokio_runtime
as handle! ref/value
binary/rs-head params
binary/rs-length? params
]
comment {bg-end:s-afe_METHOD}
comment {bg-end:OBJ}
; hi-level code
bls-key: function [
key-bin [binary!]
return: [block!]
] [
key: copy []
foreach b key-bin [
append key b
]
reduce [key]
]
comment {bg:OBJ [
NAME: "s-afe"
]}
s-afe!: object [
ref: none
comment {bg:s-afe_OBJ_DEFAULT []}
init: does [
ref: s-afe_default
]
free: does [
s-afe_free ref
ref: none
]
comment {bg-end:s-afe_OBJ_DEFAULT}
comment {bg:s-afe_FIELD_STRING [
FIELDNAME: "xorurl_base"
FIELDNAME_DASH: "xorurl-base"
]}
xorurl-base: does [
s-afe_xorurl_base ref
]
comment {bg-end:s-afe_FIELD_STRING}
]
comment {bg-end:OBJ}
safe!: make safe! [
init: does [
; ref: safe_default
ref: none
]
free: does [
; safe_free ref
ref: none
]
connect: function [
ip [tuple!]
port [integer!]
] [
genesis-key: bls-key #{
8640 e62c c44e 75cf
4fad c8ee 91b7 4b4c
f0fd 2c09 84fb 0e3a
b40f 0268 0685 7d8c
41f0 1d37 2522 3c55
b1ef 87d6 69f5 e2cc
}
safe_connect
ref
compose/deep [ ;bootstrap_config
(genesis-key)
[
(rejoin [ip #":" port])
(rejoin [ip #":" port + 1]) ;-- NODES_TO_CONTACT_PER_STARTUP_BATCH = 3 @ safe_network/src/client/connections/messaging.rs
(rejoin [ip #":" port + 2])
]
]
none ;keypair
none ;config_path
["secs" 10 "nanos" 0] ;timeout
]
]