mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
p2p/sim, pot, swarm: fixes according to linter
This commit is contained in:
parent
e0086dd33a
commit
b7e6bf0803
11 changed files with 53 additions and 64 deletions
|
|
@ -25,7 +25,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSocketPipe(t *testing.T) {
|
func TestSocketPipe(t *testing.T) {
|
||||||
c1, c2, _ := socketPipe()
|
c1, c2, err := socketPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
|
@ -52,7 +55,7 @@ func TestSocketPipe(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(msg, out) != 0 {
|
if !bytes.Equal(msg, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", msg, out)
|
t.Fatalf("expected %#v, got %#v", msg, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +70,10 @@ func TestSocketPipe(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSocketPipeBidirections(t *testing.T) {
|
func TestSocketPipeBidirections(t *testing.T) {
|
||||||
c1, c2, _ := socketPipe()
|
c1, c2, err := socketPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
|
@ -90,7 +96,7 @@ func TestSocketPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(out, []byte(`ping`)) == 0 {
|
if !bytes.Equal(out, []byte(`ping`)) {
|
||||||
msg := []byte(`pong`)
|
msg := []byte(`pong`)
|
||||||
_, err := c2.Write(msg)
|
_, err := c2.Write(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -108,7 +114,7 @@ func TestSocketPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(out, expected) != 0 {
|
if !bytes.Equal(out, expected) {
|
||||||
t.Fatalf("expected %#v, got %#v", expected, out)
|
t.Fatalf("expected %#v, got %#v", expected, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +130,10 @@ func TestSocketPipeBidirections(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTcpPipe(t *testing.T) {
|
func TestTcpPipe(t *testing.T) {
|
||||||
c1, c2, _ := tcpPipe()
|
c1, c2, err := tcpPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
|
@ -151,7 +160,7 @@ func TestTcpPipe(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(msg, out) != 0 {
|
if !bytes.Equal(msg, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", msg, out)
|
t.Fatalf("expected %#v, got %#v", msg, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +175,10 @@ func TestTcpPipe(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTcpPipeBidirections(t *testing.T) {
|
func TestTcpPipeBidirections(t *testing.T) {
|
||||||
c1, c2, _ := tcpPipe()
|
c1, c2, err := tcpPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
|
@ -191,7 +203,7 @@ func TestTcpPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", out, expected)
|
t.Fatalf("expected %#v, got %#v", out, expected)
|
||||||
} else {
|
} else {
|
||||||
msg := []byte(fmt.Sprintf("pong %02d", i))
|
msg := []byte(fmt.Sprintf("pong %02d", i))
|
||||||
|
|
@ -211,7 +223,7 @@ func TestTcpPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", out, expected)
|
t.Fatalf("expected %#v, got %#v", out, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +238,10 @@ func TestTcpPipeBidirections(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetPipe(t *testing.T) {
|
func TestNetPipe(t *testing.T) {
|
||||||
c1, c2, _ := netPipe()
|
c1, c2, err := netPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
|
@ -256,7 +271,7 @@ func TestNetPipe(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(msg, out) != 0 {
|
if !bytes.Equal(msg, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", msg, out)
|
t.Fatalf("expected %#v, got %#v", msg, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -272,7 +287,10 @@ func TestNetPipe(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetPipeBidirections(t *testing.T) {
|
func TestNetPipeBidirections(t *testing.T) {
|
||||||
c1, c2, _ := netPipe()
|
c1, c2, err := netPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
|
@ -305,7 +323,7 @@ func TestNetPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", expected, out)
|
t.Fatalf("expected %#v, got %#v", expected, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -323,7 +341,7 @@ func TestNetPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", expected, out)
|
t.Fatalf("expected %#v, got %#v", expected, out)
|
||||||
} else {
|
} else {
|
||||||
msg := []byte(fmt.Sprintf(pongTemplate, i))
|
msg := []byte(fmt.Sprintf(pongTemplate, i))
|
||||||
|
|
|
||||||
|
|
@ -271,10 +271,7 @@ func testPotEachNeighbour(n *Pot, pof Pof, val Val, expCount int, fs ...func(Val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
if count == expCount {
|
return count != expCount
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
if err == nil && count < expCount {
|
if err == nil && count < expCount {
|
||||||
return fmt.Errorf("not enough neighbours returned, expected %v, got %v", expCount, count)
|
return fmt.Errorf("not enough neighbours returned, expected %v, got %v", expCount, count)
|
||||||
|
|
@ -558,10 +555,7 @@ func benchmarkEachNeighbourSync(t *testing.B, max, count int, d time.Duration) {
|
||||||
n.EachNeighbour(val, pof, func(v Val, po int) bool {
|
n.EachNeighbour(val, pof, func(v Val, po int) bool {
|
||||||
time.Sleep(d)
|
time.Sleep(d)
|
||||||
m++
|
m++
|
||||||
if m == count {
|
return m != count
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
t.StopTimer()
|
t.StopTimer()
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,11 @@ func TestBitvectorGetSet(t *testing.T) {
|
||||||
bv.Set(i, true)
|
bv.Set(i, true)
|
||||||
for j := 0; j < length; j++ {
|
for j := 0; j < length; j++ {
|
||||||
if j == i {
|
if j == i {
|
||||||
if bv.Get(j) != true {
|
if !bv.Get(j) {
|
||||||
t.Errorf("element on index %v is not set to true", i)
|
t.Errorf("element on index %v is not set to true", i)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if bv.Get(j) != false {
|
if bv.Get(j) {
|
||||||
t.Errorf("element on index %v is not false", i)
|
t.Errorf("element on index %v is not false", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ func TestBitvectorGetSet(t *testing.T) {
|
||||||
|
|
||||||
bv.Set(i, false)
|
bv.Set(i, false)
|
||||||
|
|
||||||
if bv.Get(i) != false {
|
if bv.Get(i) {
|
||||||
t.Errorf("element on index %v is not set to false", i)
|
t.Errorf("element on index %v is not set to false", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +82,7 @@ func TestBitvectorNewFromBytesGet(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if bv.Get(3) != true {
|
if !bv.Get(3) {
|
||||||
t.Fatalf("element 3 is not set to true: state %08b", bv.b[0])
|
t.Fatalf("element 3 is not set to true: state %08b", bv.b[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -269,9 +269,6 @@ func (m TakeoverProofMsg) String() string {
|
||||||
|
|
||||||
func (p *Peer) handleTakeoverProofMsg(req *TakeoverProofMsg) error {
|
func (p *Peer) handleTakeoverProofMsg(req *TakeoverProofMsg) error {
|
||||||
_, err := p.getServer(req.Stream)
|
_, err := p.getServer(req.Stream)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// store the strongest takeoverproof for the stream in streamer
|
// store the strongest takeoverproof for the stream in streamer
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -216,9 +216,7 @@ func (self *Pss) APIs() []rpc.API {
|
||||||
Public: true,
|
Public: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, auxapi := range self.auxAPIs {
|
apis = append(apis, self.auxAPIs...)
|
||||||
apis = append(apis, auxapi)
|
|
||||||
}
|
|
||||||
return apis
|
return apis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,7 +387,7 @@ func (self *Pss) SetPeerPublicKey(pubkey *ecdsa.PublicKey, topic Topic, address
|
||||||
address: address,
|
address: address,
|
||||||
}
|
}
|
||||||
self.pubKeyPoolMu.Lock()
|
self.pubKeyPoolMu.Lock()
|
||||||
if _, ok := self.pubKeyPool[pubkeyid]; ok == false {
|
if _, ok := self.pubKeyPool[pubkeyid]; !ok {
|
||||||
self.pubKeyPool[pubkeyid] = make(map[Topic]*pssPeer)
|
self.pubKeyPool[pubkeyid] = make(map[Topic]*pssPeer)
|
||||||
}
|
}
|
||||||
self.pubKeyPool[pubkeyid][topic] = psp
|
self.pubKeyPool[pubkeyid][topic] = psp
|
||||||
|
|
@ -538,7 +536,7 @@ func (self *Pss) cleanKeys() (count int) {
|
||||||
match = true
|
match = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match == false {
|
if !match {
|
||||||
expiredtopics = append(expiredtopics, topic)
|
expiredtopics = append(expiredtopics, topic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -719,7 +719,7 @@ func testNetwork(t *testing.T) {
|
||||||
select {
|
select {
|
||||||
case recvmsg := <-msgC:
|
case recvmsg := <-msgC:
|
||||||
idx, _ := binary.Uvarint(recvmsg.Msg)
|
idx, _ := binary.Uvarint(recvmsg.Msg)
|
||||||
if recvmsgs[idx] == false {
|
if !recvmsgs[idx] {
|
||||||
log.Debug("msg recv", "idx", idx, "id", id)
|
log.Debug("msg recv", "idx", idx, "id", id)
|
||||||
recvmsgs[idx] = true
|
recvmsgs[idx] = true
|
||||||
trigger <- id
|
trigger <- id
|
||||||
|
|
|
||||||
|
|
@ -733,8 +733,7 @@ func (s *DbStore) setCapacity(c uint64) {
|
||||||
s.capacity = c
|
s.capacity = c
|
||||||
|
|
||||||
if s.entryCnt > c {
|
if s.entryCnt > c {
|
||||||
var ratio float32
|
ratio := float32(1.01) - float32(c)/float32(s.entryCnt)
|
||||||
ratio = float32(1.01) - float32(c)/float32(s.entryCnt)
|
|
||||||
if ratio < gcArrayFreeRatio {
|
if ratio < gcArrayFreeRatio {
|
||||||
ratio = gcArrayFreeRatio
|
ratio = gcArrayFreeRatio
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ func testIterator(t *testing.T, mock bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 0; i < chunkcount; i++ {
|
for i = 0; i < chunkcount; i++ {
|
||||||
if bytes.Compare(chunkkeys[i], chunkkeys_results[i]) != 0 {
|
if !bytes.Equal(chunkkeys[i], chunkkeys_results[i]) {
|
||||||
t.Fatalf("Chunk put #%d key '%v' does not match iterator's key '%v'", i, chunkkeys[i], chunkkeys_results[i])
|
t.Fatalf("Chunk put #%d key '%v' does not match iterator's key '%v'", i, chunkkeys[i], chunkkeys_results[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -625,10 +625,7 @@ func (self *ResourceHandler) verifyContent(chunkdata []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ResourceHandler) hasUpdate(name string, period uint32) bool {
|
func (self *ResourceHandler) hasUpdate(name string, period uint32) bool {
|
||||||
if self.resources[name].lastPeriod == period {
|
return self.resources[name].lastPeriod == period
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type resourceChunkStore struct {
|
type resourceChunkStore struct {
|
||||||
|
|
|
||||||
|
|
@ -156,10 +156,7 @@ func (c KeyCollection) Len() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c KeyCollection) Less(i, j int) bool {
|
func (c KeyCollection) Less(i, j int) bool {
|
||||||
if bytes.Compare(c[i], c[j]) == -1 {
|
return bytes.Compare(c[i], c[j]) == -1
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c KeyCollection) Swap(i, j int) {
|
func (c KeyCollection) Swap(i, j int) {
|
||||||
|
|
|
||||||
|
|
@ -262,20 +262,13 @@ func (self *Swarm) Stop() error {
|
||||||
|
|
||||||
// implements the node.Service interface
|
// implements the node.Service interface
|
||||||
func (self *Swarm) Protocols() (protos []p2p.Protocol) {
|
func (self *Swarm) Protocols() (protos []p2p.Protocol) {
|
||||||
|
protos = append(protos, self.bzz.Protocols()...)
|
||||||
for _, p := range self.bzz.Protocols() {
|
|
||||||
protos = append(protos, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.ps != nil {
|
if self.ps != nil {
|
||||||
for _, p := range self.ps.Protocols() {
|
protos = append(protos, self.ps.Protocols()...)
|
||||||
protos = append(protos, p)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if self.streamer != nil {
|
if self.streamer != nil {
|
||||||
for _, p := range self.streamer.Protocols() {
|
protos = append(protos, self.streamer.Protocols()...)
|
||||||
protos = append(protos, p)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -336,14 +329,10 @@ func (self *Swarm) APIs() []rpc.API {
|
||||||
// {Namespace, Version, api.NewAdmin(self), false},
|
// {Namespace, Version, api.NewAdmin(self), false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, api := range self.bzz.APIs() {
|
apis = append(apis, self.bzz.APIs()...)
|
||||||
apis = append(apis, api)
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.ps != nil {
|
if self.ps != nil {
|
||||||
for _, api := range self.ps.APIs() {
|
apis = append(apis, self.ps.APIs()...)
|
||||||
apis = append(apis, api)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return apis
|
return apis
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue