The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/p2p/ida/ida.go

38 lines
733 B

package ida
6 years ago
import (
"time"
"github.com/harmony-one/harmony/p2p"
6 years ago
)
// IDAImp implements IDA interface.
type IDAImp struct {
raptorQImp RaptorQ
}
// TakeRaptorQ takes RaptorQ implementation.
6 years ago
func (ida *IDAImp) TakeRaptorQ(raptorQImp RaptorQ) {
ida.raptorQImp = raptorQImp
}
6 years ago
// Process implements very simple IDA logic.
func (ida *IDAImp) Process(msg Message, peers []p2p.Peer, done chan struct{}, timeout time.Duration) error {
if ida.raptorQImp == nil {
return ErrRaptorImpNotFound
}
chunkStream := ida.raptorQImp.Process(msg)
id := 0
for {
select {
case <-done:
return nil
case <-time.After(timeout):
return ErrTimeOut
case chunk := <-chunkStream:
p2p.SendMessage(peers[id], chunk)
id++
}
}
}