parent
832796f7ec
commit
d810811d6f
@ -0,0 +1,23 @@ |
||||
// Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
|
||||
// All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Package errors provides common error types used throughout leveldb.
|
||||
package ida |
||||
|
||||
import ( |
||||
"errors" |
||||
) |
||||
|
||||
// Common errors.
|
||||
var ( |
||||
ErrRaptorImpNotFound = New("raptor implementation: not found") |
||||
ErrTimeOut = New("timeout: time's up now") |
||||
) |
||||
|
||||
// New returns an error that formats as the given text.
|
||||
func New(text string) error { |
||||
return errors.New(text) |
||||
} |
@ -1,11 +1,37 @@ |
||||
package ida |
||||
|
||||
// HarmonyIDA implements IDA interface.
|
||||
type HarmonyIDA struct { |
||||
raptorQImp *RaptorQ |
||||
import ( |
||||
"time" |
||||
|
||||
"github.com/simple-rules/harmony-benchmark/p2p" |
||||
) |
||||
|
||||
// IDAImp implements IDA interface.
|
||||
type IDAImp struct { |
||||
raptorQImp RaptorQ |
||||
} |
||||
|
||||
// TakeRaptorQ takes RaptorQ implementation.
|
||||
func (ida *HarmonyIDA) TakeRaptorQ(raptorQImp *RaptorQ) { |
||||
func (ida *IDAImp) TakeRaptorQ(raptorQImp RaptorQ) { |
||||
ida.raptorQImp = raptorQImp |
||||
} |
||||
|
||||
// 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++ |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue