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

Commit

Permalink
use the transport.Upgrader interface
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jan 4, 2022
1 parent 870aa2c commit 17e9790
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 55 deletions.
4 changes: 3 additions & 1 deletion dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/libp2p/go-libp2p-core/network"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/transport"
ma "github.com/multiformats/go-multiaddr"
Expand All @@ -15,7 +17,7 @@ func (d *RelayTransport) Dial(ctx context.Context, a ma.Multiaddr, p peer.ID) (t
return nil, err
}
c.tagHop()
return d.upgrader.UpgradeOutbound(ctx, d, c, p)
return d.upgrader.Upgrade(ctx, d, c, network.DirOutbound, p)
}

func (r *Relay) Dial(ctx context.Context, a ma.Multiaddr, p peer.ID) (*Conn, error) {
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ require (
github.com/ipfs/go-log v1.0.5
github.com/libp2p/go-buffer-pool v0.0.2
github.com/libp2p/go-libp2p-blankhost v0.2.0
github.com/libp2p/go-libp2p-core v0.10.0
github.com/libp2p/go-libp2p-swarm v0.6.0
github.com/libp2p/go-libp2p-transport-upgrader v0.5.0
github.com/libp2p/go-libp2p-core v0.13.1-0.20220104083644-a3dd401efe36
github.com/libp2p/go-libp2p-swarm v0.9.1-0.20220104091227-f776b7e504b1
github.com/libp2p/go-msgio v0.0.6
github.com/multiformats/go-multiaddr v0.3.3
github.com/multiformats/go-multiaddr v0.5.0
github.com/multiformats/go-varint v0.0.6
)
71 changes: 32 additions & 39 deletions go.sum

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"

pool "github.com/libp2p/go-buffer-pool"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
"github.com/libp2p/go-libp2p-core/transport"

logging "github.com/ipfs/go-log"
pool "github.com/libp2p/go-buffer-pool"
ma "github.com/multiformats/go-multiaddr"
)

Expand All @@ -42,7 +41,7 @@ var (
// Relay is the relay transport and service.
type Relay struct {
host host.Host
upgrader *tptu.Upgrader
upgrader transport.Upgrader
ctx context.Context
ctxCancel context.CancelFunc
self peer.ID
Expand Down Expand Up @@ -94,7 +93,7 @@ func (e RelayError) Error() string {
}

// NewRelay constructs a new relay.
func NewRelay(h host.Host, upgrader *tptu.Upgrader, opts ...RelayOpt) (*Relay, error) {
func NewRelay(h host.Host, upgrader transport.Upgrader, opts ...RelayOpt) (*Relay, error) {
r := &Relay{
upgrader: upgrader,
host: h,
Expand Down
2 changes: 1 addition & 1 deletion relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getNetHosts(t *testing.T, n int) []host.Host {
}

func newTestRelay(t *testing.T, host host.Host, opts ...RelayOpt) *Relay {
r, err := NewRelay(host, swarmt.GenUpgrader(host.Network().(*swarm.Swarm)), opts...)
r, err := NewRelay(host, swarmt.GenUpgrader(t, host.Network().(*swarm.Swarm)), opts...)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/transport"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
ma "github.com/multiformats/go-multiaddr"
)

Expand Down Expand Up @@ -52,7 +51,7 @@ func (r *RelayTransport) Close() error {
}

// AddRelayTransport constructs a relay and adds it as a transport to the host network.
func AddRelayTransport(h host.Host, upgrader *tptu.Upgrader, opts ...RelayOpt) error {
func AddRelayTransport(h host.Host, upgrader transport.Upgrader, opts ...RelayOpt) error {
n, ok := h.Network().(transport.TransportNetwork)
if !ok {
return fmt.Errorf("%v is not a transport network", h.Network())
Expand Down
6 changes: 3 additions & 3 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ var msg = []byte("relay works!")
func testSetupRelay(t *testing.T) []host.Host {
hosts := getNetHosts(t, 3)

err := AddRelayTransport(hosts[0], swarmt.GenUpgrader(hosts[0].Network().(*swarm.Swarm)))
err := AddRelayTransport(hosts[0], swarmt.GenUpgrader(t, hosts[0].Network().(*swarm.Swarm)))
if err != nil {
t.Fatal(err)
}

err = AddRelayTransport(hosts[1], swarmt.GenUpgrader(hosts[1].Network().(*swarm.Swarm)), OptHop)
err = AddRelayTransport(hosts[1], swarmt.GenUpgrader(t, hosts[1].Network().(*swarm.Swarm)), OptHop)
if err != nil {
t.Fatal(err)
}

err = AddRelayTransport(hosts[2], swarmt.GenUpgrader(hosts[2].Network().(*swarm.Swarm)))
err = AddRelayTransport(hosts[2], swarmt.GenUpgrader(t, hosts[2].Network().(*swarm.Swarm)))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 17e9790

Please sign in to comment.