From 2031ec09df10903d1a9522c54a8be4df951938fa Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Tue, 4 Dec 2018 13:06:55 -0800 Subject: [PATCH] get rid of unused code --- p2p/ida/errors.go | 23 ------------- p2p/ida/ida.go | 37 --------------------- p2p/ida/ida_test.go | 77 -------------------------------------------- p2p/ida/interface.go | 25 -------------- 4 files changed, 162 deletions(-) delete mode 100644 p2p/ida/errors.go delete mode 100644 p2p/ida/ida.go delete mode 100644 p2p/ida/ida_test.go delete mode 100644 p2p/ida/interface.go diff --git a/p2p/ida/errors.go b/p2p/ida/errors.go deleted file mode 100644 index 6552e2f33..000000000 --- a/p2p/ida/errors.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2014, Suryandaru Triandana -// All rights reserved. -// -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Package ida 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) -} diff --git a/p2p/ida/ida.go b/p2p/ida/ida.go deleted file mode 100644 index 23351a768..000000000 --- a/p2p/ida/ida.go +++ /dev/null @@ -1,37 +0,0 @@ -package ida - -import ( - "time" - - "github.com/harmony-one/harmony/p2p" -) - -// IDAImp implements IDA interface. -type IDAImp struct { - raptorQImp RaptorQ -} - -// TakeRaptorQ takes RaptorQ implementation. -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++ - } - } -} diff --git a/p2p/ida/ida_test.go b/p2p/ida/ida_test.go deleted file mode 100644 index d48c16644..000000000 --- a/p2p/ida/ida_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package ida - -import ( - "math/rand" - "testing" - "time" - - "github.com/harmony-one/harmony/p2p" -) - -var ( - a = Symbol{0, 0} - b = Symbol{1, 0} - c = Symbol{0, 1} - d = Symbol{1, 1} -) - -type FakeRaptor struct { - symbols []Symbol - done chan struct{} - r *rand.Rand -} - -func (raptor *FakeRaptor) Init() { - // raptor.symbols = make([]Symbol, 4) - raptor.symbols = make([]Symbol, 4) - raptor.symbols[0] = make(Symbol, 2) - copy(raptor.symbols[0], a) - raptor.symbols[1] = make(Symbol, 2) - copy(raptor.symbols[1], b) - raptor.symbols[2] = make(Symbol, 2) - copy(raptor.symbols[2], c) - raptor.symbols[3] = make(Symbol, 2) - copy(raptor.symbols[3], d) - raptor.r = rand.New(rand.NewSource(99)) - raptor.done = make(chan struct{}) -} - -func (raptor *FakeRaptor) generate(res chan Symbol) { - for { - select { - case <-raptor.done: - return - default: - i := raptor.r.Intn(4) - res <- raptor.symbols[i] - } - } -} - -func (raptor *FakeRaptor) Process(msg Message) chan Symbol { - res := make(chan Symbol) - go raptor.generate(res) - return res -} - -func TestShouldReturnErrRaptorImpNotFound(t *testing.T) { - ida := &IDAImp{} - done := make(chan struct{}) - err := ida.Process([]byte{}, []p2p.Peer{}, done, time.Second) - if err != ErrRaptorImpNotFound { - t.Fatal("Should return an error") - } -} - -func TestSimple(t *testing.T) { - raptor := &FakeRaptor{} - raptor.Init() - - // ida := &IDAImp{} - // done := make(chan struct{}) - // ida.TakeRaptorQ(raptor) - // err := ida.Process([]byte{}, []p2p.Peer{}, done, time.Second) - // if err == ErrRaptorImpNotFound { - // t.Fatal("Should return an error") - // } -} diff --git a/p2p/ida/interface.go b/p2p/ida/interface.go deleted file mode 100644 index bb6c3f446..000000000 --- a/p2p/ida/interface.go +++ /dev/null @@ -1,25 +0,0 @@ -package ida - -import ( - "time" - - "github.com/harmony-one/harmony/p2p" -) - -// Symbol is produced from a RaptorQ implementation. -type Symbol []byte - -// Message is type of general message gopssiped -type Message []byte - -// RaptorQ interface. -type RaptorQ interface { - Init() - Process(msg Message) chan Symbol -} - -// IDA interface. -type IDA interface { - TakeRaptorQ(raptorQImp *RaptorQ) - Process(msg Message, peers []p2p.Peer, done chan struct{}, timeout time.Duration) error -}