mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 12:20:03 +08:00
get bitswap working with dht
@perfmode using non-async version as apparently there's a bug in async. will look into it.
This commit is contained in:

committed by
Brian Tiger Chow

parent
8d29a3255f
commit
8112fae7b3
@ -2,6 +2,7 @@ package bitswap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||||
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
|
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
|
||||||
@ -65,12 +66,18 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
|
|||||||
// TODO add to wantlist
|
// TODO add to wantlist
|
||||||
promise := bs.notifications.Subscribe(ctx, k)
|
promise := bs.notifications.Subscribe(ctx, k)
|
||||||
|
|
||||||
|
// const maxProviders = 20
|
||||||
|
// using non-async version for now.
|
||||||
|
peersToQuery, err := bs.routing.FindProviders(ctx, k)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("No providers found for %d (%v)", k, err)
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
const maxProviders = 20
|
|
||||||
peersToQuery := bs.routing.FindProvidersAsync(ctx, k, maxProviders)
|
|
||||||
message := bsmsg.New()
|
message := bsmsg.New()
|
||||||
message.AppendWanted(k)
|
message.AppendWanted(k)
|
||||||
for iiiii := range peersToQuery {
|
for _, iiiii := range peersToQuery {
|
||||||
|
// u.DOut("bitswap got peersToQuery: %s\n", iiiii)
|
||||||
go func(p *peer.Peer) {
|
go func(p *peer.Peer) {
|
||||||
response, err := bs.sender.SendRequest(ctx, p, message)
|
response, err := bs.sender.SendRequest(ctx, p, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,9 +132,9 @@ func (bs *bitswap) ReceiveMessage(
|
|||||||
continue // FIXME(brian): err ignored
|
continue // FIXME(brian): err ignored
|
||||||
}
|
}
|
||||||
go bs.notifications.Publish(block)
|
go bs.notifications.Publish(block)
|
||||||
go func() {
|
go func(block blocks.Block) {
|
||||||
_ = bs.HasBlock(ctx, block) // FIXME err ignored
|
_ = bs.HasBlock(ctx, block) // FIXME err ignored
|
||||||
}()
|
}(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range incoming.Wantlist() {
|
for _, key := range incoming.Wantlist() {
|
||||||
|
@ -46,7 +46,11 @@ type NetMessageService interface {
|
|||||||
// TODO rename -> Router?
|
// TODO rename -> Router?
|
||||||
type Routing interface {
|
type Routing interface {
|
||||||
// FindProvidersAsync returns a channel of providers for the given key
|
// FindProvidersAsync returns a channel of providers for the given key
|
||||||
FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer
|
// FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer
|
||||||
|
// ^--- removed this for now because has some bugs apparently.
|
||||||
|
|
||||||
|
// FindProviders returns the providers for the given key
|
||||||
|
FindProviders(context.Context, u.Key) ([]*peer.Peer, error)
|
||||||
|
|
||||||
// Provide provides the key to the network
|
// Provide provides the key to the network
|
||||||
Provide(context.Context, u.Key) error
|
Provide(context.Context, u.Key) error
|
||||||
|
Reference in New Issue
Block a user