mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
Merge remote-tracking branch 'upstream/develop' into kademlia
Conflicts: p2p/protocol.go p2p/protocol_test.go
This commit is contained in:
commit
bcce94b1ad
37 changed files with 509 additions and 345 deletions
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@
|
||||||
/**
|
/**
|
||||||
* @authors:
|
* @authors:
|
||||||
* Jeffrey Wilcke <i@jev.io>
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
* @date 2014
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@
|
||||||
/**
|
/**
|
||||||
* @authors
|
* @authors
|
||||||
* Jeffrey Wilcke <i@jev.io>
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
* @date 2014
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
@ -133,6 +131,12 @@ func (self *VMEnv) Value() *big.Int { return self.value }
|
||||||
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
|
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
|
||||||
func (self *VMEnv) Depth() int { return 0 }
|
func (self *VMEnv) Depth() int { return 0 }
|
||||||
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
||||||
|
func (self *VMEnv) GetHash(n uint64) []byte {
|
||||||
|
if self.block.Number().Cmp(big.NewInt(int64(n))) == 0 {
|
||||||
|
return self.block.Hash()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (self *VMEnv) AddLog(log state.Log) {
|
func (self *VMEnv) AddLog(log state.Log) {
|
||||||
self.state.AddLog(log)
|
self.state.AddLog(log)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ Rectangle {
|
||||||
text: "Start"
|
text: "Start"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
eth.setGasPrice(minGasPrice.text || "10000000000000");
|
eth.setGasPrice(minGasPrice.text || "10000000000000");
|
||||||
|
eth.setExtra(blockExtra.text)
|
||||||
if (eth.toggleMining()) {
|
if (eth.toggleMining()) {
|
||||||
this.text = "Stop";
|
this.text = "Stop";
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -55,6 +56,7 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
id: minGasPriceRect
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: 2
|
anchors.topMargin: 2
|
||||||
width: 200
|
width: 200
|
||||||
|
|
@ -65,6 +67,23 @@ Rectangle {
|
||||||
validator: RegExpValidator { regExp: /\d*/ }
|
validator: RegExpValidator { regExp: /\d*/ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: 300
|
||||||
|
anchors {
|
||||||
|
left: minGasPriceRect.right
|
||||||
|
leftMargin: 5
|
||||||
|
top: parent.top
|
||||||
|
topMargin: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: blockExtra
|
||||||
|
placeholderText: "Extra"
|
||||||
|
width: parent.width
|
||||||
|
maximumLength: 1024
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
// License as published by the Free Software Foundation; either
|
it under the terms of the GNU General Public License as published by
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
//
|
(at your option) any later version.
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
//
|
GNU General Public License for more details.
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
You should have received a copy of the GNU General Public License
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// MA 02110-1301 USA
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,23 @@
|
||||||
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
/*
|
||||||
//
|
This file is part of go-ethereum
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation; either
|
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
// MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -279,6 +282,10 @@ func (self *UiLib) SetGasPrice(price string) {
|
||||||
self.miner.MinAcceptedGasPrice = ethutil.Big(price)
|
self.miner.MinAcceptedGasPrice = ethutil.Big(price)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *UiLib) SetExtra(extra string) {
|
||||||
|
self.miner.Extra = extra
|
||||||
|
}
|
||||||
|
|
||||||
func (self *UiLib) ToggleMining() bool {
|
func (self *UiLib) ToggleMining() bool {
|
||||||
if !self.miner.Mining() {
|
if !self.miner.Mining() {
|
||||||
self.miner.Start()
|
self.miner.Start()
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,25 @@
|
||||||
|
/*
|
||||||
|
This file is part of go-ethereum
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"fmt"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
@ -12,29 +27,32 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
natType = flag.String("nat", "", "NAT traversal implementation")
|
||||||
|
pmpGateway = flag.String("gateway", "", "gateway address for NAT-PMP")
|
||||||
|
listenAddr = flag.String("addr", ":30301", "listen address")
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
nat, err := p2p.ParseNAT(*natType, *pmpGateway)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("invalid nat:", err)
|
||||||
|
}
|
||||||
|
|
||||||
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
|
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
marshaled := elliptic.Marshal(crypto.S256(), key.PublicKey.X, key.PublicKey.Y)
|
marshaled := elliptic.Marshal(crypto.S256(), key.PublicKey.X, key.PublicKey.Y)
|
||||||
|
|
||||||
srv := p2p.Server{
|
srv := p2p.Server{
|
||||||
MaxPeers: 100,
|
MaxPeers: 100,
|
||||||
Identity: p2p.NewSimpleClientIdentity("Ethereum(G)", "0.1", "Peer Server Two", string(marshaled)),
|
Identity: p2p.NewSimpleClientIdentity("Ethereum(G)", "0.1", "Peer Server Two", marshaled),
|
||||||
ListenAddr: ":30301",
|
ListenAddr: *listenAddr,
|
||||||
NAT: p2p.UPNP(),
|
NAT: nat,
|
||||||
|
NoDial: true,
|
||||||
}
|
}
|
||||||
if err := srv.Start(); err != nil {
|
if err := srv.Start(); err != nil {
|
||||||
fmt.Println("could not start server:", err)
|
log.Fatal("could not start server:", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add seed peers
|
|
||||||
seed, err := net.ResolveTCPAddr("tcp", "poc-8.ethdev.com:30303")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("couldn't resolve:", err)
|
|
||||||
} else {
|
|
||||||
srv.SuggestPeer(seed.IP, seed.Port, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Felix Lange <felix@ethdev.com>
|
||||||
|
*/
|
||||||
|
|
||||||
// rlpdump is a pretty-printer for RLP data.
|
// rlpdump is a pretty-printer for RLP data.
|
||||||
package main
|
package main
|
||||||
|
|
@ -106,8 +110,7 @@ func dump(s *rlp.Stream, depth int) error {
|
||||||
s.List()
|
s.List()
|
||||||
defer s.ListEnd()
|
defer s.ListEnd()
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
fmt.Printf(ws(depth) + "[]")
|
fmt.Print(ws(depth) + "[]")
|
||||||
return nil
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(ws(depth) + "[")
|
fmt.Println(ws(depth) + "[")
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,24 @@
|
||||||
|
/*
|
||||||
|
This file is part of go-ethereum
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
* Viktor Tron <viktor@ethdev.com>
|
||||||
|
*/
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,23 @@
|
||||||
|
/*
|
||||||
|
This file is part of go-ethereum
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,23 @@
|
||||||
|
/*
|
||||||
|
This file is part of go-ethereum
|
||||||
|
|
||||||
|
go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @authors
|
||||||
|
* Jeffrey Wilcke <i@jev.io>
|
||||||
|
*/
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -33,73 +53,73 @@ func (self *WebSocketServer) Serv() {
|
||||||
data := ethutil.NewValue(msg.Args)
|
data := ethutil.NewValue(msg.Args)
|
||||||
bcode, err := ethutil.Compile(data.Get(0).Str(), false)
|
bcode, err := ethutil.Compile(data.Get(0).Str(), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Write(args(nil, err.Error()), msg.Seed)
|
c.Write(args(nil, err.Error()), msg.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
code := ethutil.Bytes2Hex(bcode)
|
code := ethutil.Bytes2Hex(bcode)
|
||||||
c.Write(args(code, nil), msg.Seed)
|
c.Write(args(code, nil), msg.Id)
|
||||||
case "getBlockByNumber":
|
case "eth_blockByNumber":
|
||||||
args := msg.Arguments()
|
args := msg.Arguments()
|
||||||
|
|
||||||
block := pipe.BlockByNumber(int32(args.Get(0).Uint()))
|
block := pipe.BlockByNumber(int32(args.Get(0).Uint()))
|
||||||
c.Write(block, msg.Seed)
|
c.Write(block, msg.Id)
|
||||||
|
|
||||||
case "getKey":
|
case "eth_blockByHash":
|
||||||
c.Write(pipe.Key().PrivateKey, msg.Seed)
|
args := msg.Arguments()
|
||||||
case "transact":
|
|
||||||
|
c.Write(pipe.BlockByHash(args.Get(0).Str()), msg.Id)
|
||||||
|
|
||||||
|
case "eth_transact":
|
||||||
if mp, ok := msg.Args[0].(map[string]interface{}); ok {
|
if mp, ok := msg.Args[0].(map[string]interface{}); ok {
|
||||||
object := mapToTxParams(mp)
|
object := mapToTxParams(mp)
|
||||||
c.Write(
|
c.Write(
|
||||||
args(pipe.Transact(object["from"], object["to"], object["value"], object["gas"], object["gasPrice"], object["data"])),
|
args(pipe.Transact(pipe.Key().PrivateKey, object["to"], object["value"], object["gas"], object["gasPrice"], object["data"])),
|
||||||
msg.Seed,
|
msg.Id,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
case "getCoinBase":
|
case "eth_gasPrice":
|
||||||
c.Write(pipe.CoinBase(), msg.Seed)
|
c.Write("10000000000000", msg.Id)
|
||||||
|
case "eth_coinbase":
|
||||||
|
c.Write(pipe.CoinBase(), msg.Id)
|
||||||
|
|
||||||
case "getIsListening":
|
case "eth_listening":
|
||||||
c.Write(pipe.IsListening(), msg.Seed)
|
c.Write(pipe.IsListening(), msg.Id)
|
||||||
|
|
||||||
case "getIsMining":
|
case "eth_mining":
|
||||||
c.Write(pipe.IsMining(), msg.Seed)
|
c.Write(pipe.IsMining(), msg.Id)
|
||||||
|
|
||||||
case "getPeerCoint":
|
case "eth_peerCount":
|
||||||
c.Write(pipe.PeerCount(), msg.Seed)
|
c.Write(pipe.PeerCount(), msg.Id)
|
||||||
|
|
||||||
case "getCountAt":
|
case "eth_countAt":
|
||||||
args := msg.Arguments()
|
args := msg.Arguments()
|
||||||
|
|
||||||
c.Write(pipe.TxCountAt(args.Get(0).Str()), msg.Seed)
|
c.Write(pipe.TxCountAt(args.Get(0).Str()), msg.Id)
|
||||||
|
|
||||||
case "getCodeAt":
|
case "eth_codeAt":
|
||||||
args := msg.Arguments()
|
args := msg.Arguments()
|
||||||
|
|
||||||
c.Write(len(pipe.CodeAt(args.Get(0).Str())), msg.Seed)
|
c.Write(len(pipe.CodeAt(args.Get(0).Str())), msg.Id)
|
||||||
|
|
||||||
case "getBlockByHash":
|
case "eth_storageAt":
|
||||||
args := msg.Arguments()
|
args := msg.Arguments()
|
||||||
|
|
||||||
c.Write(pipe.BlockByHash(args.Get(0).Str()), msg.Seed)
|
c.Write(pipe.StorageAt(args.Get(0).Str(), args.Get(1).Str()), msg.Id)
|
||||||
|
|
||||||
case "getStorageAt":
|
case "eth_balanceAt":
|
||||||
args := msg.Arguments()
|
args := msg.Arguments()
|
||||||
|
|
||||||
c.Write(pipe.StorageAt(args.Get(0).Str(), args.Get(1).Str()), msg.Seed)
|
c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Id)
|
||||||
|
|
||||||
case "getBalanceAt":
|
case "eth_secretToAddress":
|
||||||
args := msg.Arguments()
|
args := msg.Arguments()
|
||||||
|
|
||||||
c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Seed)
|
c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Id)
|
||||||
|
|
||||||
case "getSecretToAddress":
|
case "eth_newFilter":
|
||||||
args := msg.Arguments()
|
case "eth_newFilterString":
|
||||||
|
case "eth_messages":
|
||||||
c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Seed)
|
|
||||||
|
|
||||||
case "newFilter":
|
|
||||||
case "newFilterString":
|
|
||||||
case "messages":
|
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,10 @@ func (sm *BlockProcessor) CalculateTD(block *types.Block) (*big.Int, bool) {
|
||||||
// an uncle or anything that isn't on the current block chain.
|
// an uncle or anything that isn't on the current block chain.
|
||||||
// Validation validates easy over difficult (dagger takes longer time = difficult)
|
// Validation validates easy over difficult (dagger takes longer time = difficult)
|
||||||
func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
|
func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
|
||||||
|
if len(block.Header().Extra) > 1024 {
|
||||||
|
return fmt.Errorf("Block extra data too long (%d)", len(block.Header().Extra))
|
||||||
|
}
|
||||||
|
|
||||||
expd := CalcDifficulty(block, parent)
|
expd := CalcDifficulty(block, parent)
|
||||||
if expd.Cmp(block.Header().Difficulty) < 0 {
|
if expd.Cmp(block.Header().Difficulty) < 0 {
|
||||||
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Header().Difficulty, expd)
|
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Header().Difficulty, expd)
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func TestChainInsertions(t *testing.T) {
|
||||||
var eventMux event.TypeMux
|
var eventMux event.TypeMux
|
||||||
chainMan := NewChainManager(&eventMux)
|
chainMan := NewChainManager(&eventMux)
|
||||||
txPool := NewTxPool(&eventMux)
|
txPool := NewTxPool(&eventMux)
|
||||||
blockMan := NewBlockManager(txPool, chainMan, &eventMux)
|
blockMan := NewBlockProcessor(txPool, chainMan, &eventMux)
|
||||||
chainMan.SetProcessor(blockMan)
|
chainMan.SetProcessor(blockMan)
|
||||||
|
|
||||||
const max = 2
|
const max = 2
|
||||||
|
|
@ -115,7 +115,7 @@ func TestChainMultipleInsertions(t *testing.T) {
|
||||||
var eventMux event.TypeMux
|
var eventMux event.TypeMux
|
||||||
chainMan := NewChainManager(&eventMux)
|
chainMan := NewChainManager(&eventMux)
|
||||||
txPool := NewTxPool(&eventMux)
|
txPool := NewTxPool(&eventMux)
|
||||||
blockMan := NewBlockManager(txPool, chainMan, &eventMux)
|
blockMan := NewBlockProcessor(txPool, chainMan, &eventMux)
|
||||||
chainMan.SetProcessor(blockMan)
|
chainMan.SetProcessor(blockMan)
|
||||||
done := make(chan bool, max)
|
done := make(chan bool, max)
|
||||||
for i, chain := range chains {
|
for i, chain := range chains {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ func TestAddInvalidTx(t *testing.T) {
|
||||||
func TestRemoveSet(t *testing.T) {
|
func TestRemoveSet(t *testing.T) {
|
||||||
pool, _ := setup()
|
pool, _ := setup()
|
||||||
tx1 := transaction()
|
tx1 := transaction()
|
||||||
pool.pool.Add(tx1)
|
pool.addTx(tx1)
|
||||||
pool.RemoveSet(types.Transactions{tx1})
|
pool.RemoveSet(types.Transactions{tx1})
|
||||||
if pool.Size() > 0 {
|
if pool.Size() > 0 {
|
||||||
t.Error("expected pool size to be 0")
|
t.Error("expected pool size to be 0")
|
||||||
|
|
@ -65,7 +65,7 @@ func TestRemoveSet(t *testing.T) {
|
||||||
func TestRemoveInvalid(t *testing.T) {
|
func TestRemoveInvalid(t *testing.T) {
|
||||||
pool, key := setup()
|
pool, key := setup()
|
||||||
tx1 := transaction()
|
tx1 := transaction()
|
||||||
pool.pool.Add(tx1)
|
pool.addTx(tx1)
|
||||||
pool.RemoveInvalid(stateQuery{})
|
pool.RemoveInvalid(stateQuery{})
|
||||||
if pool.Size() > 0 {
|
if pool.Size() > 0 {
|
||||||
t.Error("expected pool size to be 0")
|
t.Error("expected pool size to be 0")
|
||||||
|
|
@ -73,7 +73,7 @@ func TestRemoveInvalid(t *testing.T) {
|
||||||
|
|
||||||
tx1.SetNonce(1)
|
tx1.SetNonce(1)
|
||||||
tx1.SignECDSA(key)
|
tx1.SignECDSA(key)
|
||||||
pool.pool.Add(tx1)
|
pool.addTx(tx1)
|
||||||
pool.RemoveInvalid(stateQuery{})
|
pool.RemoveInvalid(stateQuery{})
|
||||||
if pool.Size() != 1 {
|
if pool.Size() != 1 {
|
||||||
t.Error("expected pool size to be 1, is", pool.Size())
|
t.Error("expected pool size to be 1, is", pool.Size())
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
seedNodeAddress = "poc-7.ethdev.com:30300"
|
seedNodeAddress = "poc-8.ethdev.com:30303"
|
||||||
)
|
)
|
||||||
|
|
||||||
var seednodeId []byte = nil
|
var seednodeId []byte = nil
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ func (self *ethProtocol) handle() error {
|
||||||
return self.protoError(ErrDecode, "->msg %v: %v", msg, err)
|
return self.protoError(ErrDecode, "->msg %v: %v", msg, err)
|
||||||
}
|
}
|
||||||
hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount)
|
hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount)
|
||||||
return self.rw.EncodeMsg(BlockHashesMsg, ethutil.ByteSliceToInterface(hashes)...)
|
return p2p.EncodeMsg(self.rw, BlockHashesMsg, ethutil.ByteSliceToInterface(hashes)...)
|
||||||
|
|
||||||
case BlockHashesMsg:
|
case BlockHashesMsg:
|
||||||
// TODO: redo using lazy decode , this way very inefficient on known chains
|
// TODO: redo using lazy decode , this way very inefficient on known chains
|
||||||
|
|
@ -185,7 +185,7 @@ func (self *ethProtocol) handle() error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self.rw.EncodeMsg(BlocksMsg, blocks...)
|
return p2p.EncodeMsg(self.rw, BlocksMsg, blocks...)
|
||||||
|
|
||||||
case BlocksMsg:
|
case BlocksMsg:
|
||||||
msgStream := rlp.NewStream(msg.Payload)
|
msgStream := rlp.NewStream(msg.Payload)
|
||||||
|
|
@ -298,12 +298,12 @@ func (self *ethProtocol) handleStatus() error {
|
||||||
|
|
||||||
func (self *ethProtocol) requestBlockHashes(from []byte) error {
|
func (self *ethProtocol) requestBlockHashes(from []byte) error {
|
||||||
self.peer.Debugf("fetching hashes (%d) %x...\n", blockHashesBatchSize, from[0:4])
|
self.peer.Debugf("fetching hashes (%d) %x...\n", blockHashesBatchSize, from[0:4])
|
||||||
return self.rw.EncodeMsg(GetBlockHashesMsg, interface{}(from), uint64(blockHashesBatchSize))
|
return p2p.EncodeMsg(self.rw, GetBlockHashesMsg, interface{}(from), uint64(blockHashesBatchSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ethProtocol) requestBlocks(hashes [][]byte) error {
|
func (self *ethProtocol) requestBlocks(hashes [][]byte) error {
|
||||||
self.peer.Debugf("fetching %v blocks", len(hashes))
|
self.peer.Debugf("fetching %v blocks", len(hashes))
|
||||||
return self.rw.EncodeMsg(GetBlocksMsg, ethutil.ByteSliceToInterface(hashes)...)
|
return p2p.EncodeMsg(self.rw, GetBlocksMsg, ethutil.ByteSliceToInterface(hashes)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *protocolError) {
|
func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *protocolError) {
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,6 @@ func (self *testMsgReadWriter) WriteMsg(msg p2p.Msg) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *testMsgReadWriter) EncodeMsg(code uint64, data ...interface{}) error {
|
|
||||||
return self.WriteMsg(p2p.NewMsg(code, data...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *testMsgReadWriter) ReadMsg() (p2p.Msg, error) {
|
func (self *testMsgReadWriter) ReadMsg() (p2p.Msg, error) {
|
||||||
msg, ok := <-self.in
|
msg, ok := <-self.in
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ type Miner struct {
|
||||||
mining bool
|
mining bool
|
||||||
|
|
||||||
MinAcceptedGasPrice *big.Int
|
MinAcceptedGasPrice *big.Int
|
||||||
|
Extra string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(coinbase []byte, eth *eth.Ethereum) *Miner {
|
func New(coinbase []byte, eth *eth.Ethereum) *Miner {
|
||||||
|
|
@ -178,6 +179,7 @@ func (self *Miner) mine() {
|
||||||
chainMan = self.eth.ChainManager()
|
chainMan = self.eth.ChainManager()
|
||||||
block = chainMan.NewBlock(self.Coinbase)
|
block = chainMan.NewBlock(self.Coinbase)
|
||||||
)
|
)
|
||||||
|
block.Header().Extra = self.Extra
|
||||||
|
|
||||||
// Apply uncles
|
// Apply uncles
|
||||||
if len(self.uncles) > 0 {
|
if len(self.uncles) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -71,14 +71,11 @@ type MsgReader interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MsgWriter interface {
|
type MsgWriter interface {
|
||||||
// WriteMsg sends an existing message.
|
// WriteMsg sends a message. It will block until the message's
|
||||||
// The Payload reader of the message is consumed.
|
// Payload has been consumed by the other end.
|
||||||
|
//
|
||||||
// Note that messages can be sent only once.
|
// Note that messages can be sent only once.
|
||||||
WriteMsg(Msg) error
|
WriteMsg(Msg) error
|
||||||
|
|
||||||
// EncodeMsg writes an RLP-encoded message with the given
|
|
||||||
// code and data elements.
|
|
||||||
EncodeMsg(code uint64, data ...interface{}) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgReadWriter provides reading and writing of encoded messages.
|
// MsgReadWriter provides reading and writing of encoded messages.
|
||||||
|
|
@ -87,6 +84,12 @@ type MsgReadWriter interface {
|
||||||
MsgWriter
|
MsgWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeMsg writes an RLP-encoded message with the given code and
|
||||||
|
// data elements.
|
||||||
|
func EncodeMsg(w MsgWriter, code uint64, data ...interface{}) error {
|
||||||
|
return w.WriteMsg(NewMsg(code, data...))
|
||||||
|
}
|
||||||
|
|
||||||
var magicToken = []byte{34, 64, 8, 145}
|
var magicToken = []byte{34, 64, 8, 145}
|
||||||
|
|
||||||
func writeMsg(w io.Writer, msg Msg) error {
|
func writeMsg(w io.Writer, msg Msg) error {
|
||||||
|
|
@ -209,11 +212,6 @@ func (p *MsgPipeRW) WriteMsg(msg Msg) error {
|
||||||
return ErrPipeClosed
|
return ErrPipeClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeMsg is a convenient shorthand for sending an RLP-encoded message.
|
|
||||||
func (p *MsgPipeRW) EncodeMsg(code uint64, data ...interface{}) error {
|
|
||||||
return p.WriteMsg(NewMsg(code, data...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadMsg returns a message sent on the other end of the pipe.
|
// ReadMsg returns a message sent on the other end of the pipe.
|
||||||
func (p *MsgPipeRW) ReadMsg() (Msg, error) {
|
func (p *MsgPipeRW) ReadMsg() (Msg, error) {
|
||||||
if atomic.LoadInt32(p.closed) == 0 {
|
if atomic.LoadInt32(p.closed) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,8 @@ func TestDecodeRealMsg(t *testing.T) {
|
||||||
func ExampleMsgPipe() {
|
func ExampleMsgPipe() {
|
||||||
rw1, rw2 := MsgPipe()
|
rw1, rw2 := MsgPipe()
|
||||||
go func() {
|
go func() {
|
||||||
rw1.EncodeMsg(8, []byte{0, 0})
|
EncodeMsg(rw1, 8, []byte{0, 0})
|
||||||
rw1.EncodeMsg(5, []byte{1, 1})
|
EncodeMsg(rw1, 5, []byte{1, 1})
|
||||||
rw1.Close()
|
rw1.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ loop:
|
||||||
rw1, rw2 := MsgPipe()
|
rw1, rw2 := MsgPipe()
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
if err := rw1.EncodeMsg(1); err == nil {
|
if err := EncodeMsg(rw1, 1); err == nil {
|
||||||
t.Error("EncodeMsg returned nil error")
|
t.Error("EncodeMsg returned nil error")
|
||||||
} else if err != ErrPipeClosed {
|
} else if err != ErrPipeClosed {
|
||||||
t.Error("EncodeMsg returned wrong error: got %v, want %v", err, ErrPipeClosed)
|
t.Error("EncodeMsg returned wrong error: got %v, want %v", err, ErrPipeClosed)
|
||||||
|
|
|
||||||
|
|
@ -126,10 +126,10 @@ func TestPeerProtoEncodeMsg(t *testing.T) {
|
||||||
Name: "a",
|
Name: "a",
|
||||||
Length: 2,
|
Length: 2,
|
||||||
Run: func(peer *Peer, rw MsgReadWriter) error {
|
Run: func(peer *Peer, rw MsgReadWriter) error {
|
||||||
if err := rw.EncodeMsg(2); err == nil {
|
if err := EncodeMsg(rw, 2); err == nil {
|
||||||
t.Error("expected error for out-of-range msg code, got nil")
|
t.Error("expected error for out-of-range msg code, got nil")
|
||||||
}
|
}
|
||||||
if err := rw.EncodeMsg(1, "foo", "bar"); err != nil {
|
if err := EncodeMsg(rw, 1, "foo", "bar"); err != nil {
|
||||||
t.Errorf("write error: %v", err)
|
t.Errorf("write error: %v", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -105,25 +105,22 @@ func runBaseProtocol(peer *Peer, rw MsgReadWriter) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var lastActiveC chan time.Time
|
return bp.loop(errc)
|
||||||
if bp.peer.listenAddr != nil {
|
|
||||||
lastActiveC = bp.peer.listenAddr.lastActiveC
|
|
||||||
}
|
|
||||||
return bp.loop(errc, lastActiveC)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pingTimeout = 2 * time.Second
|
var pingTimeout = 2 * time.Second
|
||||||
|
|
||||||
func (bp *baseProtocol) loop(quit <-chan error, lastActiveC chan time.Time) error {
|
func (bp *baseProtocol) loop(quit <-chan error) error {
|
||||||
ping := time.NewTimer(pingTimeout)
|
ping := time.NewTimer(pingTimeout)
|
||||||
activity := bp.peer.activity.Subscribe(time.Time{})
|
activity := bp.peer.activity.Subscribe(time.Time{})
|
||||||
lastActive := time.Time{}
|
lastActive := time.Time{}
|
||||||
|
lastActiveC := bp.peer.lastActiveC
|
||||||
defer ping.Stop()
|
defer ping.Stop()
|
||||||
defer activity.Unsubscribe()
|
defer activity.Unsubscribe()
|
||||||
|
|
||||||
getPeersTick := time.NewTicker(10 * time.Second)
|
getPeersTick := time.NewTicker(10 * time.Second)
|
||||||
defer getPeersTick.Stop()
|
defer getPeersTick.Stop()
|
||||||
err := bp.rw.EncodeMsg(getPeersMsg)
|
err := EncodeMsg(bp.rw, getPeersMsg)
|
||||||
|
|
||||||
for err == nil {
|
for err == nil {
|
||||||
select {
|
select {
|
||||||
|
|
@ -131,7 +128,7 @@ func (bp *baseProtocol) loop(quit <-chan error, lastActiveC chan time.Time) erro
|
||||||
return err
|
return err
|
||||||
case lastActiveC <- lastActive:
|
case lastActiveC <- lastActive:
|
||||||
case <-getPeersTick.C:
|
case <-getPeersTick.C:
|
||||||
err = bp.rw.EncodeMsg(getPeersMsg)
|
err = EncodeMsg(bp.rw, getPeersMsg)
|
||||||
case event := <-activity.Chan():
|
case event := <-activity.Chan():
|
||||||
ping.Reset(pingTimeout)
|
ping.Reset(pingTimeout)
|
||||||
lastActive = event.(time.Time)
|
lastActive = event.(time.Time)
|
||||||
|
|
@ -139,7 +136,7 @@ func (bp *baseProtocol) loop(quit <-chan error, lastActiveC chan time.Time) erro
|
||||||
if lastActive.Add(pingTimeout * 2).Before(t) {
|
if lastActive.Add(pingTimeout * 2).Before(t) {
|
||||||
err = newPeerError(errPingTimeout, "")
|
err = newPeerError(errPingTimeout, "")
|
||||||
} else if lastActive.Add(pingTimeout).Before(t) {
|
} else if lastActive.Add(pingTimeout).Before(t) {
|
||||||
err = bp.rw.EncodeMsg(pingMsg)
|
err = EncodeMsg(bp.rw, pingMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +166,7 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error {
|
||||||
return discRequestedError(reason[0])
|
return discRequestedError(reason[0])
|
||||||
|
|
||||||
case pingMsg:
|
case pingMsg:
|
||||||
return bp.rw.EncodeMsg(pongMsg)
|
return EncodeMsg(bp.rw, pongMsg)
|
||||||
|
|
||||||
case pongMsg:
|
case pongMsg:
|
||||||
|
|
||||||
|
|
@ -187,16 +184,22 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error {
|
||||||
peers = append(peers, ourAddr)
|
peers = append(peers, ourAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ds := make([]interface{}, 0, len(peers))
|
addrs := make([]interface{}, 0, len(peers))
|
||||||
// encode and filter out requesting peer
|
// encode and filter out requesting peer
|
||||||
for _, addr := range peers {
|
for _, addr := range peers {
|
||||||
if addr != bp.peer.listenAddr {
|
if addr != bp.peer.Addr() {
|
||||||
ds = append(ds, addr)
|
addrs = append(addrs, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ds) > 0 {
|
// this is dangerous. the spec says that we should _delay_
|
||||||
return bp.rw.EncodeMsg(peersMsg, ds...)
|
// sending the response if no new information is available.
|
||||||
|
// this means that would need to send a response later when
|
||||||
|
// new peers become available.
|
||||||
|
//
|
||||||
|
// TODO: add event mechanism to notify baseProtocol for new peers
|
||||||
|
if len(addrs) > 0 {
|
||||||
|
return EncodeMsg(bp.rw, peersMsg, addrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
case peersMsg:
|
case peersMsg:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
@ -36,48 +37,61 @@ func newTestPeer() (peer *Peer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseProtocolPeers(t *testing.T) {
|
func TestBaseProtocolPeers(t *testing.T) {
|
||||||
cannedPeerList := []*peerAddr{
|
peerList := []*peerAddr{
|
||||||
{IP: net.ParseIP("1.2.3.4"), Port: 2222, Pubkey: []byte{}},
|
{IP: net.ParseIP("1.2.3.4"), Port: 2222, Pubkey: []byte{}},
|
||||||
{IP: net.ParseIP("5.6.7.8"), Port: 3333, Pubkey: []byte{}},
|
{IP: net.ParseIP("5.6.7.8"), Port: 3333, Pubkey: []byte{}},
|
||||||
}
|
}
|
||||||
var ownAddr *peerAddr = &peerAddr{IP: net.ParseIP("1.3.5.7"), Port: 1111, Pubkey: []byte{}}
|
listenAddr := &peerAddr{IP: net.ParseIP("1.3.5.7"), Port: 1111, Pubkey: []byte{}}
|
||||||
rw1, rw2 := MsgPipe()
|
rw1, rw2 := MsgPipe()
|
||||||
|
defer rw1.Close()
|
||||||
|
wg := new(sync.WaitGroup)
|
||||||
|
|
||||||
// run matcher, close pipe when addresses have arrived
|
// run matcher, close pipe when addresses have arrived
|
||||||
addrChan := make(chan *peerAddr, len(cannedPeerList))
|
numPeers := len(peerList) + 1
|
||||||
|
addrChan := make(chan *peerAddr)
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
for _, want := range cannedPeerList {
|
i := 0
|
||||||
got := <-addrChan
|
for got := range addrChan {
|
||||||
t.Logf("got peer: %+v", got)
|
var want *peerAddr
|
||||||
|
switch {
|
||||||
|
case i < len(peerList):
|
||||||
|
want = peerList[i]
|
||||||
|
case i == len(peerList):
|
||||||
|
want = listenAddr // listenAddr should be the last thing sent
|
||||||
|
}
|
||||||
|
t.Logf("got peer %d/%d: %v", i+1, numPeers, got)
|
||||||
if !reflect.DeepEqual(want, got) {
|
if !reflect.DeepEqual(want, got) {
|
||||||
t.Errorf("mismatch: got %#v, want %#v", got, want)
|
t.Errorf("mismatch: got %+v, want %+v", got, want)
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
if i == numPeers {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(addrChan)
|
if i != numPeers {
|
||||||
var own []*peerAddr
|
t.Errorf("wrong number of peers received: got %d, want %d", i, numPeers)
|
||||||
var got *peerAddr
|
|
||||||
for got = range addrChan {
|
|
||||||
own = append(own, got)
|
|
||||||
}
|
}
|
||||||
if len(own) < 1 {
|
rw1.Close()
|
||||||
t.Errorf("mismatch: peers own address not given")
|
wg.Done()
|
||||||
} else {
|
|
||||||
if !reflect.DeepEqual(ownAddr, own[0]) {
|
|
||||||
t.Errorf("mismatch: peers own address is incorrectly or not given, got %v, want %#v", own[0], ownAddr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rw2.Close()
|
|
||||||
}()
|
}()
|
||||||
// run first peer
|
|
||||||
|
// run first peer (in background)
|
||||||
peer1 := newTestPeer()
|
peer1 := newTestPeer()
|
||||||
peer1.ourListenAddr = ownAddr
|
peer1.ourListenAddr = listenAddr
|
||||||
peer1.getPeers = func(...[]byte) []*peerAddr {
|
peer1.getPeers = func(...[]byte) []*peerAddr {
|
||||||
pl := make([]*peerAddr, len(cannedPeerList))
|
pl := make([]*peerAddr, len(peerList))
|
||||||
for i, addr := range cannedPeerList {
|
for i, addr := range cannedPeerList {
|
||||||
pl[i] = addr
|
pl[i] = addr
|
||||||
}
|
}
|
||||||
return pl
|
return pl
|
||||||
}
|
}
|
||||||
go runBaseProtocol(peer1, rw1)
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
runBaseProtocol(peer1, rw1)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
// run second peer
|
// run second peer
|
||||||
peer2 := newTestPeer()
|
peer2 := newTestPeer()
|
||||||
peer2.addPeer = func(addr *peerAddr) error {
|
peer2.addPeer = func(addr *peerAddr) error {
|
||||||
|
|
@ -87,6 +101,10 @@ func TestBaseProtocolPeers(t *testing.T) {
|
||||||
if err := runBaseProtocol(peer2, rw2); err != ErrPipeClosed {
|
if err := runBaseProtocol(peer2, rw2); err != ErrPipeClosed {
|
||||||
t.Errorf("peer2 terminated with unexpected error: %v", err)
|
t.Errorf("peer2 terminated with unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// terminate matcher
|
||||||
|
close(addrChan)
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseProtocolDisconnect(t *testing.T) {
|
func TestBaseProtocolDisconnect(t *testing.T) {
|
||||||
|
|
@ -100,7 +118,7 @@ func TestBaseProtocolDisconnect(t *testing.T) {
|
||||||
if err := expectMsg(rw2, handshakeMsg); err != nil {
|
if err := expectMsg(rw2, handshakeMsg); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
err := rw2.EncodeMsg(handshakeMsg,
|
err := EncodeMsg(rw2, handshakeMsg,
|
||||||
baseProtocolVersion,
|
baseProtocolVersion,
|
||||||
"",
|
"",
|
||||||
[]interface{}{},
|
[]interface{}{},
|
||||||
|
|
@ -113,7 +131,7 @@ func TestBaseProtocolDisconnect(t *testing.T) {
|
||||||
if err := expectMsg(rw2, getPeersMsg); err != nil {
|
if err := expectMsg(rw2, getPeersMsg); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if err := rw2.EncodeMsg(discMsg, DiscQuitting); err != nil {
|
if err := EncodeMsg(rw2, discMsg, DiscQuitting); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ func (c *Client) Conn() *ws.Conn {
|
||||||
return c.ws
|
return c.ws
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Write(data interface{}, seed int) {
|
func (c *Client) Write(data interface{}, id int) {
|
||||||
msg := &Message{Seed: seed, Data: data}
|
msg := &Message{Id: id, Data: data}
|
||||||
select {
|
select {
|
||||||
case c.ch <- msg:
|
case c.ch <- msg:
|
||||||
default:
|
default:
|
||||||
|
|
@ -73,7 +73,6 @@ func (c *Client) Listen() {
|
||||||
|
|
||||||
// Listen write request via chanel
|
// Listen write request via chanel
|
||||||
func (c *Client) listenWrite() {
|
func (c *Client) listenWrite() {
|
||||||
wslogger.Debugln("Listening write to client")
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
||||||
|
|
@ -93,7 +92,6 @@ func (c *Client) listenWrite() {
|
||||||
|
|
||||||
// Listen read request via chanel
|
// Listen read request via chanel
|
||||||
func (c *Client) listenRead() {
|
func (c *Client) listenRead() {
|
||||||
wslogger.Debugln("Listening read from client")
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import "github.com/ethereum/go-ethereum/ethutil"
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Call string `json:"call"`
|
Call string `json:"call"`
|
||||||
Args []interface{} `json:"args"`
|
Args []interface{} `json:"args"`
|
||||||
Seed int `json:"seed"`
|
Id int `json:"_id"`
|
||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,6 @@ func (s *Server) MessageFunc(f MsgFunc) {
|
||||||
// Listen and serve.
|
// Listen and serve.
|
||||||
// It serves client connection and broadcast request.
|
// It serves client connection and broadcast request.
|
||||||
func (s *Server) Listen() {
|
func (s *Server) Listen() {
|
||||||
wslogger.Debugln("Listening server...")
|
|
||||||
|
|
||||||
// ws handler
|
// ws handler
|
||||||
onConnected := func(ws *ws.Conn) {
|
onConnected := func(ws *ws.Conn) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,8 @@ func NewJSPeer(peer *p2p.Peer) *JSPeer {
|
||||||
|
|
||||||
return &JSPeer{
|
return &JSPeer{
|
||||||
ref: peer,
|
ref: peer,
|
||||||
Ip: peer.RemoteAddr().String(),
|
Ip: fmt.Sprintf("%v", peer.RemoteAddr()),
|
||||||
Version: peer.Identity().String(),
|
Version: fmt.Sprintf("%v", peer.Identity()),
|
||||||
Caps: fmt.Sprintf("%v", caps),
|
Caps: fmt.Sprintf("%v", caps),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue