-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.ss
47 lines (36 loc) · 987 Bytes
/
interface.ss
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
;;; -*- Gerbil -*-
;;; libp2p host interface
(import :std/io/interface
:std/misc/timeout)
(export #t)
(defstruct PeerID ())
(defstruct MultiAddr ())
(defstruct AddrInfo ())
(interface (Stream Closer)
(protocol) => :string
(reader) => Reader
(writer) => Writer
;; abruptly close/abort the stream
(reset!) => :void
;; input timeout
(set-input-timeout! (timeo :~ (maybe timeout?)))
=> :void
;; output timeout
(set-output-timeout! (timeo :~ (maybe timeout? )))
=> :void)
(interface (Host Closer)
(ID) => PeerID
;; => [MultiAddr]
(addrs) => :list
(connect! (addrs : AddrInfo) => :void)
(open-stream (p : PeerID)
(protos :~ protocol-or-list?))
=> Stream
;; handler: lambda (Stream)
(set-protocol-handler! (proto-or-list :~ protocol-or-list? )
(handler : :procedure))
=> :void)
(defrule (protocol-or-list? obj)
(or (string? obj)
(and (list? obj)
(andmap string? obj))))