dht.go 13.9 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2
package dht

3
import (
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
4
	"bytes"
5
	"crypto/rand"
6
	"errors"
7
	"fmt"
8 9
	"sync"
	"time"
10

11
	inet "github.com/jbenet/go-ipfs/net"
12
	msg "github.com/jbenet/go-ipfs/net/message"
13
	peer "github.com/jbenet/go-ipfs/peer"
Jeromy's avatar
Jeromy committed
14
	kb "github.com/jbenet/go-ipfs/routing/kbucket"
15
	u "github.com/jbenet/go-ipfs/util"
16

17
	context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
18
	ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
Jeromy's avatar
Jeromy committed
19

20
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
21 22
)

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
23
var log = u.Logger("dht")
24

25 26
const doPinging = true

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
27 28 29 30 31
// TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js

// IpfsDHT is an implementation of Kademlia with Coral and S/Kademlia modifications.
// It is used to implement the base IpfsRouting module.
type IpfsDHT struct {
32 33
	// Array of routing tables for differently distanced nodes
	// NOTE: (currently, only a single table is used)
34
	routingTables []*kb.RoutingTable
35

36
	// the network interface. service
37
	network inet.Network
38
	sender  inet.Sender
39

Jeromy's avatar
Jeromy committed
40
	// Local peer (yourself)
41
	self peer.Peer
Jeromy's avatar
Jeromy committed
42

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
43 44 45
	// Other peers
	peerstore peer.Peerstore

Jeromy's avatar
Jeromy committed
46 47
	// Local data
	datastore ds.Datastore
48
	dslock    sync.Mutex
49

50
	providers *ProviderManager
51

52 53
	// When this peer started up
	birth time.Time
54 55 56

	//lock to make diagnostics work better
	diaglock sync.Mutex
57 58

	ctx context.Context
59 60
}

Jeromy's avatar
Jeromy committed
61
// NewDHT creates a new DHT object with the given peer as the 'local' host
62
func NewDHT(ctx context.Context, p peer.Peer, ps peer.Peerstore, net inet.Network, sender inet.Sender, dstore ds.Datastore) *IpfsDHT {
63
	dht := new(IpfsDHT)
Jeromy's avatar
Jeromy committed
64
	dht.network = net
65
	dht.sender = sender
Jeromy's avatar
Jeromy committed
66
	dht.datastore = dstore
67
	dht.self = p
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
68
	dht.peerstore = ps
69
	dht.ctx = ctx
70

71
	dht.providers = NewProviderManager(p.ID())
72

73
	dht.routingTables = make([]*kb.RoutingTable, 3)
74 75 76
	dht.routingTables[0] = kb.NewRoutingTable(20, kb.ConvertPeerID(p.ID()), time.Millisecond*1000)
	dht.routingTables[1] = kb.NewRoutingTable(20, kb.ConvertPeerID(p.ID()), time.Millisecond*1000)
	dht.routingTables[2] = kb.NewRoutingTable(20, kb.ConvertPeerID(p.ID()), time.Hour)
77
	dht.birth = time.Now()
78

79 80 81
	if doPinging {
		go dht.PingRoutine(time.Second * 10)
	}
Jeromy's avatar
Jeromy committed
82
	return dht
83 84
}

85
// Connect to a new peer at the given address, ping and add to the routing table
86
func (dht *IpfsDHT) Connect(ctx context.Context, npeer peer.Peer) (peer.Peer, error) {
87
	log.Debug("Connect to new peer: %s", npeer)
88 89 90 91 92 93 94 95 96 97 98

	// TODO(jbenet,whyrusleeping)
	//
	// Connect should take in a Peer (with ID). In a sense, we shouldn't be
	// allowing connections to random multiaddrs without knowing who we're
	// speaking to (i.e. peer.ID). In terms of moving around simple addresses
	// -- instead of an (ID, Addr) pair -- we can use:
	//
	//   /ip4/10.20.30.40/tcp/1234/ipfs/Qxhxxchxzcncxnzcnxzcxzm
	//
	err := dht.network.DialPeer(npeer)
99
	if err != nil {
100
		return nil, err
101 102
	}

Jeromy's avatar
Jeromy committed
103 104
	// Ping new peer to register in their routing table
	// NOTE: this should be done better...
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
105
	err = dht.Ping(ctx, npeer)
Jeromy's avatar
Jeromy committed
106
	if err != nil {
107
		return nil, fmt.Errorf("failed to ping newly connected peer: %s\n", err)
Jeromy's avatar
Jeromy committed
108 109
	}

110 111
	dht.Update(npeer)

112
	return npeer, nil
Jeromy's avatar
Jeromy committed
113 114
}

