Skip to content

Commit

Permalink
migrate to consolidated types. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk authored May 26, 2019
1 parent 09f1d4e commit 9ad01ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
21 changes: 11 additions & 10 deletions p2p/host/autonat/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"sync"
"time"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/helpers"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"

pb "github.com/libp2p/go-libp2p-autonat/pb"

ggio "github.com/gogo/protobuf/io"
libp2p "github.com/libp2p/go-libp2p"
autonat "github.com/libp2p/go-libp2p-autonat"
host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
)
Expand Down Expand Up @@ -57,13 +58,13 @@ func NewAutoNATService(ctx context.Context, h host.Host, opts ...libp2p.Option)
return as, nil
}

func (as *AutoNATService) handleStream(s inet.Stream) {
defer inet.FullClose(s)
func (as *AutoNATService) handleStream(s network.Stream) {
defer helpers.FullClose(s)

pid := s.Conn().RemotePeer()
log.Debugf("New stream from %s", pid.Pretty())

r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
r := ggio.NewDelimitedReader(s, network.MessageSizeMax)
w := ggio.NewDelimitedWriter(s)

var req pb.Message
Expand Down Expand Up @@ -146,7 +147,7 @@ func (as *AutoNATService) handleDial(p peer.ID, obsaddr ma.Multiaddr, mpi *pb.Me
return newDialResponseError(pb.Message_E_DIAL_ERROR, "no dialable addresses")
}

return as.doDial(pstore.PeerInfo{ID: p, Addrs: addrs})
return as.doDial(peer.AddrInfo{ID: p, Addrs: addrs})
}

func (as *AutoNATService) skipDial(addr ma.Multiaddr) bool {
Expand All @@ -164,7 +165,7 @@ func (as *AutoNATService) skipDial(addr ma.Multiaddr) bool {
return false
}

func (as *AutoNATService) doDial(pi pstore.PeerInfo) *pb.Message_DialResponse {
func (as *AutoNATService) doDial(pi peer.AddrInfo) *pb.Message_DialResponse {
// rate limit check
as.mx.Lock()
count := as.reqs[pi.ID]
Expand Down
11 changes: 6 additions & 5 deletions p2p/host/autonat/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"testing"
"time"

libp2p "github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"

autonat "github.com/libp2p/go-libp2p-autonat"
host "github.com/libp2p/go-libp2p-host"
pstore "github.com/libp2p/go-libp2p-peerstore"
manet "github.com/multiformats/go-multiaddr-net"
)

Expand Down Expand Up @@ -38,14 +39,14 @@ func makeAutoNATClient(ctx context.Context, t *testing.T) (host.Host, autonat.Au
}

func connect(t *testing.T, a, b host.Host) {
pinfo := pstore.PeerInfo{ID: a.ID(), Addrs: a.Addrs()}
pinfo := peer.AddrInfo{ID: a.ID(), Addrs: a.Addrs()}
err := b.Connect(context.Background(), pinfo)
if err != nil {
t.Fatal(err)
}
}

// Note: these tests assume that the host has only private inet addresses!
// Note: these tests assume that the host has only private network addresses!
func TestAutoNATServiceDialError(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit 9ad01ee

Please sign in to comment.