Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Adding transport.QListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Feb 29, 2020
1 parent 2d4fee4 commit b1a91b6
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions transport/transport.go
Expand Up @@ -73,11 +73,17 @@ type CapableConn interface {
//
// QCapableConn embed CapableConn but with `Quality() uint32` support.
type QCapableConn interface {
BaseCapableConn
ListenedQCapableConn

// Quality returns the Quality we can expect from the connection to this peer.
// That must be deterministic and fast.
Quality() uint32
}

// ListenedQCapableConn is like QCapableConn but is used by listener, quality is
// managed on client side.
type ListenedQCapableConn interface {
BaseCapableConn

// Transport returns the transport to which this connection belongs.
Transport() QTransport
Expand Down Expand Up @@ -124,6 +130,9 @@ type Transport interface {
// 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) (CapableConn, error)

// Listen listens on the passed multiaddr.
Listen(laddr ma.Multiaddr) (Listener, error)
}

type QTransport interface {
Expand All @@ -133,6 +142,9 @@ type QTransport interface {
// addresses if possible but it may choose not to.
Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (QCapableConn, error)

// Listen listens on the passed multiaddr.
Listen(laddr ma.Multiaddr) (QListener, error)

// Score returns the Quality we can expect from the connection to this peer.
// That must be deterministic and fast.
Score(raddr ma.Multiaddr, p peer.ID) (Score, error)
Expand All @@ -147,9 +159,6 @@ type BaseTransport interface {
// out addresses that we can't dial.
CanDial(addr ma.Multiaddr) bool

// Listen listens on the passed multiaddr.
Listen(laddr ma.Multiaddr) (Listener, error)

// Protocol returns the set of protocols handled by this transport.
//
// See the Network interface for an explanation of how this is used.
Expand All @@ -167,7 +176,20 @@ type BaseTransport interface {
// package, and also exposes a Multiaddr method as opposed to a regular Addr
// method
type Listener interface {
BaseListener

Accept() (CapableConn, error)
}

// QListener is like listener but produce QCapableConn instead of CapableConn.
type QListener interface {
BaseListener

Accept() (ListenedQCapableConn, error)
}

// BaseListener is used to build `Lister` and `QListener`
type BaseListener interface {
Close() error
Addr() net.Addr
Multiaddr() ma.Multiaddr
Expand Down

0 comments on commit b1a91b6

Please sign in to comment.