Merge branch 'master' of https://github.com/harmony-one/harmony into HAR-67_libp2p_integration_v2
commit
bc76946bdb
@ -1,9 +1,14 @@ |
||||
#!/bin/bash |
||||
|
||||
if [ $(golint ./... | wc | awk '{print $1}') -gt 2 ]; then |
||||
echo "Go code is not formatted:" |
||||
gofmt -d . |
||||
exit 1 |
||||
fi |
||||
if [ -n "$(gofmt -l .)" ]; then |
||||
echo "Go code is not formatted:" |
||||
gofmt -d . |
||||
exit 1 |
||||
else |
||||
echo "Go code is well formatted ;)" |
||||
fi |
||||
fi |
||||
|
@ -1,14 +1,18 @@ |
||||
language: go |
||||
go: |
||||
- master |
||||
- master |
||||
install: |
||||
- export GOPATH=$HOME/gopath |
||||
- cd $HOME/gopath/src |
||||
- cd github.com/harmony-one/harmony |
||||
- go get -t -v ./... |
||||
- go get -u golang.org/x/lint/golint |
||||
- go get gopkg.in/check.v1 |
||||
- ./.travis.gofmt.sh |
||||
- go build -v ./... |
||||
script: |
||||
- ./.travis.gofmt.sh |
||||
notifications: |
||||
slack: harmonyone:gggCd1QQopsQAW8JYgBWiH7M |
||||
slack: |
||||
harmonyone:gggCd1QQopsQAW8JYgBWiH7M |
||||
# secure: RPB3ThYIGuDUidvaWfOA7Hc9x1bDfd5+Y10r7xwY+NGCN3zW86s/GNLpLutI0MWTV9e2CJupHvz5clp8Ktle/tVjLhs6jHQnNV7U8PTWKkL5By6IFVAHN12unMQn/m0RPwqMfdubajXoV51XhbFA/iow/0fqwsd61VdPIuBrlQjy9z7kyVnRLNoGvYjDqKEkJfYVb3qFNFLzD0F7Y2AgxnezIRjsTLgHzR4owLJYqVMhvTYIV9/vSf1w4UUPzhHyZRESl6bri+a1+g7GxE32OtNwq68xxVeeJcrO/MbjAHHW9V6BW1MjJfYzD5T+7JHIfZOjV2WgzJ7uCkVYztfq+02yOCSWsLNxFVojIDhVFEhhJ6Vd2Zf1otolS7j0svK/qNmShID9q9NAasaI105GsQgtaSPAUGd88J/vyX2ndG1nDOvxmgOo10tZFOnPHW7JnWMybk3PLza8o1ujA7X3JFdvDA8BPP9h6MVP4N7doCQ/n4Crts53HvEWlvcv5sBNu61WYlSTBzf1qNwBKMyN2E0rNubsxKmW8B6jLdWYdlx57nyTRPraNKGE1fnUW5nWRZGax3F1tQRwEfpQMk22qgeUK0RYWsPgHFaPciKCA3dJX7t1k/ib9pyR4nc9SZnYw54KMhkAXPIVQ0iy0EpTAH1DNYV6v8zXCwjl+BdkhlY= |
||||
|
@ -1,23 +0,0 @@ |
||||
// 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 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) |
||||
} |
@ -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++ |
||||
} |
||||
} |
||||
} |
@ -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")
|
||||
// }
|
||||
} |
@ -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 |
||||
} |
Loading…
Reference in new issue