115
// HandleMessage implements the inet.Handler interface.
116
func (dht *IpfsDHT) HandleMessage(ctx context.Context, mes msg.NetMessage) msg.NetMessage {
117 118 119

	mData := mes.Data()
	if mData == nil {
120
		log.Error("Message contained nil data.")
121
		return nil
122 123 124 125
	}

	mPeer := mes.Peer()
	if mPeer == nil {
126
		log.Error("Message contained nil peer.")
127
		return nil
128 129 130 131 132 133
	}

	// deserialize msg
	pmes := new(Message)
	err := proto.Unmarshal(mData, pmes)
	if err != nil {
134
		log.Error("Error unmarshaling data")
135
		return nil
136 137 138 139 140 141
	}

	// update the peer (on valid msgs only)
	dht.Update(mPeer)

	// Print out diagnostic
Jeromy's avatar
Jeromy committed
142
	log.Debug("[peer: %s] Got message type: '%s' [from = %s]\n",
143
		dht.self, Message_MessageType_name[int32(pmes.GetType())], mPeer)
144 145 146 147

	// get handler for this msg type.
	handler := dht.handlerForMsgType(pmes.GetType())
	if handler == nil {
148
		log.Error("got back nil handler from handlerForMsgType")
149
		return nil
150 151 152 153 154
	}

	// dispatch handler.
	rpmes, err := handler(mPeer, pmes)
	if err != nil {
155
		log.Error("handle message error: %s", err)
156
		return nil
157 158
	}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
159 160
	// if nil response, return it before serializing
	if rpmes == nil {
161
		log.Warning("Got back nil response from request.")
162
		return nil
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
163 164
	}

165 166 167
	// serialize response msg
	rmes, err := msg.FromObject(mPeer, rpmes)
	if err != nil {
168
		log.Error("serialze response error: %s", err)
169
		return nil
170 171
	}

172
	return rmes
173 174
}

