@@ -6,31 +6,30 @@ import (
6
6
"strings"
7
7
"sync"
8
8
9
+ "github.com/libp2p/go-libp2p-core/peer"
10
+ "github.com/libp2p/go-libp2p-core/routing"
11
+
9
12
cid "github.com/ipfs/go-cid"
10
- peer "github.com/libp2p/go-libp2p-peer"
11
- pstore "github.com/libp2p/go-libp2p-peerstore"
12
- routing "github.com/libp2p/go-libp2p-routing"
13
- ropts "github.com/libp2p/go-libp2p-routing/options"
14
13
)
15
14
16
15
type failValueStore struct {}
17
16
18
17
var failValueErr = errors .New ("fail valuestore error" )
19
18
20
- func (f failValueStore ) PutValue (ctx context.Context , key string , value []byte , opts ... ropts .Option ) error {
19
+ func (f failValueStore ) PutValue (ctx context.Context , key string , value []byte , opts ... routing .Option ) error {
21
20
return failValueErr
22
21
}
23
- func (f failValueStore ) GetValue (ctx context.Context , key string , opts ... ropts .Option ) ([]byte , error ) {
22
+ func (f failValueStore ) GetValue (ctx context.Context , key string , opts ... routing .Option ) ([]byte , error ) {
24
23
return nil , failValueErr
25
24
}
26
25
27
- func (f failValueStore ) SearchValue (ctx context.Context , key string , opts ... ropts .Option ) (<- chan []byte , error ) {
26
+ func (f failValueStore ) SearchValue (ctx context.Context , key string , opts ... routing .Option ) (<- chan []byte , error ) {
28
27
return nil , failValueErr
29
28
}
30
29
31
30
type dummyValueStore sync.Map
32
31
33
- func (d * dummyValueStore ) PutValue (ctx context.Context , key string , value []byte , opts ... ropts .Option ) error {
32
+ func (d * dummyValueStore ) PutValue (ctx context.Context , key string , value []byte , opts ... routing .Option ) error {
34
33
if strings .HasPrefix (key , "/notsupported/" ) {
35
34
return routing .ErrNotSupported
36
35
}
@@ -45,7 +44,7 @@ func (d *dummyValueStore) PutValue(ctx context.Context, key string, value []byte
45
44
return nil
46
45
}
47
46
48
- func (d * dummyValueStore ) GetValue (ctx context.Context , key string , opts ... ropts .Option ) ([]byte , error ) {
47
+ func (d * dummyValueStore ) GetValue (ctx context.Context , key string , opts ... routing .Option ) ([]byte , error ) {
49
48
if strings .HasPrefix (key , "/error/" ) {
50
49
return nil , errors .New (key [len ("/error/" ):])
51
50
}
@@ -59,7 +58,7 @@ func (d *dummyValueStore) GetValue(ctx context.Context, key string, opts ...ropt
59
58
return nil , routing .ErrNotFound
60
59
}
61
60
62
- func (d * dummyValueStore ) SearchValue (ctx context.Context , key string , opts ... ropts .Option ) (<- chan []byte , error ) {
61
+ func (d * dummyValueStore ) SearchValue (ctx context.Context , key string , opts ... routing .Option ) (<- chan []byte , error ) {
63
62
out := make (chan []byte )
64
63
if strings .HasPrefix (key , "/error/" ) {
65
64
return nil , errors .New (key [len ("/error/" ):])
@@ -80,12 +79,12 @@ func (d *dummyValueStore) SearchValue(ctx context.Context, key string, opts ...r
80
79
81
80
type dummyProvider map [string ][]peer.ID
82
81
83
- func (d dummyProvider ) FindProvidersAsync (ctx context.Context , c cid.Cid , count int ) <- chan pstore. PeerInfo {
82
+ func (d dummyProvider ) FindProvidersAsync (ctx context.Context , c cid.Cid , count int ) <- chan peer. AddrInfo {
84
83
peers := d [c .KeyString ()]
85
84
if len (peers ) > count {
86
85
peers = peers [:count ]
87
86
}
88
- out := make (chan pstore. PeerInfo )
87
+ out := make (chan peer. AddrInfo )
89
88
go func () {
90
89
defer close (out )
91
90
for _ , p := range peers {
@@ -94,7 +93,7 @@ func (d dummyProvider) FindProvidersAsync(ctx context.Context, c cid.Cid, count
94
93
return
95
94
}
96
95
select {
97
- case out <- pstore. PeerInfo {ID : p }:
96
+ case out <- peer. AddrInfo {ID : p }:
98
97
case <- ctx .Done ():
99
98
}
100
99
}
@@ -112,17 +111,17 @@ func (d cbProvider) Provide(ctx context.Context, c cid.Cid, local bool) error {
112
111
return d (c , local )
113
112
}
114
113
115
- func (d cbProvider ) FindProvidersAsync (ctx context.Context , c cid.Cid , count int ) <- chan pstore. PeerInfo {
116
- ch := make (chan pstore. PeerInfo )
114
+ func (d cbProvider ) FindProvidersAsync (ctx context.Context , c cid.Cid , count int ) <- chan peer. AddrInfo {
115
+ ch := make (chan peer. AddrInfo )
117
116
close (ch )
118
117
return ch
119
118
}
120
119
121
120
type dummyPeerRouter map [peer.ID ]struct {}
122
121
123
- func (d dummyPeerRouter ) FindPeer (ctx context.Context , p peer.ID ) (pstore. PeerInfo , error ) {
122
+ func (d dummyPeerRouter ) FindPeer (ctx context.Context , p peer.ID ) (peer. AddrInfo , error ) {
124
123
if _ , ok := d [p ]; ok {
125
- return pstore. PeerInfo {ID : p }, nil
124
+ return peer. AddrInfo {ID : p }, nil
126
125
}
127
- return pstore. PeerInfo {}, routing .ErrNotFound
126
+ return peer. AddrInfo {}, routing .ErrNotFound
128
127
}
0 commit comments