Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

Commit faf0508

Browse files
authored
use migrated types; drop import prefixes. (#22)
1 parent 4808c1f commit faf0508

File tree

3 files changed

+29
-103
lines changed

3 files changed

+29
-103
lines changed

blank.go

+27-24
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import (
44
"context"
55
"io"
66

7+
"github.com/libp2p/go-libp2p-core/connmgr"
8+
"github.com/libp2p/go-libp2p-core/host"
9+
"github.com/libp2p/go-libp2p-core/network"
10+
"github.com/libp2p/go-libp2p-core/peer"
11+
"github.com/libp2p/go-libp2p-core/peerstore"
12+
"github.com/libp2p/go-libp2p-core/protocol"
13+
714
logging "github.com/ipfs/go-log"
8-
core "github.com/libp2p/go-libp2p-core"
9-
connmgr "github.com/libp2p/go-libp2p-core/connmgr"
10-
network "github.com/libp2p/go-libp2p-core/network"
11-
pstore "github.com/libp2p/go-libp2p-core/peerstore"
12-
protocol "github.com/libp2p/go-libp2p-core/protocol"
15+
1316
ma "github.com/multiformats/go-multiaddr"
1417
mstream "github.com/multiformats/go-multistream"
1518
)
@@ -18,12 +21,12 @@ var log = logging.Logger("blankhost")
1821

1922
// BlankHost is the thinnest implementation of the host.Host interface
2023
type BlankHost struct {
21-
n core.Network
24+
n network.Network
2225
mux *mstream.MultistreamMuxer
2326
cmgr connmgr.ConnManager
2427
}
2528

26-
func NewBlankHost(n core.Network) *BlankHost {
29+
func NewBlankHost(n network.Network) *BlankHost {
2730
bh := &BlankHost{
2831
n: n,
2932
cmgr: &connmgr.NullConnMgr{},
@@ -34,7 +37,7 @@ func NewBlankHost(n core.Network) *BlankHost {
3437
return bh
3538
}
3639

37-
var _ core.Host = (*BlankHost)(nil)
40+
var _ host.Host = (*BlankHost)(nil)
3841

3942
func (bh *BlankHost) Addrs() []ma.Multiaddr {
4043
addrs, err := bh.n.InterfaceListenAddresses()
@@ -50,28 +53,28 @@ func (bh *BlankHost) Close() error {
5053
return bh.n.Close()
5154
}
5255

53-
func (bh *BlankHost) Connect(ctx context.Context, pi core.PeerAddrInfo) error {
56+
func (bh *BlankHost) Connect(ctx context.Context, ai peer.AddrInfo) error {
5457
// absorb addresses into peerstore
55-
bh.Peerstore().AddAddrs(pi.ID, pi.Addrs, pstore.TempAddrTTL)
58+
bh.Peerstore().AddAddrs(ai.ID, ai.Addrs, peerstore.TempAddrTTL)
5659

57-
cs := bh.n.ConnsToPeer(pi.ID)
60+
cs := bh.n.ConnsToPeer(ai.ID)
5861
if len(cs) > 0 {
5962
return nil
6063
}
6164

62-
_, err := bh.Network().DialPeer(ctx, pi.ID)
65+
_, err := bh.Network().DialPeer(ctx, ai.ID)
6366
return err
6467
}
6568

66-
func (bh *BlankHost) Peerstore() pstore.Peerstore {
69+
func (bh *BlankHost) Peerstore() peerstore.Peerstore {
6770
return bh.n.Peerstore()
6871
}
6972

70-
func (bh *BlankHost) ID() core.PeerID {
73+
func (bh *BlankHost) ID() peer.ID {
7174
return bh.n.LocalPeer()
7275
}
7376

74-
func (bh *BlankHost) NewStream(ctx context.Context, p core.PeerID, protos ...core.ProtocolID) (core.Stream, error) {
77+
func (bh *BlankHost) NewStream(ctx context.Context, p peer.ID, protos ...protocol.ID) (network.Stream, error) {
7578
s, err := bh.n.NewStream(ctx, p)
7679
if err != nil {
7780
return nil, err
@@ -95,32 +98,32 @@ func (bh *BlankHost) NewStream(ctx context.Context, p core.PeerID, protos ...cor
9598
return s, nil
9699
}
97100

98-
func (bh *BlankHost) RemoveStreamHandler(p core.ProtocolID) {
101+
func (bh *BlankHost) RemoveStreamHandler(p protocol.ID) {
99102
bh.Mux().RemoveHandler(string(p))
100103
}
101104

102-
func (bh *BlankHost) SetStreamHandler(pid core.ProtocolID, handler network.StreamHandler) {
105+
func (bh *BlankHost) SetStreamHandler(pid protocol.ID, handler network.StreamHandler) {
103106
bh.Mux().AddHandler(string(pid), func(p string, rwc io.ReadWriteCloser) error {
104-
is := rwc.(core.Stream)
107+
is := rwc.(network.Stream)
105108
is.SetProtocol(protocol.ID(p))
106109
handler(is)
107110
return nil
108111
})
109112
}
110113

111-
func (bh *BlankHost) SetStreamHandlerMatch(pid core.ProtocolID, m func(string) bool, handler network.StreamHandler) {
114+
func (bh *BlankHost) SetStreamHandlerMatch(pid protocol.ID, m func(string) bool, handler network.StreamHandler) {
112115
bh.Mux().AddHandlerWithFunc(string(pid), m, func(p string, rwc io.ReadWriteCloser) error {
113-
is := rwc.(core.Stream)
116+
is := rwc.(network.Stream)
114117
is.SetProtocol(protocol.ID(p))
115118
handler(is)
116119
return nil
117120
})
118121
}
119122

120-
// newStreamHandler is the remote-opened stream handler for core.Network
121-
func (h *BlankHost) newStreamHandler(s core.Stream) {
123+
// newStreamHandler is the remote-opened stream handler for network.Network
124+
func (bh *BlankHost) newStreamHandler(s network.Stream) {
122125

123-
protoID, handle, err := h.Mux().Negotiate(s)
126+
protoID, handle, err := bh.Mux().Negotiate(s)
124127
if err != nil {
125128
log.Warning("protocol mux failed: %s", err)
126129
s.Close()
@@ -138,7 +141,7 @@ func (bh *BlankHost) Mux() protocol.Switch {
138141
}
139142

140143
// TODO: also not sure this fits... Might be better ways around this (leaky abstractions)
141-
func (bh *BlankHost) Network() core.Network {
144+
func (bh *BlankHost) Network() network.Network {
142145
return bh.n
143146
}
144147

go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module github.com/libp2p/go-libp2p-blankhost
33
require (
44
github.com/ipfs/go-log v0.0.1
55
github.com/libp2p/go-libp2p-core v0.0.1
6-
github.com/libp2p/go-libp2p-peerstore v0.1.0
7-
github.com/libp2p/go-libp2p-protocol v0.1.0
8-
github.com/multiformats/go-multiaddr v0.0.4
6+
github.com/multiformats/go-multiaddr v0.0.2
97
github.com/multiformats/go-multistream v0.1.0
108
)

0 commit comments

Comments
 (0)