forked from btcsuite/btcd
/
factompeer.go
690 lines (587 loc) · 20.5 KB
/
factompeer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package btcd
import (
"encoding/hex"
"github.com/FactomProject/FactomCode/common"
"github.com/FactomProject/FactomCode/database"
"github.com/FactomProject/btcd/blockchain"
"github.com/FactomProject/btcd/wire"
"github.com/davecgh/go-spew/spew"
"time"
)
// handleFBlockMsg is invoked when a peer receives a factoid block message.
func (p *peer) handleFBlockMsg(msg *wire.MsgFBlock, buf []byte) {
binary, _ := msg.SC.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeFactomFBlock, hash)
p.AddKnownInventory(iv)
inMsgQueue <- msg
}
// handleDirBlockMsg is invoked when a peer receives a dir block message.
func (p *peer) handleDirBlockMsg(msg *wire.MsgDirBlock, buf []byte) {
binary, _ := msg.DBlk.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeFactomDirBlock, hash)
p.AddKnownInventory(iv)
p.pushGetNonDirDataMsg(msg.DBlk)
inMsgQueue <- msg
delete(p.requestedBlocks, *hash)
delete(p.server.blockManager.requestedBlocks, *hash)
}
// handleABlockMsg is invoked when a peer receives a entry credit block message.
func (p *peer) handleABlockMsg(msg *wire.MsgABlock, buf []byte) {
binary, _ := msg.ABlk.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeFactomAdminBlock, hash)
p.AddKnownInventory(iv)
inMsgQueue <- msg
}
// handleECBlockMsg is invoked when a peer receives a entry credit block
// message.
func (p *peer) handleECBlockMsg(msg *wire.MsgECBlock, buf []byte) {
headerHash, err := msg.ECBlock.HeaderHash()
if err != nil {
panic(err)
}
hash := wire.FactomHashToShaHash(headerHash)
iv := wire.NewInvVect(wire.InvTypeFactomEntryCreditBlock, hash)
p.AddKnownInventory(iv)
inMsgQueue <- msg
}
// handleEBlockMsg is invoked when a peer receives an entry block bitcoin message.
func (p *peer) handleEBlockMsg(msg *wire.MsgEBlock, buf []byte) {
binary, _ := msg.EBlk.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeFactomEntryBlock, hash)
p.AddKnownInventory(iv)
p.pushGetEntryDataMsg(msg.EBlk)
inMsgQueue <- msg
}
// handleEntryMsg is invoked when a peer receives a EBlock Entry message.
func (p *peer) handleEntryMsg(msg *wire.MsgEntry, buf []byte) {
binary, _ := msg.Entry.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeFactomEntry, hash)
p.AddKnownInventory(iv)
inMsgQueue <- msg
}
// handleGetEntryDataMsg is invoked when a peer receives a get entry data message and
// is used to deliver entry of EBlock information.
func (p *peer) handleGetEntryDataMsg(msg *wire.MsgGetEntryData) {
numAdded := 0
notFound := wire.NewMsgNotFound()
// We wait on the this wait channel periodically to prevent queueing
// far more data than we can send in a reasonable time, wasting memory.
// The waiting occurs after the database fetch for the next one to
// provide a little pipelining.
var waitChan chan struct{}
doneChan := make(chan struct{}, 1)
for i, iv := range msg.InvList {
var c chan struct{}
// If this will be the last message we send.
if i == len(msg.InvList)-1 && len(notFound.InvList) == 0 {
c = doneChan
} else { //if (i+1)%3 == 0 {
// Buffered so as to not make the send goroutine block.
c = make(chan struct{}, 1)
}
if iv.Type != wire.InvTypeFactomEntry {
continue
}
// Is this right? what is iv.hash?
blk, err := db.FetchEBlockByHash(iv.Hash.ToFactomHash())
if err != nil {
if doneChan != nil {
doneChan <- struct{}{}
}
return
}
for _, ebEntry := range blk.Body.EBEntries {
//Skip the minute markers
if ebEntry.IsMinuteMarker() {
continue
}
var err error
err = p.pushEntryMsg(ebEntry, c, waitChan)
if err != nil {
notFound.AddInvVect(iv)
// When there is a failure fetching the final entry
// and the done channel was sent in due to there
// being no outstanding not found inventory, consume
// it here because there is now not found inventory
// that will use the channel momentarily.
if i == len(msg.InvList)-1 && c != nil {
<-c
}
}
numAdded++
waitChan = c
}
}
if len(notFound.InvList) != 0 {
p.QueueMessage(notFound, doneChan)
}
// Wait for messages to be sent. We can send quite a lot of data at this
// point and this will keep the peer busy for a decent amount of time.
// We don't process anything else by them in this time so that we
// have an idea of when we should hear back from them - else the idle
// timeout could fire when we were only half done sending the blocks.
if numAdded > 0 {
<-doneChan
}
}
// handleGetNonDirDataMsg is invoked when a peer receives a dir block message.
// It returns the corresponding data block like Factoid block,
// EC block, Entry block, and Entry based on directory block's ChainID
func (p *peer) handleGetNonDirDataMsg(msg *wire.MsgGetNonDirData) {
numAdded := 0
notFound := wire.NewMsgNotFound()
// We wait on the this wait channel periodically to prevent queueing
// far more data than we can send in a reasonable time, wasting memory.
// The waiting occurs after the database fetch for the next one to
// provide a little pipelining.
var waitChan chan struct{}
doneChan := make(chan struct{}, 1)
for i, iv := range msg.InvList {
var c chan struct{}
// If this will be the last message we send.
if i == len(msg.InvList)-1 && len(notFound.InvList) == 0 {
c = doneChan
} else { //if (i+1)%3 == 0 {
// Buffered so as to not make the send goroutine block.
c = make(chan struct{}, 1)
}
if iv.Type != wire.InvTypeFactomNonDirBlock {
continue
}
// Is this right? what is iv.hash?
blk, err := db.FetchDBlockByHash(iv.Hash.ToFactomHash())
if err != nil {
peerLog.Tracef("Unable to fetch requested EC block sha %v: %v",
iv.Hash, err)
if doneChan != nil {
doneChan <- struct{}{}
}
return
}
for _, dbEntry := range blk.DBEntries {
var err error
switch dbEntry.ChainID.String() {
case hex.EncodeToString(common.EC_CHAINID[:]):
err = p.pushECBlockMsg(dbEntry.KeyMR, c, waitChan)
case hex.EncodeToString(common.ADMIN_CHAINID[:]):
err = p.pushABlockMsg(dbEntry.KeyMR, c, waitChan)
case wire.FChainID.String():
err = p.pushFBlockMsg(dbEntry.KeyMR, c, waitChan)
default:
err = p.pushEBlockMsg(dbEntry.KeyMR, c, waitChan)
//continue
}
if err != nil {
notFound.AddInvVect(iv)
// When there is a failure fetching the final entry
// and the done channel was sent in due to there
// being no outstanding not found inventory, consume
// it here because there is now not found inventory
// that will use the channel momentarily.
if i == len(msg.InvList)-1 && c != nil {
<-c
}
}
numAdded++
waitChan = c
}
}
if len(notFound.InvList) != 0 {
p.QueueMessage(notFound, doneChan)
}
// Wait for messages to be sent. We can send quite a lot of data at this
// point and this will keep the peer busy for a decent amount of time.
// We don't process anything else by them in this time so that we
// have an idea of when we should hear back from them - else the idle
// timeout could fire when we were only half done sending the blocks.
if numAdded > 0 {
<-doneChan
}
}
// handleDirInvMsg is invoked when a peer receives an inv bitcoin message and is
// used to examine the inventory being advertised by the remote peer and react
// accordingly. We pass the message down to blockmanager which will call
// QueueMessage with any appropriate responses.
func (p *peer) handleDirInvMsg(msg *wire.MsgDirInv) {
p.server.blockManager.QueueDirInv(msg, p)
}
// handleGetDirDataMsg is invoked when a peer receives a getdata bitcoin message and
// is used to deliver block and transaction information.
func (p *peer) handleGetDirDataMsg(msg *wire.MsgGetDirData) {
numAdded := 0
notFound := wire.NewMsgNotFound()
// We wait on the this wait channel periodically to prevent queueing
// far more data than we can send in a reasonable time, wasting memory.
// The waiting occurs after the database fetch for the next one to
// provide a little pipelining.
var waitChan chan struct{}
doneChan := make(chan struct{}, 1)
for i, iv := range msg.InvList {
var c chan struct{}
// If this will be the last message we send.
if i == len(msg.InvList)-1 && len(notFound.InvList) == 0 {
c = doneChan
} else if (i+1)%3 == 0 {
// Buffered so as to not make the send goroutine block.
c = make(chan struct{}, 1)
}
var err error
switch iv.Type {
//case wire.InvTypeTx:
//err = p.pushTxMsg(&iv.Hash, c, waitChan)
case wire.InvTypeFactomDirBlock:
err = p.pushDirBlockMsg(&iv.Hash, c, waitChan)
/*
case wire.InvTypeFilteredBlock:
err = p.pushMerkleBlockMsg(&iv.Hash, c, waitChan)
*/
default:
peerLog.Warnf("Unknown type in inventory request %d",
iv.Type)
continue
}
if err != nil {
notFound.AddInvVect(iv)
// When there is a failure fetching the final entry
// and the done channel was sent in due to there
// being no outstanding not found inventory, consume
// it here because there is now not found inventory
// that will use the channel momentarily.
if i == len(msg.InvList)-1 && c != nil {
<-c
}
}
numAdded++
waitChan = c
}
if len(notFound.InvList) != 0 {
p.QueueMessage(notFound, doneChan)
}
// Wait for messages to be sent. We can send quite a lot of data at this
// point and this will keep the peer busy for a decent amount of time.
// We don't process anything else by them in this time so that we
// have an idea of when we should hear back from them - else the idle
// timeout could fire when we were only half done sending the blocks.
if numAdded > 0 {
<-doneChan
}
}
// handleGetDirBlocksMsg is invoked when a peer receives a getdirblocks factom message.
func (p *peer) handleGetDirBlocksMsg(msg *wire.MsgGetDirBlocks) {
// Return all block hashes to the latest one (up to max per message) if
// no stop hash was specified.
// Attempt to find the ending index of the stop hash if specified.
endIdx := database.AllShas //factom db
if !msg.HashStop.IsEqual(&zeroHash) {
height, err := db.FetchBlockHeightBySha(&msg.HashStop)
if err == nil {
endIdx = height + 1
}
}
// Find the most recent known block based on the block locator.
// Use the block after the genesis block if no other blocks in the
// provided locator are known. This does mean the client will start
// over with the genesis block if unknown block locators are provided.
// This mirrors the behavior in the reference implementation.
startIdx := int64(1)
for _, hash := range msg.BlockLocatorHashes {
height, err := db.FetchBlockHeightBySha(hash)
if err == nil {
// Start with the next hash since we know this one.
startIdx = height + 1
break
}
}
peerLog.Info("startIdx=", startIdx, ", endIdx=", endIdx)
// Don't attempt to fetch more than we can put into a single message.
autoContinue := false
if endIdx-startIdx > wire.MaxBlocksPerMsg {
endIdx = startIdx + wire.MaxBlocksPerMsg
autoContinue = true
}
// Generate inventory message.
//
// The FetchBlockBySha call is limited to a maximum number of hashes
// per invocation. Since the maximum number of inventory per message
// might be larger, call it multiple times with the appropriate indices
// as needed.
invMsg := wire.NewMsgDirInv()
for start := startIdx; start < endIdx; {
// Fetch the inventory from the block database.
hashList, err := db.FetchHeightRange(start, endIdx)
if err != nil {
peerLog.Warnf("Dir Block lookup failed: %v", err)
return
}
// The database did not return any further hashes. Break out of
// the loop now.
if len(hashList) == 0 {
break
}
// Add dir block inventory to the message.
for _, hash := range hashList {
hashCopy := hash
iv := wire.NewInvVect(wire.InvTypeFactomDirBlock, &hashCopy)
invMsg.AddInvVect(iv)
}
start += int64(len(hashList))
}
// Send the inventory message if there is anything to send.
if len(invMsg.InvList) > 0 {
invListLen := len(invMsg.InvList)
if autoContinue && invListLen == wire.MaxBlocksPerMsg {
// Intentionally use a copy of the final hash so there
// is not a reference into the inventory slice which
// would prevent the entire slice from being eligible
// for GC as soon as it's sent.
continueHash := invMsg.InvList[invListLen-1].Hash
p.continueHash = &continueHash
}
p.QueueMessage(invMsg, nil)
}
}
// pushDirBlockMsg sends a dir block message for the provided block hash to the
// connected peer. An error is returned if the block hash is not known.
func (p *peer) pushDirBlockMsg(sha *wire.ShaHash, doneChan, waitChan chan struct{}) error {
commonhash := new(common.Hash)
commonhash.SetBytes(sha.Bytes())
blk, err := db.FetchDBlockByHash(commonhash)
if err != nil {
peerLog.Tracef("Unable to fetch requested dir block sha %v: %v",
sha, err)
if doneChan != nil {
doneChan <- struct{}{}
}
return err
}
// Once we have fetched data wait for any previous operation to finish.
if waitChan != nil {
<-waitChan
}
// We only send the channel for this message if we aren't sending(sha)
// an inv straight after.
var dc chan struct{}
sendInv := p.continueHash != nil && p.continueHash.IsEqual(sha)
if !sendInv {
dc = doneChan
}
msg := wire.NewMsgDirBlock()
msg.DBlk = blk
p.QueueMessage(msg, dc) //blk.MsgBlock(), dc)
// When the peer requests the final block that was advertised in
// response to a getblocks message which requested more blocks than
// would fit into a single message, send it a new inventory message
// to trigger it to issue another getblocks message for the next
// batch of inventory.
if p.continueHash != nil && p.continueHash.IsEqual(sha) {
peerLog.Debug("continueHash: " + spew.Sdump(sha))
// Sleep for 5 seconds for the peer to catch up
time.Sleep(5 * time.Second)
//
// Note: Rather than the latest block height, we should pass
// the last block height of this batch of wire.MaxBlockLocatorsPerMsg
// to signal this is the end of the batch and
// to trigger a client to send a new GetDirBlocks message
//
//hash, _, err := db.FetchBlockHeightCache()
//if err == nil {
invMsg := wire.NewMsgDirInvSizeHint(1)
iv := wire.NewInvVect(wire.InvTypeFactomDirBlock, sha) //hash)
invMsg.AddInvVect(iv)
p.QueueMessage(invMsg, doneChan)
p.continueHash = nil
//} else if doneChan != nil {
if doneChan != nil {
doneChan <- struct{}{}
}
}
return nil
}
// PushGetDirBlocksMsg sends a getdirblocks message for the provided block locator
// and stop hash. It will ignore back-to-back duplicate requests.
func (p *peer) PushGetDirBlocksMsg(locator blockchain.BlockLocator, stopHash *wire.ShaHash) error {
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getblocks requests.
// request.
var beginHash *wire.ShaHash
if len(locator) > 0 {
beginHash = locator[0]
}
// Filter duplicate getdirblocks requests.
if p.prevGetBlocksStop != nil && p.prevGetBlocksBegin != nil &&
beginHash != nil && stopHash.IsEqual(p.prevGetBlocksStop) &&
beginHash.IsEqual(p.prevGetBlocksBegin) {
peerLog.Tracef("Filtering duplicate [getdirblocks] with begin "+
"hash %v, stop hash %v", beginHash, stopHash)
return nil
}
// Construct the getblocks request and queue it to be sent.
msg := wire.NewMsgGetDirBlocks(stopHash)
for _, hash := range locator {
err := msg.AddBlockLocatorHash(hash)
if err != nil {
return err
}
}
p.QueueMessage(msg, nil)
// Update the previous getblocks request information for filtering
// duplicates.
p.prevGetBlocksBegin = beginHash
p.prevGetBlocksStop = stopHash
return nil
}
// pushGetNonDirDataMsg takes the passed DBlock
// and return corresponding data block like Factoid block,
// EC block, Entry block, and Entry
func (p *peer) pushGetNonDirDataMsg(dblock *common.DirectoryBlock) {
binary, _ := dblock.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeFactomNonDirBlock, hash)
gdmsg := wire.NewMsgGetNonDirData()
gdmsg.AddInvVect(iv)
if len(gdmsg.InvList) > 0 {
p.QueueMessage(gdmsg, nil)
}
}
// pushGetEntryDataMsg takes the passed EBlock
// and return all the corresponding EBEntries
func (p *peer) pushGetEntryDataMsg(eblock *common.EBlock) {
binary, _ := eblock.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeFactomEntry, hash)
gdmsg := wire.NewMsgGetEntryData()
gdmsg.AddInvVect(iv)
if len(gdmsg.InvList) > 0 {
p.QueueMessage(gdmsg, nil)
}
}
// pushFBlockMsg sends an factoid block message for the provided block hash to the
// connected peer. An error is returned if the block hash is not known.
func (p *peer) pushFBlockMsg(commonhash *common.Hash, doneChan, waitChan chan struct{}) error {
blk, err := db.FetchFBlockByHash(commonhash)
if err != nil || blk == nil {
peerLog.Tracef("Unable to fetch requested SC block sha %v: %v",
commonhash, err)
if doneChan != nil {
doneChan <- struct{}{}
}
return err
}
// Once we have fetched data wait for any previous operation to finish.
if waitChan != nil {
<-waitChan
}
msg := wire.NewMsgFBlock()
msg.SC = blk
p.QueueMessage(msg, doneChan) //blk.MsgBlock(), dc)
return nil
}
// pushABlockMsg sends an admin block message for the provided block hash to the
// connected peer. An error is returned if the block hash is not known.
func (p *peer) pushABlockMsg(commonhash *common.Hash, doneChan, waitChan chan struct{}) error {
blk, err := db.FetchABlockByHash(commonhash)
if err != nil || blk == nil {
peerLog.Tracef("Unable to fetch requested Admin block sha %v: %v",
commonhash, err)
if doneChan != nil {
doneChan <- struct{}{}
}
return err
}
// Once we have fetched data wait for any previous operation to finish.
if waitChan != nil {
<-waitChan
}
msg := wire.NewMsgABlock()
msg.ABlk = blk
p.QueueMessage(msg, doneChan) //blk.MsgBlock(), dc)
return nil
}
// pushECBlockMsg sends a entry credit block message for the provided block
// hash to the connected peer. An error is returned if the block hash is not
// known.
func (p *peer) pushECBlockMsg(commonhash *common.Hash, doneChan, waitChan chan struct{}) error {
blk, err := db.FetchECBlockByHash(commonhash)
if err != nil || blk == nil {
peerLog.Tracef("Unable to fetch requested Entry Credit block sha %v: %v",
commonhash, err)
if doneChan != nil {
doneChan <- struct{}{}
}
return err
}
// Once we have fetched data wait for any previous operation to finish.
if waitChan != nil {
<-waitChan
}
msg := wire.NewMsgECBlock()
msg.ECBlock = blk
p.QueueMessage(msg, doneChan) //blk.MsgBlock(), dc)
return nil
}
// pushEBlockMsg sends a entry block message for the provided block hash to the
// connected peer. An error is returned if the block hash is not known.
func (p *peer) pushEBlockMsg(commonhash *common.Hash, doneChan, waitChan chan struct{}) error {
blk, err := db.FetchEBlockByMR(commonhash)
if err != nil {
if doneChan != nil || blk == nil {
peerLog.Tracef("Unable to fetch requested Entry block sha %v: %v",
commonhash, err)
doneChan <- struct{}{}
}
return err
}
// Once we have fetched data wait for any previous operation to finish.
if waitChan != nil {
<-waitChan
}
msg := wire.NewMsgEBlock()
msg.EBlk = blk
p.QueueMessage(msg, doneChan) //blk.MsgBlock(), dc)
return nil
}
// pushEntryMsg sends a EBlock entry message for the provided ebentry hash to the
// connected peer. An error is returned if the block hash is not known.
func (p *peer) pushEntryMsg(commonhash *common.Hash, doneChan, waitChan chan struct{}) error {
entry, err := db.FetchEntryByHash(commonhash)
if err != nil || entry == nil {
peerLog.Tracef("Unable to fetch requested Entry sha %v: %v",
commonhash, err)
if doneChan != nil {
doneChan <- struct{}{}
}
return err
}
// Once we have fetched data wait for any previous operation to finish.
if waitChan != nil {
<-waitChan
}
msg := wire.NewMsgEntry()
msg.Entry = entry
p.QueueMessage(msg, doneChan) //blk.MsgBlock(), dc)
return nil
}
// handleFactoidMsg
func (p *peer) handleFactoidMsg(msg *wire.MsgFactoidTX, buf []byte) {
binary, _ := msg.Transaction.MarshalBinary()
commonHash := common.Sha(binary)
hash, _ := wire.NewShaHash(commonHash.Bytes())
iv := wire.NewInvVect(wire.InvTypeTx, hash)
p.AddKnownInventory(iv)
inMsgQueue <- msg
}