Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement disconnect and fixes for Gambit-v4.9.1. breakage #3

Merged
merged 5 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ Identifies the daemon.

Ensures there is a connection open to `peer`.

#### libp2p-disconnect
```
(libp2p-disconnect c peer)
c := client
peer := ID
```

Closes any open connections to `peer`.

#### libp2p-stream
```
(libp2p-stream c peer protos)
Expand Down
7 changes: 6 additions & 1 deletion example/libp2p-chat.ss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
;;; libp2p chat example

(import :gerbil/gambit/threads
:gerbil/gambit/ports
:std/getopt
:std/sugar
:std/iter
Expand Down Expand Up @@ -48,7 +49,11 @@
((string-empty? line)
(lp))
(else
(displayln "\x1b[32m" line "\x1b[0m")
(write-u8 #x1b)
(display "[32m")
(display line)
(write-u8 #x1b)
(displayln "[0m")
(display "> ")
(lp))))))

Expand Down
1 change: 1 addition & 0 deletions libp2p.ss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
open-libp2p-client
libp2p-identify
libp2p-connect
libp2p-disconnect
libp2p-stream
libp2p-listen
libp2p-close
Expand Down
8 changes: 8 additions & 0 deletions libp2p/client.ss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@
addrs: (map multiaddr-bytes (peer-info-addrs pinfo)))))
(control-request c req void)))

(def (libp2p-disconnect c p)
(let (req
(Request
type: 'DISCONNECT
disconnect: (DisconnectRequest
peer: (ID-bytes p))))
(control-request c req void)))

(def (libp2p-stream c peer protos (bufsz 4096))
(let* ((id (if (ID? peer) peer (peer-info-id peer)))
(s (open-stream c bufsz))
Expand Down
12 changes: 9 additions & 3 deletions libp2p/pb/p2pd.ss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message Request {
DHT = 4;
LIST_PEERS = 5;
CONNMANAGER = 6;
DISCONNECT = 7;
}

required Type type = 1;
Expand All @@ -22,6 +23,7 @@ message Request {
optional StreamHandlerRequest streamHandler = 4;
optional DHTRequest dht = 5;
optional ConnManagerRequest connManager = 6;
optional DisconnectRequest disconnect = 7;
}

message Response {
Expand Down Expand Up @@ -109,9 +111,9 @@ message PeerInfo {

message ConnManagerRequest {
enum Type {
TAG_PEER = 0;
UNTAG_PEER = 1;
TRIM = 2;
TAG_PEER = 0;
UNTAG_PEER = 1;
TRIM = 2;
}

required Type type = 1;
Expand All @@ -120,3 +122,7 @@ message ConnManagerRequest {
optional string tag = 3;
optional int64 weight = 4;
}

message DisconnectRequest {
required bytes peer = 1;
}