175 176
// sendRequest sends out a request using dht.sender, but also makes sure to
// measure the RTT for latency measurements.
177
func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.Peer, pmes *Message) (*Message, error) {
178 179 180 181 182 183 184 185

	mes, err := msg.FromObject(p, pmes)
	if err != nil {
		return nil, err
	}

	start := time.Now()

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
186
	// Print out diagnostic
187
	log.Debug("Sent message type: '%s' [to = %s]",
188
		Message_MessageType_name[int32(pmes.GetType())], p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
189

190 191 192 193
	rmes, err := dht.sender.SendRequest(ctx, mes)
	if err != nil {
		return nil, err
	}
194 195 196
	if rmes == nil {
		return nil, errors.New("no response to request")
	}
197 198 199 200 201 202 203 204 205 206 207 208

	rtt := time.Since(start)
	rmes.Peer().SetLatency(rtt)

	rpmes := new(Message)
	if err := proto.Unmarshal(rmes.Data(), rpmes); err != nil {
		return nil, err
	}

	return rpmes, nil
}

209
// putValueToNetwork stores the given key/value pair at the peer 'p'
210
func (dht *IpfsDHT) putValueToNetwork(ctx context.Context, p peer.Peer,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
211 212
	key string, value []byte) error {

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
213 214
	pmes := newMessage(Message_PUT_VALUE, string(key), 0)
	pmes.Value = value
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
215
	rpmes, err := dht.sendRequest(ctx, p, pmes)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
216 217 218
	if err != nil {
		return err
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
219 220 221 222 223

	if !bytes.Equal(rpmes.Value, pmes.Value) {
		return errors.New("value not put correctly")
	}
	return nil
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
224 225
}

226
func (dht *IpfsDHT) putProvider(ctx context.Context, p peer.Peer, key string) error {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
227

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
228
	pmes := newMessage(Message_ADD_PROVIDER, string(key), 0)
229 230

	// add self as the provider
231
	pmes.ProviderPeers = peersToPBPeers([]peer.Peer{dht.self})
232

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
233
	rpmes, err := dht.sendRequest(ctx, p, pmes)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
234 235 236
	if err != nil {
		return err
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
237

238
	log.Debug("%s putProvider: %s for %s", dht.self, p, key)
239
	if rpmes.GetKey() != pmes.GetKey() {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
240 241 242 243
		return errors.New("provider not added correctly")
	}

	return nil
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
244 245
}

246 247
func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.Peer,
	key u.Key, level int) ([]byte, []peer.Peer, error) {
248 249

	pmes, err := dht.getValueSingle(ctx, p, key, level)
250
	if err != nil {
251
		return nil, nil, err
252 253
	}

Jeromy's avatar
Jeromy committed
254
	log.Debug("pmes.GetValue() %v", pmes.GetValue())
255
	if value := pmes.GetValue(); value != nil {
256
		// Success! We were given the value
Jeromy's avatar
Jeromy committed
257
		log.Debug("getValueOrPeers: got value")
258
		return value, nil, nil
259
	}
260

261
	// TODO decide on providers. This probably shouldn't be happening.
262 263 264 265 266
	if prv := pmes.GetProviderPeers(); prv != nil && len(prv) > 0 {
		val, err := dht.getFromPeerList(ctx, key, prv, level)
		if err != nil {
			return nil, nil, err
		}
Jeromy's avatar
Jeromy committed
267
		log.Debug("getValueOrPeers: get from providers")
268 269
		return val, nil, nil
	}
270 271

	// Perhaps we were given closer peers
272
	var peers []peer.Peer
273
	for _, pb := range pmes.GetCloserPeers() {
274
		pr, err := dht.peerFromInfo(pb)
275
		if err != nil {
276
			log.Error("%s", err)
277 278
			continue
		}
279
		peers = append(peers, pr)
280
	}
281 282

	if len(peers) > 0 {
283
		log.Debug("getValueOrPeers: peers")
284 285 286
		return nil, peers, nil
	}

Jeromy's avatar
Jeromy committed
287
	log.Warning("getValueOrPeers: u.ErrNotFound")
288
	return nil, nil, u.ErrNotFound
289 290
}

291
// getValueSingle simply performs the get value RPC with the given parameters
292
func (dht *IpfsDHT) getValueSingle(ctx context.Context, p peer.Peer,
293 294
	key u.Key, level int) (*Message, error) {

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
295
	pmes := newMessage(Message_GET_VALUE, string(key), level)
296
	return dht.sendRequest(ctx, p, pmes)
Jeromy's avatar
Jeromy committed
297 298
}

299 300 301 302
// TODO: Im not certain on this implementation, we get a list of peers/providers
// from someone what do we do with it? Connect to each of them? randomly pick
// one to get the value from? Or just connect to one at a time until we get a
// successful connection and request the value from it?
303 304
func (dht *IpfsDHT) getFromPeerList(ctx context.Context, key u.Key,
	peerlist []*Message_Peer, level int) ([]byte, error) {
305

306
	for _, pinfo := range peerlist {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
307
		p, err := dht.ensureConnectedToPeer(pinfo)
308
		if err != nil {
Jeromy's avatar
Jeromy committed
309
			log.Error("getFromPeers error: %s", err)
310
			continue
Jeromy's avatar
Jeromy committed
311
		}
312 313

		pmes, err := dht.getValueSingle(ctx, p, key, level)
Jeromy's avatar
Jeromy committed
314
		if err != nil {
Jeromy's avatar
Jeromy committed
315
			log.Error("getFromPeers error: %s\n", err)
Jeromy's avatar
Jeromy committed
316 317 318
			continue
		}

319 320 321 322
		if value := pmes.GetValue(); value != nil {
			// Success! We were given the value
			dht.providers.AddProvider(key, p)
			return value, nil
323
		}
Jeromy's avatar
Jeromy committed
324 325 326 327
	}
	return nil, u.ErrNotFound
}

328
// getLocal attempts to retrieve the value from the datastore
329
func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
330 331
	dht.dslock.Lock()
	defer dht.dslock.Unlock()
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
332
	v, err := dht.datastore.Get(key.DsKey())
333 334 335
	if err != nil {
		return nil, err
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
336 337 338

	byt, ok := v.([]byte)
	if !ok {
339
		return nil, errors.New("value stored in datastore not []byte")
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
340 341
	}
	return byt, nil
342 343
}

344
// putLocal stores the key value pair in the datastore
345
func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
346
	return dht.datastore.Put(key.DsKey(), value)
347
}
348

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
349 350
// Update signals to all routingTables to Update their last-seen status
// on the given peer.
351
func (dht *IpfsDHT) Update(p peer.Peer) {
352
	log.Debug("updating peer: %s latency = %f\n", p, p.GetLatency().Seconds())
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
353
	removedCount := 0
354
	for _, route := range dht.routingTables {
355
		removed := route.Update(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
356
		// Only close the connection if no tables refer to this peer
357
		if removed != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
358
			removedCount++
359
		}
360
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
361 362 363 364 365 366 367 368

	// Only close the connection if no tables refer to this peer
	// if removedCount == len(dht.routingTables) {
	// 	dht.network.ClosePeer(p)
	// }
	// ACTUALLY, no, let's not just close the connection. it may be connected
	// due to other things. it seems that we just need connection timeouts
	// after some deadline of inactivity.
369
}
Jeromy's avatar
Jeromy committed
370

Jeromy's avatar
Jeromy committed
371
// FindLocal looks for a peer with a given ID connected to this dht and returns the peer and the table it was found in.
372
func (dht *IpfsDHT) FindLocal(id peer.ID) (peer.Peer, *kb.RoutingTable) {
373
	for _, table := range dht.routingTables {
Jeromy's avatar
Jeromy committed
374 375 376 377 378 379 380
		p := table.Find(id)
		if p != nil {
			return p, table
		}
	}
	return nil, nil
}
381

382
func (dht *IpfsDHT) findPeerSingle(ctx context.Context, p peer.Peer, id peer.ID, level int) (*Message, error) {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
383 384
	pmes := newMessage(Message_FIND_NODE, string(id), level)
	return dht.sendRequest(ctx, p, pmes)
385
}
386

387 388
func (dht *IpfsDHT) printTables() {
	for _, route := range dht.routingTables {
389 390 391
		route.Print()
	}
}
Jeromy's avatar
Jeromy committed
392

393
func (dht *IpfsDHT) findProvidersSingle(ctx context.Context, p peer.Peer, key u.Key, level int) (*Message, error) {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
394 395
	pmes := newMessage(Message_GET_PROVIDERS, string(key), level)
	return dht.sendRequest(ctx, p, pmes)
Jeromy's avatar
Jeromy committed
396 397
}

398
// TODO: Could be done async
399 400
func (dht *IpfsDHT) addProviders(key u.Key, peers []*Message_Peer) []peer.Peer {
	var provArr []peer.Peer
Jeromy's avatar
Jeromy committed
401
	for _, prov := range peers {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
402 403
		p, err := dht.peerFromInfo(prov)
		if err != nil {
404
			log.Error("error getting peer from info: %v", err)
Jeromy's avatar
Jeromy committed
405 406
			continue
		}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
407

408
		log.Debug("%s adding provider: %s for %s", dht.self, p, key)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
409

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
410
		// Dont add outselves to the list
411
		if p.ID().Equal(dht.self.ID()) {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
412
			continue
Jeromy's avatar
Jeromy committed
413
		}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
414 415

		// TODO(jbenet) ensure providers is idempotent
416
		dht.providers.AddProvider(key, p)
417
		provArr = append(provArr, p)
Jeromy's avatar
Jeromy committed
418
	}
419
	return provArr
Jeromy's avatar
Jeromy committed
420
}
Jeromy's avatar
Jeromy committed
421

422
// nearestPeersToQuery returns the routing tables closest peers.
423
func (dht *IpfsDHT) nearestPeersToQuery(pmes *Message, count int) []peer.Peer {
424 425 426 427
	level := pmes.GetClusterLevel()
	cluster := dht.routingTables[level]

	key := u.Key(pmes.GetKey())
428
	closer := cluster.NearestPeers(kb.ConvertKey(key), count)
429 430 431
	return closer
}

432
// betterPeerToQuery returns nearestPeersToQuery, but iff closer than self.
433
func (dht *IpfsDHT) betterPeersToQuery(pmes *Message, count int) []peer.Peer {
434
	closer := dht.nearestPeersToQuery(pmes, count)
435 436 437 438 439 440

	// no node? nil
	if closer == nil {
		return nil
	}

441 442
	// == to self? thats bad
	for _, p := range closer {
443
		if p.ID().Equal(dht.self.ID()) {
444 445 446
			log.Error("Attempted to return self! this shouldnt happen...")
			return nil
		}
447 448
	}

449
	var filtered []peer.Peer
450 451 452
	for _, p := range closer {
		// must all be closer than self
		key := u.Key(pmes.GetKey())
453
		if !kb.Closer(dht.self.ID(), p.ID(), key) {
454 455
			filtered = append(filtered, p)
		}
456 457
	}

458 459
	// ok seems like closer nodes
	return filtered
460 461
}

462
func (dht *IpfsDHT) getPeer(id peer.ID) (peer.Peer, error) {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
463 464 465 466 467 468 469 470 471
	p, err := dht.peerstore.Get(id)
	if err != nil {
		err = fmt.Errorf("Failed to get peer from peerstore: %s", err)
		log.Error("%s", err)
		return nil, err
	}
	return p, nil
}

472
func (dht *IpfsDHT) peerFromInfo(pbp *Message_Peer) (peer.Peer, error) {
473 474

	id := peer.ID(pbp.GetId())
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
475

476 477
	// bail out if it's ourselves
	//TODO(jbenet) not sure this should be an error _here_
478
	if id.Equal(dht.self.ID()) {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
479 480 481
		return nil, errors.New("found self")
	}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
482 483 484
	p, err := dht.getPeer(id)
	if err != nil {
		return nil, err
485 486
	}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
487 488 489
	maddr, err := pbp.Address()
	if err != nil {
		return nil, err
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
490
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
491
	p.AddAddress(maddr)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
492 493 494
	return p, nil
}

495
func (dht *IpfsDHT) ensureConnectedToPeer(pbp *Message_Peer) (peer.Peer, error) {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
496 497 498
	p, err := dht.peerFromInfo(pbp)
	if err != nil {
		return nil, err
Jeromy's avatar
Jeromy committed
499 500
	}

501
	// dial connection
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
502
	err = dht.network.DialPeer(p)
503
	return p, err
Jeromy's avatar
Jeromy committed
504
}
505

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
506
//TODO: this should be smarter about which keys it selects.
507
func (dht *IpfsDHT) loadProvidableKeys() error {
508 509 510 511
	kl, err := dht.datastore.KeyList()
	if err != nil {
		return err
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
512 513 514 515 516 517 518
	for _, dsk := range kl {
		k := u.KeyFromDsKey(dsk)
		if len(k) == 0 {
			log.Error("loadProvidableKeys error: %v", dsk)
		}

		dht.providers.AddProvider(k, dht.self)
519 520 521 522
	}
	return nil
}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
523
// PingRoutine periodically pings nearest neighbors.
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
func (dht *IpfsDHT) PingRoutine(t time.Duration) {
	tick := time.Tick(t)
	for {
		select {
		case <-tick:
			id := make([]byte, 16)
			rand.Read(id)
			peers := dht.routingTables[0].NearestPeers(kb.ConvertKey(u.Key(id)), 5)
			for _, p := range peers {
				ctx, _ := context.WithTimeout(dht.ctx, time.Second*5)
				err := dht.Ping(ctx, p)
				if err != nil {
					log.Error("Ping error: %s", err)
				}
			}
		case <-dht.ctx.Done():
			return
		}
	}
}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
545
// Bootstrap builds up list of peers by requesting random peer IDs
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
546
func (dht *IpfsDHT) Bootstrap(ctx context.Context) {
547 548
	id := make([]byte, 16)
	rand.Read(id)
549 550 551 552
	_, err := dht.FindPeer(ctx, peer.ID(id))
	if err != nil {
		log.Error("Bootstrap peer error: %s", err)
	}
553
}