-
Notifications
You must be signed in to change notification settings - Fork 46
Conversation
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
With the change over to async/await something that may be valuable to look at adding to It also makes it much easier to properly close outbound dials when shutting a node down. |
Good idea @jacobheun 👍 |
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
After some thinking, abort controller support was actually super easy to add using Should be good for review. |
Async await changes merged but not released :( License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
interface-transport now has a few extra tests for cancelling dials, which require a new |
src/adapter.js
Outdated
@@ -0,0 +1,81 @@ | |||
'use strict' | |||
|
|||
const { Connection } = require('interface-connection') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do the async/await update to interface-connection
for this? It should be a pretty quick change and will prevent us from needing to come back and update this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dirkmc do you want to send a PR for this?
cc @vasco-santos (I know you were thinking of working on it this week)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what fields / methods should be required on the interface, I opened an issue to discuss: libp2p/interface-connection#28
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
This PR would also get us of |
"aegir": "^18.2.1", | ||
"chai": "^4.2.0", | ||
"dirty-chai": "^2.0.1", | ||
"interface-transport": "~0.3.7", | ||
"interface-transport": "github:libp2p/interface-transport#master", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If #master, why not released? //cc @jacobheun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's wrong, this is outdated. We're tackling tcp first and then will circle back to this and the other transports.
Superseded by #92 |
BREAKING CHANGE: Switch to using async/await and async iterators. The transport and connection interfaces have changed.
Dials are now abortable! Pass an
AbortSignal
assignal
to the options to abort the connection whenever you like!For example, abort during dial:
For example, abort after dial:
Note: there is an adapter class that allows use of the new API via the old one, usage:
const Websockets = require('libp2p-websockets/src/adapter')
Interface Transport
dial(ma<Multiaddr>, [options<Object>]): Promise<Connection>
Dial to a peer at the given multiaddr, returns a promise that is resolved when the connection has opened. Throws if connection error or any other error opening the connection, including if the connection is aborted.
The promise resolves to a
Connection
(which is a duplex object) that can be used to communicate with the peer.Options
signal
- anAbortSignal
that can be used to abort the dial. You can obtain one from anAbortController
createListener([options<Object>], [handler<Function<Connection>>]): Listener
Create a new listener, where incoming connections are handled by
handler
. The handler function is called for each new incoming connection. It is passed aConnection
(which is a duplex object). Note the handler param is optional and can be registered later by listening for the 'connected' event.filter(mas<Multiaddr[]>): Multiaddr[]
Filter the multiaddrs this transport can dial.
Events
listening
After the listener has started listening.
connected
For every new connection. The event handler is passed a
Connection
(which is a duplex object).close
After the listener has stopped listening.
Interface Listener
listen(): Promise
getAddrs(): Promise<Multiaddr[]>
Interface Connection
sink<Function>
https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#sink-it
source<Iterable>
https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#source-it
getObservedAddrs(): Promise<Multiaddr[]>
close(): Promise
test/adapter/compliance/*
are just a copy of the oldinterface-transport
tests