Skip to content

Commit

Permalink
fix(p2p): Update bootstrap nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton authored and 90dy committed Mar 8, 2019
1 parent 3a2fc5c commit f660cdc
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 18 deletions.
16 changes: 12 additions & 4 deletions core/network/config/config.go
Expand Up @@ -18,10 +18,18 @@ const DefaultSwarmKey = `/key/swarm/psk/1.0.0/
7beb018da4c79cb018e05305335d265046909f060c1b65e8eef94a107b9387cc`

var DefaultBootstrap = []string{
"/ip4/104.248.78.238/udp/4004/quic/ipfs/QmSMTqF5zUYQH8dmBrvbvVq2gqdnSnYdN6RN7unhfYndnU",
"/ip4/104.248.78.238/tcp/4004/ipfs/QmSMTqF5zUYQH8dmBrvbvVq2gqdnSnYdN6RN7unhfYndnU",
"/ip4/104.248.78.238/tcp/443/ipfs/QmSMTqF5zUYQH8dmBrvbvVq2gqdnSnYdN6RN7unhfYndnU",
"/ip4/104.248.78.238/tcp/80/ipfs/QmSMTqF5zUYQH8dmBrvbvVq2gqdnSnYdN6RN7unhfYndnU",
"/ip4/51.158.71.240/udp/4004/quic/ipfs/QmeYFvq4VV5RU1k1wBw3J5ZZLYxTE6H3AAKMzCAavuBjTp",
"/ip4/51.158.71.240/tcp/4004/ipfs/QmeYFvq4VV5RU1k1wBw3J5ZZLYxTE6H3AAKMzCAavuBjTp",
"/ip4/51.158.71.240/tcp/443/ipfs/QmeYFvq4VV5RU1k1wBw3J5ZZLYxTE6H3AAKMzCAavuBjTp",
"/ip4/51.158.71.240/tcp/80/ipfs/QmeYFvq4VV5RU1k1wBw3J5ZZLYxTE6H3AAKMzCAavuBjTp",
"/ip4/51.158.67.118/udp/4004/quic/ipfs/QmS88MDaMZUQeEvVdRAFmMfMz96b19Y79VJ6wQJnf4dwoo",
"/ip4/51.158.67.118/tcp/4004/ipfs/QmS88MDaMZUQeEvVdRAFmMfMz96b19Y79VJ6wQJnf4dwoo",
"/ip4/51.158.67.118/tcp/443/ipfs/QmS88MDaMZUQeEvVdRAFmMfMz96b19Y79VJ6wQJnf4dwoo",
"/ip4/51.158.67.118/tcp/80/ipfs/QmS88MDaMZUQeEvVdRAFmMfMz96b19Y79VJ6wQJnf4dwoo",
"/ip4/51.15.221.60/udp/4004/quic/ipfs/QmZP7oAGikmrMLAmf7ooNtnarYdDWki4Wru2sJ5H5kgCw3",
"/ip4/51.15.221.60/tcp/4004/ipfs/QmZP7oAGikmrMLAmf7ooNtnarYdDWki4Wru2sJ5H5kgCw3",
"/ip4/51.15.221.60/tcp/443/ipfs/QmZP7oAGikmrMLAmf7ooNtnarYdDWki4Wru2sJ5H5kgCw3",
"/ip4/51.15.221.60/tcp/80/ipfs/QmZP7oAGikmrMLAmf7ooNtnarYdDWki4Wru2sJ5H5kgCw3",
}

var BootstrapIpfs = []string{
Expand Down
80 changes: 66 additions & 14 deletions core/network/host/routing.go
Expand Up @@ -9,19 +9,21 @@ import (
cid "github.com/ipfs/go-cid"
datastore "github.com/ipfs/go-datastore"
syncdatastore "github.com/ipfs/go-datastore/sync"
log "github.com/ipfs/go-log"
host "github.com/libp2p/go-libp2p-host"
kaddht "github.com/libp2p/go-libp2p-kad-dht"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
routing "github.com/libp2p/go-libp2p-routing"
ropts "github.com/libp2p/go-libp2p-routing/options"
ma "github.com/multiformats/go-multiaddr"
"go.uber.org/zap"
)

var _ routing.IpfsRouting = (*BertyRouting)(nil)

type BertyRouting struct {
routing.IpfsRouting
dht *kaddht.IpfsDHT
muReady sync.RWMutex
cready chan struct{}
Expand All @@ -42,25 +44,70 @@ func NewBertyRouting(ctx context.Context, h host.Host, dhtSvc bool) (*BertyRouti
dht = kaddht.NewDHTClient(ctx, h, ds)
}

br := &BertyRouting{
dht: dht,
cready: make(chan struct{}, 1),
tstart: time.Now(),
}

// Bootstrap DHT
// Boostrap only return an error if a bad config is provided
// since Bootstrap use default config, it should never happened
if err := dht.Bootstrap(ctx); err != nil {
if err := dht.Close(); err != nil {
logger().Warn("dht bootstrap error", zap.Error(err))
}
if err := br.dht.Bootstrap(ctx); err != nil {
logger().Warn("dht bootstrap error", zap.Error(err))
}

h.Network().Notify(br)
return br, nil
}

func (br *BertyRouting) Bootstrap(ctx context.Context) error {
return br.dht.Bootstrap(ctx)
}

// PutValue adds value corresponding to given Key.
func (br *BertyRouting) PutValue(ctx context.Context, k string, data []byte, opts ...ropts.Option) error {
if err := br.isReady(ctx); err != nil {
return err
}

return br.dht.PutValue(ctx, k, data, opts...)
}

// GetValue searches for the value corresponding to given Key.
func (br *BertyRouting) GetValue(ctx context.Context, ns string, opts ...ropts.Option) ([]byte, error) {
if err := br.isReady(ctx); err != nil {
return nil, err
}

br := &BertyRouting{
IpfsRouting: dht,
dht: dht,
cready: make(chan struct{}, 1),
tstart: time.Now(),
return br.dht.GetValue(ctx, ns, opts...)
}

// SearchValue searches for better and better values from this value
// store corresponding to the given Key. By default implementations must
// stop the search after a good value is found. A 'good' value is a value
// that would be returned from GetValue.
//
// Useful when you want a result *now* but still want to hear about
// better/newer results.
//
// Implementations of this methods won't return ErrNotFound. When a value
// couldn't be found, the channel will get closed without passing any results
func (br *BertyRouting) SearchValue(ctx context.Context, ns string, opts ...ropts.Option) (<-chan []byte, error) {
if err := br.isReady(ctx); err != nil {
logger().Error("routing isn't ready", zap.Error(err))
}

h.Network().Notify(br)
return br, nil
return br.dht.SearchValue(ctx, ns, opts...)
}

func (br *BertyRouting) FindPeer(ctx context.Context, pid peer.ID) (pstore.PeerInfo, error) {
if err := br.isReady(ctx); err != nil {
return pstore.PeerInfo{}, nil
}

return br.dht.FindPeer(ctx, pid)

}

// Provide adds the given cid to the content routing system. If 'true' is
Expand All @@ -69,9 +116,10 @@ func NewBertyRouting(ctx context.Context, h host.Host, dhtSvc bool) (*BertyRouti
func (br *BertyRouting) Provide(ctx context.Context, id cid.Cid, brd bool) error {
if err := br.isReady(ctx); err != nil {
logger().Error("routing isn't ready", zap.Error(err))
return nil
}

return br.IpfsRouting.Provide(ctx, id, brd)
return br.dht.Provide(ctx, id, brd)
}

// Search for peers who are able to provide a given key
Expand All @@ -80,7 +128,7 @@ func (br *BertyRouting) FindProvidersAsync(ctx context.Context, id cid.Cid, n in
logger().Error("routing isn't ready", zap.Error(err))
}

return br.IpfsRouting.FindProvidersAsync(ctx, id, n)
return br.dht.FindProvidersAsync(ctx, id, n)
}

func (br *BertyRouting) isReady(ctx context.Context) error {
Expand Down Expand Up @@ -131,3 +179,7 @@ func (br *BertyRouting) Connected(net inet.Network, c inet.Conn) {
}

func (br *BertyRouting) Disconnected(s inet.Network, c inet.Conn) {}

func init() {
log.SetDebugLogging()
}

0 comments on commit f660cdc

Please sign in to comment.