Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

refactor transports to be fully featured #29

Merged
merged 5 commits into from
Jun 6, 2018
Merged

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented Mar 9, 2018

DO NOT MERGE (yet)
Part of: libp2p/go-libp2p#297

@ghost ghost assigned Stebalien Mar 9, 2018
@ghost ghost added the in progress label Mar 9, 2018
@@ -1,53 +0,0 @@
package transport
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed without replacement (the libp2p constructor will add-in the tcp transport by default if no other transports are specified.

transport.go Outdated
Protocols() []int

// Proxy returns true if this transport proxies.
// TODO: Make this a part of the go-multiaddr protocol instead?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to leave this here for now but we may want to move it later. Proxy transports are transports like p2p-circuit that handle part of the multiaddr and forward the rest to some other system.

@@ -50,9 +74,10 @@ type Listener interface {
Multiaddr() ma.Multiaddr
}

// DialOpt is an option used for configuring dialer behaviour
type DialOpt interface{}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All configuration options are passed to the transport on construction.

@@ -24,19 +40,27 @@ type Conn interface {
// but many more can be implemented, sctp, audio signals, sneakernet, UDT, a
// network of drones carrying usb flash drives, and so on.
type Transport interface {
Dialer(laddr ma.Multiaddr, opts ...DialOpt) (Dialer, error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer have "dialers". Instead, we just call Dial on the transport and the transport decides how to dial (e.g., which source address to use). In the past, we constructed one dialer per listen address and picked the dialer randomly. That was obviously not an optimal solution but the swarm just didn't have enough information to make an informed decision (without special-casing transports). On the other hand, the transport does have enough information.

Dialer(laddr ma.Multiaddr, opts ...DialOpt) (Dialer, error)
// Dial dials a remote peer. It should try to reuse local listener
// addresses if possible but it may choose not to.
Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (Conn, error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we're breaking things, I got rid of the distinction between Dial and DialContext. Just pass a context.

Also, this now takes a peer ID. While we can technically get away with not having this, it allows us to validate connections early (given that transport security now happens inside the transport).

README.md Outdated
@@ -21,26 +21,6 @@ This is the 'base' layer for any transport that wants to be used by libp2p and i
> gx-go rewrite
```

## Usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new usage text? @Stebalien tsk tsk tsk

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One generally doesn't use transports directly like this. One implements them.

... fine. I'll add an example.

Copy link
Contributor

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, doing away with the fallback dialer seems okay.

@Stebalien
Copy link
Member Author

Stebalien commented Mar 11, 2018

edit: punt, see #30


So, during the refactor, I inverted the transport/net dependency. That is, instead of go-libp2p-net depending on go-libp2p-transport, go-libp2p-transport now depends on go-libp2p-net. My reasoning was that transports are one way to implement a libp2p networks. That's why this package has a transport.Network interface that extends inet.Network.

However, go-libp2p-net contains the Network interface which, unfortunately, depends on the peerstore. Given that all transports will depend on go-libp2p-transport, this is a bit unfortunate.

One solution is to:

  1. Move inet.ConnMultiaddrs to go-multiaddr-net. Really, that's where it belongs (and then maddr.Conn would simply be a composition of net.Conn and this interface).
  2. Move inet.ConnSecurity somewhere... Honestly, I don't know where it belongs. Maybe go-libp2p-peer or a new go-libp2p-peer-net package? We don't really need this mixin but it's nice to have.
  3. Make a new go-libp2p-transport-net package and move the transport.Network interface there.

Personally, I'm inclined to finish this refactor and punt on this. Unlike the current refactor, moving these interfaces around won't be a major operation.

You don't really *use* this package in that way.
* explain that transports are fully-featured.
* note how to use them (and link to the upgrader package).
…listening

The one for listening is the reverse of the one for dialing.
@Stebalien Stebalien merged commit e4d6a1a into master Jun 6, 2018
@ghost ghost removed the in progress label Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants